daandemeyer / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
923a60
From 3bcdd03212c6f0a849a4fbdf3cc7cb99fb7327cb Mon Sep 17 00:00:00 2001
923a60
From: Michal Sekletar <msekletar@users.noreply.github.com>
923a60
Date: Fri, 25 Aug 2017 15:36:10 +0200
923a60
Subject: [PATCH] service: attempt to execute next main command only for
923a60
 oneshot services (#6619)
923a60
923a60
This commit fixes crash described in
923a60
https://github.com/systemd/systemd/issues/6533
923a60
923a60
Multiple ExecStart lines are allowed only for oneshot services
923a60
anyway so it doesn't make sense to call service_run_next_main() with
923a60
services of type other than SERVICE_ONESHOT.
923a60
923a60
Referring back to reproducer from the issue, previously we didn't observe
923a60
this problem because s->main_command was reset after daemon-reload hence
923a60
we never reached the assert statement in service_run_next_main().
923a60
923a60
Fixes #6533
923a60
923a60
(cherry picked from commit b58aeb70dbd1cab5908b003ef5187da1fc241839)
923a60
923a60
Related: #1404657, #1471230
923a60
---
923a60
 src/core/service.c                |  1 +
923a60
 test/test-exec-deserialization.py | 31 +++++++++++++++++++++++++++++++
923a60
 2 files changed, 32 insertions(+)
923a60
923a60
diff --git a/src/core/service.c b/src/core/service.c
923a60
index 9ad3a0eb01..ceed1cc2e3 100644
923a60
--- a/src/core/service.c
923a60
+++ b/src/core/service.c
923a60
@@ -2612,6 +2612,7 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) {
923a60
 
923a60
                 if (s->main_command &&
923a60
                     s->main_command->command_next &&
923a60
+                    s->type == SERVICE_ONESHOT &&
923a60
                     f == SERVICE_SUCCESS) {
923a60
 
923a60
                         /* There is another command to *
923a60
diff --git a/test/test-exec-deserialization.py b/test/test-exec-deserialization.py
923a60
index 859778a7a8..61623da995 100755
923a60
--- a/test/test-exec-deserialization.py
923a60
+++ b/test/test-exec-deserialization.py
923a60
@@ -178,6 +178,37 @@ class ExecutionResumeTest(unittest.TestCase):
923a60
 
923a60
         self.assertTrue(not os.path.exists(self.output_file))
923a60
 
923a60
+    def test_issue_6533(self):
923a60
+        unit = "test-issue-6533.service"
923a60
+        unitfile_path = "/run/systemd/system/{}".format(unit)
923a60
+
923a60
+        content = '''
923a60
+        [Service]
923a60
+        ExecStart=/bin/sleep 5
923a60
+        '''
923a60
+
923a60
+        with open(unitfile_path, 'w') as f:
923a60
+            f.write(content)
923a60
+
923a60
+        self.reload()
923a60
+
923a60
+        subprocess.check_call(['systemctl', '--job-mode=replace', '--no-block', 'start', unit])
923a60
+        time.sleep(2)
923a60
+
923a60
+        content = '''
923a60
+        [Service]
923a60
+        ExecStart=/bin/sleep 5
923a60
+        ExecStart=/bin/true
923a60
+        '''
923a60
+
923a60
+        with open(unitfile_path, 'w') as f:
923a60
+            f.write(content)
923a60
+
923a60
+        self.reload()
923a60
+        time.sleep(5)
923a60
+
923a60
+        self.assertTrue(subprocess.call("journalctl -b _PID=1  | grep -q 'Freezing execution'", shell=True) != 0)
923a60
+
923a60
     def tearDown(self):
923a60
         for f in [self.output_file, self.unitfile_path]:
923a60
             try: