Bug 9337

Summary: systemd .service "WantedBy" lines not parsed correctly by systemctl script
Product: [Build System, Metadata & Runtime] OE-Core Reporter: Sandro Stiller <sandro.stiller>
Component: coreAssignee: Ross Burton <ross.burton>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: Medium+ CC: f.bre, meta.mr.watcher, meta.watcher, randy.macleod
Version: unspecified   
Target Milestone: 2.1 M4   
Hardware: x86   
OS: Multiple   
Whiteboard:
OS type for building Yocto: --- Type of Regression: ---
Verified: Documentation change: No (bug/feature does not impact docs)

Description Sandro Stiller 2016-03-24 07:42:34 UTC
If a .service file of a recipe contains a space / tab at the end of the WantedBy line, the service is not enabled in the image.
If a .ipk for the same recipe is installed in the target, the service is enabled after installation.
The problem is in the recipes-core/systemd/systemd-systemctl/systemctl shell script. The "real" systemctl binary on the target system works properly.

Preconditions/Environment
-------------------------
tested with
* Yocto 1.8 and
* the current git version of the systemctl script

Triggering Action/Cause
-----------------------
1. Add a space or tab to the end of the WantedBy line of a .service file
2. build an image
3. start the built system

The problem can also reproduced by simply executing
recipes-core/systemd/systemd-systemctl/systemctl --root=<rootfs-dir> <servicename>.service
and checking the result.

Expectation
-----------
The service should be enabled (symlink created)

Actual Result
-------------
The service is not enabled.
There is no message in the build process about it.

Reproducibility
---------------
always
Comment 1 Randy MacLeod 2016-03-24 15:17:28 UTC
As mentioned on the bugboard call, depending on the actual bug, we could add a QA, build time check so that we catch malformed .service files before runtime.
Comment 2 Ross Burton 2016-03-24 17:01:56 UTC
I don't have a working systemd build right now, but can you see if changing unit_types_re to:

	unit_types_re='\.\(service\|socket\|device\|mount\|automount\|swap\|target\|path\|timer\|snapshot\)\s*$'


Fixes this?  Basically, add \s* before the $.  (allow some whitespace before the line end)
Comment 3 Ross Burton 2016-04-06 19:46:15 UTC
Patch on the list
Comment 4 Ross Burton 2016-04-13 15:25:28 UTC
Fixed in oe-core 0395162aa45a416db6a0a38e7ee6c0f808272393.
Comment 5 f.bre 2019-09-17 13:06:40 UTC
The systemctl script in poky/meta/recipes-core/systemd/systemd-systemctl is a bit too complicated for me to understand. But a fast look let me tend that somewhere in the beginning it should do a tr '\r\n' '\n' or something of the whole .service file.
Comment 6 f.bre 2019-09-17 13:07:56 UTC
oops sorry, wrong ticked. This should go to Bug 13535