chiark / gitweb /
manager: simplify startup of special targets
authorLennart Poettering <lennart@poettering.net>
Mon, 12 Apr 2010 23:59:06 +0000 (01:59 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 12 Apr 2010 23:59:06 +0000 (01:59 +0200)
manager.c
manager.h

index 0a10808..43ee7f5 100644 (file)
--- a/manager.c
+++ b/manager.c
@@ -1251,6 +1251,21 @@ int manager_add_job(Manager *m, JobType type, Unit *unit, JobMode mode, bool for
         return 0;
 }
 
+int manager_add_job_by_name(Manager *m, JobType type, const char *name, JobMode mode, bool force, Job **_ret) {
+        Unit *unit;
+        int r;
+
+        assert(m);
+        assert(type < _JOB_TYPE_MAX);
+        assert(name);
+        assert(mode < _JOB_MODE_MAX);
+
+        if ((r = manager_load_unit(m, name, &unit)) < 0)
+                return r;
+
+        return manager_add_job(m, type, unit, mode, force, _ret);
+}
+
 Job *manager_get_job(Manager *m, uint32_t id) {
         assert(m);
 
@@ -1454,6 +1469,13 @@ static int manager_dispatch_sigchld(Manager *m) {
         return 0;
 }
 
+static void manager_start_target(Manager *m, const char *name) {
+        int r;
+
+        if ((r = manager_add_job_by_name(m, JOB_START, name, JOB_REPLACE, true, NULL)) < 0)
+                log_error("Failed to enqueue %s job: %s", name, strerror(-r));
+}
+
 static int manager_process_signal_fd(Manager *m, bool *quit) {
         ssize_t n;
         struct signalfd_siginfo sfsi;
@@ -1489,38 +1511,27 @@ static int manager_process_signal_fd(Manager *m, bool *quit) {
                 case SIGINT:
                 case SIGTERM:
 
-                        if (m->running_as != MANAGER_INIT) {
-                                *quit = true;
-                                return 0;
-
-                        } else {
-                                Unit *target;
-                                int r;
-
-                                if ((r = manager_load_unit(m, SPECIAL_CTRL_ALT_DEL_TARGET, &target)) < 0)
-                                        log_error("Failed to load ctrl-alt-del target: %s", strerror(-r));
-                                else if ((r = manager_add_job(m, JOB_START, target, JOB_REPLACE, true, NULL)) < 0)
-                                        log_error("Failed to enqueue ctrl-alt-del job: %s", strerror(-r));
-
+                        if (m->running_as == MANAGER_INIT) {
+                                manager_start_target(m, SPECIAL_CTRL_ALT_DEL_TARGET);
                                 break;
                         }
 
-                case SIGWINCH:
+                        *quit = true;
+                        return 0;
 
-                        if (m->running_as == MANAGER_INIT) {
-                                Unit *target;
-                                int r;
+                case SIGWINCH:
 
-                                if ((r = manager_load_unit(m, SPECIAL_KBREQUEST_TARGET, &target)) < 0)
-                                        log_error("Failed to load kbrequest target: %s", strerror(-r));
-                                else if ((r = manager_add_job(m, JOB_START, target, JOB_REPLACE, true, NULL)) < 0)
-                                        log_error("Failed to enqueue kbrequest job: %s", strerror(-r));
+                        if (m->running_as == MANAGER_INIT)
+                                manager_start_target(m, SPECIAL_KBREQUEST_TARGET);
 
-                                break;
-                        }
+                        /* This is a nop on non-init */
+                        break;
 
-                        /* This is a nop on non-init systemd's */
+                case SIGPWR:
+                        if (m->running_as == MANAGER_INIT)
+                                manager_start_target(m, SPECIAL_SIGPWR_TARGET);
 
+                        /* This is a nop on non-init */
                         break;
 
                 case SIGUSR1:
index 3ae8126..77b39b2 100644 (file)
--- a/manager.h
+++ b/manager.h
@@ -70,16 +70,21 @@ struct Watch {
 #include "dbus.h"
 
 #define SPECIAL_DEFAULT_TARGET "default.target"
+
 #define SPECIAL_LOGGER_SOCKET "systemd-logger.socket"
+
 #define SPECIAL_KBREQUEST_TARGET "kbrequest.target"
+#define SPECIAL_SIGPWR_TARGET "sigpwr.target"
 #define SPECIAL_CTRL_ALT_DEL_TARGET "ctrl-alt-del.target"
+
 #define SPECIAL_LOCAL_FS_TARGET "local-fs.target"
+#define SPECIAL_REMOTE_FS_TARGET "remote-fs.target"
 #define SPECIAL_NETWORK_TARGET "network.target"
 #define SPECIAL_NSS_LOOKUP_TARGET "nss-lookup.target"     /* LSB's $named */
 #define SPECIAL_RPCBIND_TARGET "rpcbind.target"           /* LSB's $portmap */
-#define SPECIAL_REMOTE_FS_TARGET "remote-fs.target"
 #define SPECIAL_SYSLOG_TARGET "syslog.target"             /* Should pull in syslog.socket or syslog.service */
 #define SPECIAL_RTC_SET_TARGET "rtc-set.target"           /* LSB's $time */
+
 #define SPECIAL_BASIC_TARGET "basic.target"
 #define SPECIAL_RESCUE_TARGET "rescue.target"
 
@@ -190,7 +195,9 @@ int manager_get_unit_from_dbus_path(Manager *m, const char *s, Unit **_u);
 int manager_get_job_from_dbus_path(Manager *m, const char *s, Job **_j);
 
 int manager_load_unit(Manager *m, const char *path_or_name, Unit **_ret);
+
 int manager_add_job(Manager *m, JobType type, Unit *unit, JobMode mode, bool force, Job **_ret);
+int manager_add_job_by_name(Manager *m, JobType type, const char *name, JobMode mode, bool force, Job **_ret);
 
 void manager_dump_units(Manager *s, FILE *f, const char *prefix);
 void manager_dump_jobs(Manager *s, FILE *f, const char *prefix);