[systemd/f16] Fix auto-restart handling (#817968, fdo#45511)
Michal Schmidt
michich at fedoraproject.org
Tue May 22 07:25:56 UTC 2012
commit a89d6fef4a6b116ada04c347629023b72ac3e297
Author: Michal Schmidt <mschmidt at redhat.com>
Date: Tue May 22 09:18:55 2012 +0200
Fix auto-restart handling (#817968, fdo#45511)
...edule-JOB_RESTART-from-SERVICE_AUTO_RESTA.patch | 35 ++++++++++++++
...ually-delay-auto-restart-if-another-job-i.patch | 25 ++++++++++
...fix-auto-restart-handling-in-service_stop.patch | 49 ++++++++++++++++++++
...ix-auto-restart-handling-in-service_start.patch | 34 ++++++++++++++
systemd.spec | 9 +++-
5 files changed, 151 insertions(+), 1 deletions(-)
---
diff --git a/0227-service-schedule-JOB_RESTART-from-SERVICE_AUTO_RESTA.patch b/0227-service-schedule-JOB_RESTART-from-SERVICE_AUTO_RESTA.patch
new file mode 100644
index 0000000..110c380
--- /dev/null
+++ b/0227-service-schedule-JOB_RESTART-from-SERVICE_AUTO_RESTA.patch
@@ -0,0 +1,35 @@
+From d53773e3da3cd0c0e19d0e382c4461062955f885 Mon Sep 17 00:00:00 2001
+From: David Ward <david.ward at ll.mit.edu>
+Date: Mon, 2 Apr 2012 23:45:35 -0400
+Subject: [PATCH] service: schedule JOB_RESTART from SERVICE_AUTO_RESTART
+ state
+
+Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=45511
+(cherry picked from commit 48bb58769a00e8e50a617ebbfff84599a0350fa5)
+
+Conflicts:
+ src/service.c
+---
+ src/service.c | 9 ++++++---
+ 1 file changed, 6 insertions(+), 3 deletions(-)
+
+diff --git a/src/service.c b/src/service.c
+index 97a4a45..3ed79b0 100644
+--- a/src/service.c
++++ b/src/service.c
+@@ -2125,9 +2125,12 @@ static void service_enter_restart(Service *s) {
+ goto fail;
+ }
+
+- service_enter_dead(s, true, false);
+-
+- if ((r = manager_add_job(UNIT(s)->manager, JOB_START, UNIT(s), JOB_FAIL, false, &error, NULL)) < 0)
++ /* Any units that are bound to this service must also be
++ * restarted. We use JOB_RESTART (instead of the more obvious
++ * JOB_START) here so that those dependency jobs will be added
++ * as well. */
++ r = manager_add_job(UNIT(s)->manager, JOB_RESTART, UNIT(s), JOB_FAIL, false, &error, NULL);
++ if (r < 0)
+ goto fail;
+
+ log_debug("%s scheduled restart job.", UNIT(s)->id);
diff --git a/0228-service-actually-delay-auto-restart-if-another-job-i.patch b/0228-service-actually-delay-auto-restart-if-another-job-i.patch
new file mode 100644
index 0000000..ebb797d
--- /dev/null
+++ b/0228-service-actually-delay-auto-restart-if-another-job-i.patch
@@ -0,0 +1,25 @@
+From 3f48ebb13ba3becc54b47a96c39bf8a2c63ebd4a Mon Sep 17 00:00:00 2001
+From: David Ward <david.ward at ll.mit.edu>
+Date: Sun, 29 Apr 2012 09:35:40 -0400
+Subject: [PATCH] service: actually delay auto-restart if another job is
+ pending
+
+https://bugs.freedesktop.org/show_bug.cgi?id=45511
+(cherry picked from commit feae8adb848e26110b28a06d1244e02f36cdf382)
+---
+ src/service.c | 2 ++
+ 1 file changed, 2 insertions(+)
+
+diff --git a/src/service.c b/src/service.c
+index 3ed79b0..225b5e5 100644
+--- a/src/service.c
++++ b/src/service.c
+@@ -2123,6 +2123,8 @@ static void service_enter_restart(Service *s) {
+
+ if ((r = unit_watch_timer(UNIT(s), s->restart_usec, &s->timer_watch)) < 0)
+ goto fail;
++
++ return;
+ }
+
+ /* Any units that are bound to this service must also be
diff --git a/0229-service-fix-auto-restart-handling-in-service_stop.patch b/0229-service-fix-auto-restart-handling-in-service_stop.patch
new file mode 100644
index 0000000..1a08737
--- /dev/null
+++ b/0229-service-fix-auto-restart-handling-in-service_stop.patch
@@ -0,0 +1,49 @@
+From 44e5bd271f04262115446b4c4a32081383e74ce1 Mon Sep 17 00:00:00 2001
+From: David Ward <david.ward at ll.mit.edu>
+Date: Sun, 29 Apr 2012 09:35:48 -0400
+Subject: [PATCH] service: fix auto-restart handling in service_stop()
+
+When service_stop() handles a service in the SERVICE_AUTO_RESTART state,
+it calls service_set_state() to transition it to the SERVICE_DEAD state.
+However if the service failed, it should transition it to SERVICE_FAILED
+instead, which will trigger its OnFailure units. To achieve this, we now
+call service_enter_dead() in place of service_set_state(), which will
+transition the service to either SERVICE_DEAD or SERVICE_FAILED as is
+appropriate.
+
+Also, some misleading comments are adjusted: service_stop() is not only
+called on a user request, but also during an automatic restart in order
+to handle dependencies.
+
+Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=45511
+(cherry picked from commit f0c7b229e1aba12488ffb3ca39f606cc93291f55)
+---
+ src/service.c | 7 +++----
+ 1 file changed, 3 insertions(+), 4 deletions(-)
+
+diff --git a/src/service.c b/src/service.c
+index 225b5e5..1696ed5 100644
+--- a/src/service.c
++++ b/src/service.c
+@@ -2302,8 +2302,7 @@ static int service_stop(Unit *u) {
+
+ assert(s);
+
+- /* This is a user request, so don't do restarts on this
+- * shutdown. */
++ /* Don't create restart jobs from here. */
+ s->forbid_restart = true;
+
+ /* Already on it */
+@@ -2315,9 +2314,9 @@ static int service_stop(Unit *u) {
+ s->state == SERVICE_FINAL_SIGKILL)
+ return 0;
+
+- /* Don't allow a restart */
++ /* A restart will be scheduled or is in progress. */
+ if (s->state == SERVICE_AUTO_RESTART) {
+- service_set_state(s, SERVICE_DEAD);
++ service_enter_dead(s, true, false);
+ return 0;
+ }
+
diff --git a/0230-service-fix-auto-restart-handling-in-service_start.patch b/0230-service-fix-auto-restart-handling-in-service_start.patch
new file mode 100644
index 0000000..1d2ff9b
--- /dev/null
+++ b/0230-service-fix-auto-restart-handling-in-service_start.patch
@@ -0,0 +1,34 @@
+From 6a0c1491128a8f4e5c555f1d1ff38c8f05d46bfa Mon Sep 17 00:00:00 2001
+From: David Ward <david.ward at ll.mit.edu>
+Date: Sun, 29 Apr 2012 09:35:51 -0400
+Subject: [PATCH] service: fix auto-restart handling in service_start()
+
+Do not bypass the SERVICE_DEAD/SERVICE_FAILED state by manually issuing
+a start job while an automatic restart is pending.
+(cherry picked from commit 2e9d6c1251abc0af9aa5bc53610bd522d55be776)
+---
+ src/service.c | 11 ++++++++++-
+ 1 file changed, 10 insertions(+), 1 deletion(-)
+
+diff --git a/src/service.c b/src/service.c
+index 1696ed5..d17c057 100644
+--- a/src/service.c
++++ b/src/service.c
+@@ -2279,7 +2279,16 @@ static int service_start(Unit *u) {
+ s->state == SERVICE_START_POST)
+ return 0;
+
+- assert(s->state == SERVICE_DEAD || s->state == SERVICE_FAILED || s->state == SERVICE_AUTO_RESTART);
++ /* A service that will be restarted must be stopped first to
++ * trigger BindTo and/or OnFailure dependencies. If a user
++ * does not want to wait for the holdoff time to elapse, the
++ * service should be manually restarted, not started. */
++ if (s->state == SERVICE_AUTO_RESTART) {
++ log_warning("%s automatic restart is pending, must be stopped before issuing start request.", UNIT(s)->id);
++ return -ECANCELED;
++ }
++
++ assert(s->state == SERVICE_DEAD || s->state == SERVICE_FAILED);
+
+ /* Make sure we don't enter a busy loop of some kind. */
+ if (!ratelimit_test(&s->ratelimit)) {
diff --git a/systemd.spec b/systemd.spec
index e80e5bb..4f1c076 100644
--- a/systemd.spec
+++ b/systemd.spec
@@ -2,7 +2,7 @@ Name: systemd
Url: http://www.freedesktop.org/wiki/Software/systemd
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
Version: 37
-Release: 23%{?dist}
+Release: 24%{?dist}
License: GPLv2+
Group: System Environment/Base
Summary: A System and Service Manager
@@ -282,6 +282,10 @@ Patch0223: 0223-bash-completion-use-printf-instead-of-echo.patch
Patch0224: 0224-dbus-unit-always-load-the-unit-before-handling-a-mes.patch
Patch0225: 0225-systemctl-drop-useless-DBus-calls-from-systemctl-sho.patch
Patch0226: 0226-F16-Revert-logind-close-FIFO-before-ending-sessions-.patch
+Patch0227: 0227-service-schedule-JOB_RESTART-from-SERVICE_AUTO_RESTA.patch
+Patch0228: 0228-service-actually-delay-auto-restart-if-another-job-i.patch
+Patch0229: 0229-service-fix-auto-restart-handling-in-service_stop.patch
+Patch0230: 0230-service-fix-auto-restart-handling-in-service_start.patch
# For sysvinit tools
Obsoletes: SysVinit < 2.86-24, sysvinit < 2.86-24
@@ -603,6 +607,9 @@ fi
%{_bindir}/systemd-sysv-convert
%changelog
+* Tue May 22 2012 Michal Schmidt <mschmidt at redhat.com> - 37-24
+- Fix auto-restart handling (#817968, fdo#45511)
+
* Tue May 22 2012 Michal Schmidt <mschmidt at redhat.com> - 37-23
- Revert the ReleaseSession patch (#823485)
More information about the scm-commits
mailing list