ryantimwilson / rpms / systemd

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