Bug 78311

Summary: daemon-reload clears bus_name_good bit, reloads kill units with BusName=
Product: systemd Reporter: Michael Stapelberg <michael+freedesktop>
Component: generalAssignee: systemd-bugs
Status: RESOLVED FIXED QA Contact: systemd-bugs
Severity: normal    
Priority: medium CC: joss, werner
Version: unspecified   
Hardware: Other   
OS: All   
Whiteboard:
i915 platform: i915 features:
Attachments: This one let some boolean survive a daemon-reload
0001-Let-some-boolean-survive-a-daemon-reload.patch
0001-Let-some-boolean-survive-a-daemon-reload.patch
0001-Let-some-boolean-survive-a-daemon-reload.patch

Description Michael Stapelberg 2014-05-05 21:37:13 UTC
This has originally been reported at http://bugs.debian.org/746151

D-Bus-activated units (i.e. having BusName= non-empty) will lose their bus_name_good bit after daemon-reloading:

x200 ~ $ systemctl dump | perl -nlE 'say if /joss.service:$/ ... /^-> .*.service/' | grep Bus
	BusName: org.freedesktop.timedate1
	Bus Name Good: yes

x200 ~ $ sudo systemctl daemon-reload
x200 ~ $ systemctl dump | perl -nlE 'say if /joss.service:$/ ... /^-> .*.service/' | grep Bus
	BusName: org.freedesktop.timedate1
	Bus Name Good: no

When using “systemctl reload” on the service and the control command SIGCHLDs, service_sigchld_event() will call service_enter_running(s, SERVICE_SUCCESS), but the following if condition will fail and therefore the last branch is taken instead of the first one:

        if ((main_pid_ok > 0 || (main_pid_ok < 0 && cgroup_ok != 0)) &&
            (s->bus_name_good || s->type != SERVICE_DBUS))
                service_set_state(s, SERVICE_RUNNING);
        else if (s->remain_after_exit)
                service_set_state(s, SERVICE_EXITED);
        else
                service_enter_stop(s, SERVICE_SUCCESS);

I am not sure how to properly fix this, which is why I’m creating this report. Thanks in advance for any fixes :).
Comment 1 Werner Fink 2015-06-09 14:39:37 UTC
Created attachment 116393 [details]
This one let some boolean survive a daemon-reload

This is a patch for an older systemd-210 but with this it works here.
Comment 2 Lennart Poettering 2015-06-09 18:01:39 UTC
Werner, patch looks mostly good, but can you prep it as git-format-patch formatted patch with you as author and stuff, so that i can actually merge it?

Thanks!
Comment 3 Werner Fink 2015-06-10 09:05:11 UTC
Created attachment 116418 [details] [review]
0001-Let-some-boolean-survive-a-daemon-reload.patch

OK, here is a git-format-patch formatted patch
Comment 4 Lennart Poettering 2015-06-10 09:56:29 UTC
The patch isn't right, I cannot apply this:

$ curl 'https://bugs.freedesktop.org/attachment.cgi?id=116418' | git am
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  3016  100  3016    0     0   2120      0  0:00:01  0:00:01 --:--:--  2120
Applying: Let some boolean survive a daemon-reload
error: core/service.c: does not exist in index
error: core/unit.c: does not exist in index
Patch failed at 0001 Let some boolean survive a daemon-reload
The copy of the patch that failed is found in:
   /home/lennart/projects/systemd/.git/rebase-apply/patch
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".


Please clone current git from github, make your change, add it with "git add -p" commit it with "git commit", then generate a git-format-patch formatted patch with "git format-patch -1", and attach this here! THanks!
Comment 5 Werner Fink 2015-06-10 12:08:44 UTC
(In reply to Lennart Poettering from comment #4)
> The patch isn't right, I cannot apply this:
> 
> $ curl 'https://bugs.freedesktop.org/attachment.cgi?id=116418' | git am
>   % Total    % Received % Xferd  Average Speed   Time    Time     Time 
> Current
>                                  Dload  Upload   Total   Spent    Left  Speed
> 100  3016  100  3016    0     0   2120      0  0:00:01  0:00:01 --:--:-- 
> 2120
> Applying: Let some boolean survive a daemon-reload
> error: core/service.c: does not exist in index
> error: core/unit.c: does not exist in index
> Patch failed at 0001 Let some boolean survive a daemon-reload
> The copy of the patch that failed is found in:
>    /home/lennart/projects/systemd/.git/rebase-apply/patch
> When you have resolved this problem, run "git am --continue".
> If you prefer to skip this patch, run "git am --skip" instead.
> To restore the original branch and stop patching, run "git am --abort".
> 
> 
> Please clone current git from github, make your change, add it with "git add
> -p" commit it with "git commit", then generate a git-format-patch formatted
> patch with "git format-patch -1", and attach this here! THanks!

Hmmm ... I've used a clone of the current git from git://anongit.freedesktop.org/systemd/systemd

  systemd/Upstream> git pull
  Already up-to-date.

please note that my git configuration does skip the a/ and b/ from the patches due diff.noprefix=true.

Let's try github.com

 systemd/tmp> git clone https://github.com/systemd/systemd.git .
 Cloning into '.'...
 remote: Counting objects: 139803, done.
 remote: Compressing objects: 100% (12/12), done.
 remote: Total 139803 (delta 2), reused 0 (delta 0), pack-reused 139791
 Receiving objects: 100% (139803/139803), 33.11 MiB | 715.00 KiB/s, done.
 Resolving deltas: 100% (105992/105992), done.
 Checking connectivity... done.
 Checking out files: 100% (1917/1917), done.
 systemd/tmp> git checkout src/core/unit.c src/core/service.c
 systemd/tmp> patch -p0 < ../outgoing/0001-Let-some-boolean-survive-a-daemon-reload.patch 
 patching file src/core/service.c
 patching file src/core/unit.c

... it simlpy works.

 systemd/tmp> git commit -a
 [master 5344fce] Let some boolean survive a daemon-reload
 2 files changed, 20 insertions(+)
 systemd/tmp> git format-patch -M origin/master --stdout | diff -u ../outgoing/0001-Let-some-boolean-survive-a-daemon-reload.patch -
 --- ../outgoing/0001-Let-some-boolean-survive-a-daemon-reload.patch     2015-06-10 10:59:47.133519522 +0200
 +++ -   2015-06-10 14:05:09.574887246 +0200
 @@ -1,6 +1,6 @@
 -From deff2d3e18e831d63bf98dd4114e4e35e41966e8 Mon Sep 17 00:00:00 2001
 +From 5344fced316c465a6e9df72fe8e42d1a30ceb04a Mon Sep 17 00:00:00 2001
  From: Werner Fink <werner@suse.de>
 -Date: Wed, 10 Jun 2015 10:47:13 +0200
 +Date: Wed, 10 Jun 2015 14:00:51 +0200
  Subject: [PATCH] Let some boolean survive a daemon-reload
 
  Without the boolean bus_name_good services as well as cgroup_realized
Comment 6 Werner Fink 2015-06-10 12:09:35 UTC
Created attachment 116422 [details] [review]
0001-Let-some-boolean-survive-a-daemon-reload.patch

Version with source and destination prefix (a/ and b/)
Comment 7 Lennart Poettering 2015-06-10 12:27:31 UTC
That patch applies now, but does not build. Please rebase on current git. Thanks.
Comment 8 Lennart Poettering 2015-06-10 12:29:08 UTC
Alternatively, just post it as github PR. That will ensure the patch applies cleanly and builds cleanly all automatically, which makes this a ton more efficient to me.

https://github.com/systemd/systemd
Comment 9 Werner Fink 2015-06-11 07:17:11 UTC
Created attachment 116430 [details] [review]
0001-Let-some-boolean-survive-a-daemon-reload.patch

Now hopefully with correct logging API.  Maybe a more stable API, even if internal only, would be an good idea to get a better maintainable systemd across version boundaries ;^)
Comment 10 Lennart Poettering 2015-06-11 10:16:16 UTC
(In reply to Werner Fink from comment #9)
> Created attachment 116430 [details] [review] [review]
> 0001-Let-some-boolean-survive-a-daemon-reload.patch

Applied! Thansk!
 
> Now hopefully with correct logging API.  Maybe a more stable API, even if
> internal only, would be an good idea to get a better maintainable systemd
> across version boundaries ;^)

Nope, no way. We reserve the liberty to change internal APIs, and we will do so all the time. This is not different from the kernel or similar. Sorry.

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.