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