Bug 1288600 - sysv generator may produce unit file containing lines that are longer than 2048 characters
sysv generator may produce unit file containing lines that are longer than 20...
Status: CLOSED ERRATA
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: systemd (Show other bugs)
7.2
Unspecified Unspecified
unspecified Severity medium
: rc
: ---
Assigned To: systemd-maint
Branislav Blaškovič
:
Depends On:
Blocks: 1203710 1289485 1313485
  Show dependency treegraph
 
Reported: 2015-12-04 12:12 EST by Zdenek Pytela
Modified: 2017-09-18 06:01 EDT (History)
8 users (show)

See Also:
Fixed In Version: systemd-219-20.el7
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2016-11-03 20:48:10 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)


External Trackers
Tracker ID Priority Status Summary Last Updated
Red Hat Knowledge Base (Solution) 3187552 None None None 2017-09-18 06:01 EDT

  None (edit)
Description Zdenek Pytela 2015-12-04 12:12:00 EST
Description of problem:

systemd fails to load a unit with a line longer than 2048 characters


Version-Release number of selected component (if applicable):
systemd-219-19.el7.x86_64


How reproducible:
always


Steps to Reproduce:
1. After= line with more than 2048 characters in a service unit


Actual results:
# systemctl status rsyncd -l
Failed to restart rsyncd.service: Unit rsyncd.service failed to load: Bad message. See system logs and 'systemctl status rsyncd.service' for details.
● rsyncd.service - fast remote file copy program daemon
   Loaded: error (Reason: Bad message)
   Active: active (running) since Fri 2015-12-04 18:03:09 CET; 16s ago
 Main PID: 15886 (rsync)
   CGroup: /system.slice/rsyncd.service
           └─15886 /usr/bin/rsync --daemon --no-detach

dec 04 18:03:09 my-rhel71 systemd[1]: Started fast remote file copy program daemon.
dec 04 18:03:09 my-rhel71 systemd[1]: Starting fast remote file copy program daemon...
dec 04 18:03:09 my-rhel71 rsyncd[15886]: rsyncd version 3.0.9 starting, listening on port 873
dec 04 18:03:09 my-rhel71 rsyncd[15886]: rsyncd version 3.0.9 starting, listening on port 873
dec 04 18:03:25 my-rhel71 systemd[1]: [/usr/lib/systemd/system/rsyncd.service:4] Failed to add dependency on juno-fra, ignoring: Invalid argument
dec 04 18:03:25 my-rhel71 systemd[1]: [/usr/lib/systemd/system/rsyncd.service:5] Missing '='.


Expected results:
<no error>


Additional info:
reproduced on After= and Before= lines
Comment 2 Michal Sekletar 2015-12-04 14:32:13 EST
systemd generally uses fgets() function for line oriented input. We pass to fgets() stack allocated array of size LINE_MAX. Constant LINE_MAX is on Linux defined as _POSIX2_LINE_MAX. Minimum length of _POSIX2_LINE_MAX according to spec is 2048 [1]. Note that LINE_MAX is compile time constant.

I am not entirely sure what would be the best fix. Probably the easiest one, is to redefine LINE_MAX to some higher value. Another option is to use getline() instead of fgets() for line oriented input. I think that would be the preferred option, however it requires patching systemd in many places.

At any rate, I will bring this upstream.

[1] http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap01.html
Comment 3 Zdenek Pytela 2015-12-07 04:45:33 EST
Michal,

Thank you for explanation. What could be a recommended workaround for now, creating a meta-target, possibly more targets with a wrapper script?

I would also like to raise a question if some of the directives can be specified multiple times, i. e.
After=a.service
After=b.service

in future versions.
Comment 4 Lukáš Nykrýn 2016-01-12 09:20:06 EST
> I would also like to raise a question if some of the directives can be
> specified multiple times, i. e.
> After=a.service
> After=b.service

This is absolutely fine and you can do that.
Comment 5 Lukáš Nykrýn 2016-01-21 08:11:31 EST
We need to backport https://github.com/systemd/systemd/commit/c584ffc0b75d4b9e9229bf1d8edb7d89562be3c1
Comment 6 Lars Delhage 2016-01-21 09:16:18 EST
I was the one who initiated this bugzilla and our case is that we get units like this generated by systemd from SysV init-scripts, since we have loads of SysV init-scripts. So in our case it's not a sloution to put several "After" on separate line, since the unit file (/run/systemd/generator.late/foo.service is auto-generated.

Our workaround so far (until we move to native systemd unit files) is to have the same start value in the LSB header for all our SysV services.

It looks like it's been fixed in https://github.com/systemd/systemd/pull/2401
Comment 7 Lukáš Nykrýn 2016-01-21 09:32:14 EST
By the way, as a workaround you can now compile the systemd-sysv-generator from upstream sources and replace the shipped one in /usr/lib/systemd/systemd-generators

But anyway I will try to backport it to rhel-7.3.
Comment 8 Lukáš Nykrýn 2016-01-29 10:04:35 EST
backported to staging https://github.com/lnykryn/systemd-rhel/commit/72b3ff75e786efa2c9b2fdfb50e46597434c5420 -> post
Comment 15 Branislav Blaškovič 2016-09-13 08:42:24 EDT
The attached testcase tests, if sysv-generator generates multiple After/Before lines on /etc/init.d/network initscript (which is part of initscripts component).

NEW PACKAGE:
:: [   LOG    ] :: Package versions:
:: [   LOG    ] ::   systemd-219-29.el7.x86_64
:: [   PASS   ] :: Command '/usr/lib/systemd/system-generators/systemd-sysv-generator' (Expected 0, got 0)
:: [   PASS   ] :: Command 'grep After /tmp/network.service' (Expected 0, got 0)
:: [   PASS   ] :: Command 'test 1 -lt 6' (Expected 0, got 0)
:: [   PASS   ] :: Command 'grep Before /tmp/network.service' (Expected 0, got 0)
:: [   PASS   ] :: Command 'test 1 -lt 7' (Expected 0, got 0)
:: [   LOG    ] :: Duration: 1s
:: [   LOG    ] :: Assertions: 5 good, 0 bad
:: [   PASS   ] :: RESULT: Test

OLD PACKAGE:
:: [   LOG    ] :: Package versions:
:: [   LOG    ] ::   systemd-219-19.el7.x86_64
:: [   PASS   ] :: Command '/usr/lib/systemd/system-generators/systemd-sysv-generator' (Expected 0, got 0)
:: [   PASS   ] :: Command 'grep After /tmp/network.service' (Expected 0, got 0)
:: [   PASS   ] :: Command 'test 1 -lt 2' (Expected 0, got 0)
:: [   PASS   ] :: Command 'grep Before /tmp/network.service' (Expected 0, got 0)
:: [   FAIL   ] :: Command 'test 1 -lt 1' (Expected 0, got 1)
:: [   LOG    ] :: Duration: 0s
:: [   LOG    ] :: Assertions: 4 good, 1 bad
:: [   FAIL   ] :: RESULT: Test

Removing need info, as far as changing of summary kind of answers it.
Comment 17 errata-xmlrpc 2016-11-03 20:48:10 EDT
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://rhn.redhat.com/errata/RHBA-2016-2216.html

Note You need to log in before you can comment on or make changes to this bug.