[systemd-devel] systemd --user sometimes is not stopped by systemd-exit.service

Andrey Borzenkov arvidjaar at gmail.com
Wed Sep 25 22:41:30 PDT 2013


I'm still observing timeouts stopping user at 0.service on shutdown. It
appears to be some race condition, because enabling debugging of either
main systemd or user systemd, or even changing console from vt to
serial would hide it. Sometimes it also works using vt console as well.

Here is difference between good case and bad case.

Good case:

bor at opensuse:~> fgrep 'systemd[1507]' /tmp/log.debug 
Sep 26 08:39:39 linux-1a7f systemd[1507]: pam_unix(systemd-user:session): session opened for user root by (uid=0)
Sep 26 08:39:39 linux-1a7f systemd[1507]: Failed to open private bus connection: Failed to connect to socket /run/user/0/dbus/user_bus_socket: No such file or directory
Sep 26 08:39:39 linux-1a7f systemd[1507]: Starting Default.
Sep 26 08:39:39 linux-1a7f systemd[1507]: Reached target Default.
Sep 26 08:39:39 linux-1a7f systemd[1507]: Startup finished in 37ms.
Sep 26 08:39:42 linux-1a7f systemd[1507]: Time has been changed
Sep 26 08:39:50 linux-1a7f systemd[1507]: Stopping Default.
Sep 26 08:39:50 linux-1a7f systemd[1507]: Stopped target Default.
Sep 26 08:39:50 linux-1a7f systemd[1507]: Starting Shutdown.
Sep 26 08:39:50 linux-1a7f systemd[1507]: Reached target Shutdown.
Sep 26 08:39:50 linux-1a7f systemd[1507]: Starting Exit the Session...

As expected no more output after calling "kill -RTMIN+24"

Bad case:

bor at opensuse:~> fgrep 'systemd[1508]' /tmp/log.normal
Sep 26 08:41:23 linux-1a7f systemd[1508]: pam_unix(systemd-user:session): session opened for user root by (uid=0)
Sep 26 08:41:23 linux-1a7f systemd[1508]: Failed to open private bus connection: Failed to connect to socket /run/user/0/dbus/user_bus_socket: No such file or directory
Sep 26 08:41:23 linux-1a7f systemd[1508]: Starting Default.
Sep 26 08:41:23 linux-1a7f systemd[1508]: Reached target Default.
Sep 26 08:41:23 linux-1a7f systemd[1508]: Startup finished in 38ms.
Sep 26 08:41:25 linux-1a7f systemd[1508]: Time has been changed
Sep 26 08:45:27 linux-1a7f systemd[1508]: Stopping Default.
Sep 26 08:45:27 linux-1a7f systemd[1508]: Stopped target Default.
Sep 26 08:45:27 linux-1a7f systemd[1508]: Starting Shutdown.
Sep 26 08:45:27 linux-1a7f systemd[1508]: Reached target Shutdown.
Sep 26 08:45:27 linux-1a7f systemd[1508]: Starting Exit the Session...
Sep 26 08:45:27 linux-1a7f systemd[1508]: Started Exit the Session.
Sep 26 08:45:27 linux-1a7f systemd[1508]: Starting Exit the Session.
Sep 26 08:45:27 linux-1a7f systemd[1508]: Reached target Exit the Session.

Here systemd ignored or missed RTMIN+24 signal and remained after
SIGTERM.

One possible workaround seems to be

diff --git a/src/core/manager.c b/src/core/manager.c
index 079db41..8d59d6e 100644
--- a/src/core/manager.c
+++ b/src/core/manager.c
@@ -1463,11 +1463,10 @@ static int manager_process_signal_fd(Manager *m) {
                                 break;
                         }
 
-                        /* Run the exit target if there is one, if not, just exit. */
-                        if (manager_start_target(m, SPECIAL_EXIT_TARGET, JOB_REPLACE) < 0) {
-                                m->exit_code = MANAGER_EXIT;
-                                return 0;
-                        }
+                        /* Run the exit target and exit. */
+                        manager_start_target(m, SPECIAL_EXIT_TARGET, JOB_REPLACE);
+                        m->exit_code = MANAGER_EXIT;
+                        return 0;
 
                         break;
 

We obviously assume that SIGTERM/SIGINT always stop user instance
anyway. This just makes it obvious (and removes need to send additional
signal).

Still I wonder if anyone has idea about this race condition and how to
debug it (so far any attempt would eliminate race).


More information about the systemd-devel mailing list