[systemd-devel] [PATCH 3/4] manager: stop start timeout when sysinit.target is reached

Zbigniew Jędrzejewski-Szmek zbyszek at in.waw.pl
Sat Oct 25 12:43:26 PDT 2014


---
This is pretty basic, sysinit.target is hardcoded, but it should fix
the issue at hand, i.e. the system powering off when some long running
job is started during boot.

 src/core/job.c     |  3 +++
 src/core/manager.c | 14 ++++++++++----
 src/core/manager.h |  1 +
 3 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/src/core/job.c b/src/core/job.c
index ef5dbce1a3..f4844cd6e1 100644
--- a/src/core/job.c
+++ b/src/core/job.c
@@ -768,6 +768,9 @@ int job_finish_and_invalidate(Job *j, JobResult result, bool recursive) {
         job_print_status_message(u, t, result);
         job_log_status_message(u, t, result);
 
+        if (result == JOB_DONE && unit_has_name(u, SPECIAL_SYSINIT_TARGET))
+                manager_cancel_start_timeout(u->manager);
+
         job_add_to_dbus_queue(j);
 
         /* Patch restart jobs so that they become normal start jobs */
diff --git a/src/core/manager.c b/src/core/manager.c
index 770a6b55e2..b0d73c1068 100644
--- a/src/core/manager.c
+++ b/src/core/manager.c
@@ -276,6 +276,12 @@ static void manager_close_idle_pipe(Manager *m) {
         safe_close_pair(m->idle_pipe + 2);
 }
 
+void manager_cancel_start_timeout(Manager *m) {
+        assert(m);
+
+        m->start_timeout_event_source = sd_event_source_unref(m->start_timeout_event_source);
+}
+
 static int manager_setup_time_change(Manager *m) {
         int r;
 
@@ -911,7 +917,7 @@ void manager_free(Manager *m) {
 
         manager_close_idle_pipe(m);
 
-        sd_event_source_unref(m->start_timeout_event_source);
+        manager_cancel_start_timeout(m);
         free(m->start_timeout_reboot_arg);
 
         udev_unref(m->udev);
@@ -1089,7 +1095,7 @@ static int on_start_timeout(sd_event_source *s, usec_t usec, void *userdata) {
                           strerror(-r));
         }
 
-        m->start_timeout_event_source = sd_event_source_unref(m->start_timeout_event_source);
+        manager_cancel_start_timeout(m);
 
         manager_status_printf(m, false,
                               ANSI_HIGHLIGHT_RED_ON " !!  " ANSI_HIGHLIGHT_OFF,
@@ -1182,7 +1188,7 @@ int manager_startup(Manager *m, FILE *serialization, FDSet *fds) {
 
         /* Possibly set up a start timeout */
         if (!dual_timestamp_is_set(&m->finish_timestamp)) {
-                m->start_timeout_event_source = sd_event_source_unref(m->start_timeout_event_source);
+                manager_cancel_start_timeout(m);
 
                 if (m->start_timeout_usec) {
                         r = sd_event_add_time(
@@ -2639,7 +2645,7 @@ void manager_check_finished(Manager *m) {
 
         dual_timestamp_get(&m->finish_timestamp);
 
-        m->start_timeout_event_source = sd_event_source_unref(m->start_timeout_event_source);
+        manager_cancel_start_timeout(m);
 
         if (m->running_as == SYSTEMD_SYSTEM && detect_container(NULL) <= 0) {
 
diff --git a/src/core/manager.h b/src/core/manager.h
index 4db6433a2b..87060718ed 100644
--- a/src/core/manager.h
+++ b/src/core/manager.h
@@ -355,6 +355,7 @@ void manager_set_first_boot(Manager *m, bool b);
 
 void manager_status_printf(Manager *m, bool ephemeral, const char *status, const char *format, ...) _printf_(4,5);
 void manager_flip_auto_status(Manager *m, bool enable);
+void manager_cancel_start_timeout(Manager *m);
 
 Set *manager_get_units_requiring_mounts_for(Manager *m, const char *path);
 
-- 
1.9.3



More information about the systemd-devel mailing list