anitazha / rpms / systemd

Forked from rpms/systemd 3 years ago
Clone

Blame SOURCES/0573-service-attempt-to-execute-next-main-command-only-fo.patch

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