chiark / gitweb /
service: drop the per-distro ifdefs in service.c
[elogind.git] / src / core / service.c
index 2febdb69d148ffd68e4d412717b56bbcd6dbd2d2..3ab05508472ce90ec6c455ecc3e200a580bae3d2 100644 (file)
@@ -49,8 +49,7 @@
 
 typedef enum RunlevelType {
         RUNLEVEL_UP,
-        RUNLEVEL_DOWN,
-        RUNLEVEL_SYSINIT
+        RUNLEVEL_DOWN
 } RunlevelType;
 
 static const struct {
@@ -65,16 +64,6 @@ static const struct {
         { "rc4.d",  SPECIAL_RUNLEVEL4_TARGET, RUNLEVEL_UP },
         { "rc5.d",  SPECIAL_RUNLEVEL5_TARGET, RUNLEVEL_UP },
 
-#ifdef TARGET_SUSE
-        /* SUSE style boot.d */
-        { "boot.d", SPECIAL_SYSINIT_TARGET,   RUNLEVEL_SYSINIT },
-#endif
-
-#if defined(TARGET_DEBIAN) || defined(TARGET_UBUNTU) || defined(TARGET_ANGSTROM)
-        /* Debian style rcS.d */
-        { "rcS.d",  SPECIAL_SYSINIT_TARGET,   RUNLEVEL_SYSINIT },
-#endif
-
         /* Standard SysV runlevels for shutdown */
         { "rc0.d",  SPECIAL_POWEROFF_TARGET,  RUNLEVEL_DOWN },
         { "rc6.d",  SPECIAL_REBOOT_TARGET,    RUNLEVEL_DOWN }
@@ -83,12 +72,10 @@ static const struct {
            directories in this order, and we want to make sure that
            sysv_start_priority is known when we first load the
            unit. And that value we only know from S links. Hence
-           UP/SYSINIT must be read before DOWN */
+           UP must be read before DOWN */
 };
 
 #define RUNLEVELS_UP "12345"
-/* #define RUNLEVELS_DOWN "06" */
-#define RUNLEVELS_BOOT "bBsS"
 #endif
 
 static const UnitActiveState state_translation_table[_SERVICE_STATE_MAX] = {
@@ -140,9 +127,9 @@ static void service_init(Unit *u) {
         s->restart_usec = DEFAULT_RESTART_USEC;
         s->type = _SERVICE_TYPE_INVALID;
 
-        s->watchdog_watch.type = WATCH_INVALID;
+        watch_init(&s->watchdog_watch);
+        watch_init(&s->timer_watch);
 
-        s->timer_watch.type = WATCH_INVALID;
 #ifdef HAVE_SYSV_COMPAT
         s->sysv_start_priority = -1;
         s->sysv_start_priority_from_rcnd = -1;
@@ -262,7 +249,7 @@ static void service_handle_watchdog(Service *s) {
                 return;
         }
 
-        r = unit_watch_timer(UNIT(s), s->watchdog_usec - offset, &s->watchdog_watch);
+        r = unit_watch_timer(UNIT(s), CLOCK_MONOTONIC, true, s->watchdog_usec - offset, &s->watchdog_watch);
         if (r < 0)
                 log_warning("%s failed to install watchdog timer: %s", UNIT(s)->id, strerror(-r));
 }
@@ -334,21 +321,12 @@ static char *sysv_translate_name(const char *name) {
         if (!(r = new(char, strlen(name) + sizeof(".service"))))
                 return NULL;
 
-#if defined(TARGET_DEBIAN) || defined(TARGET_UBUNTU) || defined(TARGET_ANGSTROM)
         if (endswith(name, ".sh"))
                 /* Drop Debian-style .sh suffix */
                 strcpy(stpcpy(r, name) - 3, ".service");
-#endif
-#ifdef TARGET_SUSE
-        if (startswith(name, "boot."))
-                /* Drop SuSE-style boot. prefix */
-                strcpy(stpcpy(r, name + 5), ".service");
-#endif
-#ifdef TARGET_FRUGALWARE
         if (startswith(name, "rc."))
                 /* Drop Frugalware-style rc. prefix */
                 strcpy(stpcpy(r, name + 3), ".service");
-#endif
         else
                 /* Normal init scripts */
                 strcpy(stpcpy(r, name), ".service");
@@ -367,14 +345,11 @@ static int sysv_translate_facility(const char *name, const char *filename, char
         static const char * const table[] = {
                 /* LSB defined facilities */
                 "local_fs",             SPECIAL_LOCAL_FS_TARGET,
-#if defined(TARGET_MANDRIVA) || defined(TARGET_MAGEIA)
-#else
                 /* Due to unfortunate name selection in Mandriva,
                  * $network is provided by network-up which is ordered
                  * after network which actually starts interfaces.
                  * To break the loop, just ignore it */
                 "network",              SPECIAL_NETWORK_TARGET,
-#endif
                 "named",                SPECIAL_NSS_LOOKUP_TARGET,
                 "portmap",              SPECIAL_RPCBIND_TARGET,
                 "remote_fs",            SPECIAL_REMOTE_FS_TARGET,
@@ -385,20 +360,8 @@ static int sysv_translate_facility(const char *name, const char *filename, char
                 "mail-transfer-agent",  SPECIAL_MAIL_TRANSFER_AGENT_TARGET,
                 "x-display-manager",    SPECIAL_DISPLAY_MANAGER_SERVICE,
                 "null",                 NULL,
-
-#if defined(TARGET_DEBIAN) || defined(TARGET_UBUNTU) || defined(TARGET_ANGSTROM)
                 "mail-transport-agent", SPECIAL_MAIL_TRANSFER_AGENT_TARGET,
-#endif
-
-#ifdef TARGET_FEDORA
-                "MTA",                  SPECIAL_MAIL_TRANSFER_AGENT_TARGET,
-                "smtpdaemon",           SPECIAL_MAIL_TRANSFER_AGENT_TARGET,
-                "httpd",                SPECIAL_HTTP_DAEMON_TARGET,
-#endif
-
-#ifdef TARGET_SUSE
                 "smtp",                 SPECIAL_MAIL_TRANSFER_AGENT_TARGET,
-#endif
         };
 
         unsigned i;
@@ -936,13 +899,6 @@ static int service_load_sysv_path(Service *s, const char *path) {
 
         if ((r = sysv_exec_commands(s, supports_reload)) < 0)
                 goto finish;
-        if (s->sysv_runlevels &&
-            chars_intersect(RUNLEVELS_BOOT, s->sysv_runlevels) &&
-            chars_intersect(RUNLEVELS_UP, s->sysv_runlevels)) {
-                /* Service has both boot and "up" runlevels
-                   configured.  Kill the "up" ones. */
-                delete_chars(s->sysv_runlevels, RUNLEVELS_UP);
-        }
 
         if (s->sysv_runlevels && !chars_intersect(RUNLEVELS_UP, s->sysv_runlevels)) {
                 /* If there a runlevels configured for this service
@@ -1019,22 +975,11 @@ static int service_load_sysv_name(Service *s, const char *name) {
         assert(s);
         assert(name);
 
-        /* For SysV services we strip the boot.*, rc.* and *.sh
+        /* For SysV services we strip the rc.* and *.sh
          * prefixes/suffixes. */
-#if defined(TARGET_DEBIAN) || defined(TARGET_UBUNTU) || defined(TARGET_ANGSTROM)
         if (endswith(name, ".sh.service"))
                 return -ENOENT;
-#endif
-
-#ifdef TARGET_SUSE
-        if (startswith(name, "boot."))
-                return -ENOENT;
-#endif
-
-#ifdef TARGET_FRUGALWARE
         if (startswith(name, "rc."))
-                return -ENOENT;
-#endif
 
         STRV_FOREACH(p, UNIT(s)->manager->lookup_paths.sysvinit_path) {
                 char *path;
@@ -1049,31 +994,13 @@ static int service_load_sysv_name(Service *s, const char *name) {
 
                 r = service_load_sysv_path(s, path);
 
-#if defined(TARGET_DEBIAN) || defined(TARGET_UBUNTU) || defined(TARGET_ANGSTROM)
                 if (r >= 0 && UNIT(s)->load_state == UNIT_STUB) {
                         /* Try Debian style *.sh source'able init scripts */
                         strcat(path, ".sh");
                         r = service_load_sysv_path(s, path);
                 }
-#endif
                 free(path);
 
-#ifdef TARGET_SUSE
-                if (r >= 0 && UNIT(s)->load_state == UNIT_STUB) {
-                        /* Try SUSE style boot.* init scripts */
-
-                        path = strjoin(*p, "/boot.", name, NULL);
-                        if (!path)
-                                return -ENOMEM;
-
-                        /* Drop .service suffix */
-                        path[strlen(path)-8] = 0;
-                        r = service_load_sysv_path(s, path);
-                        free(path);
-                }
-#endif
-
-#ifdef TARGET_FRUGALWARE
                 if (r >= 0 && UNIT(s)->load_state == UNIT_STUB) {
                         /* Try Frugalware style rc.* init scripts */
 
@@ -1086,12 +1013,11 @@ static int service_load_sysv_name(Service *s, const char *name) {
                         r = service_load_sysv_path(s, path);
                         free(path);
                 }
-#endif
 
                 if (r < 0)
                         return r;
 
-                if ((UNIT(s)->load_state != UNIT_STUB))
+                if (UNIT(s)->load_state != UNIT_STUB)
                         break;
         }
 
@@ -1650,7 +1576,8 @@ static int service_coldplug(Unit *u) {
 
                                 k = s->deserialized_state == SERVICE_AUTO_RESTART ? s->restart_usec : s->timeout_start_usec;
 
-                                if ((r = unit_watch_timer(UNIT(s), k, &s->timer_watch)) < 0)
+                                r = unit_watch_timer(UNIT(s), CLOCK_MONOTONIC, true, k, &s->timer_watch);
+                                if (r < 0)
                                         return r;
                         }
                 }
@@ -1795,7 +1722,7 @@ static int service_spawn(
         }
 
         if (timeout && s->timeout_start_usec) {
-                r = unit_watch_timer(UNIT(s), s->timeout_start_usec, &s->timer_watch);
+                r = unit_watch_timer(UNIT(s), CLOCK_MONOTONIC, true, s->timeout_start_usec, &s->timer_watch);
                 if (r < 0)
                         goto fail;
         } else
@@ -1950,7 +1877,7 @@ static void service_enter_dead(Service *s, ServiceResult f, bool allow_restart)
              !set_contains(s->restart_ignore_status.signal, INT_TO_PTR(s->main_exec_status.status)))
                 ) {
 
-                r = unit_watch_timer(UNIT(s), s->restart_usec, &s->timer_watch);
+                r = unit_watch_timer(UNIT(s), CLOCK_MONOTONIC, true, s->restart_usec, &s->timer_watch);
                 if (r < 0)
                         goto fail;
 
@@ -2063,7 +1990,7 @@ static void service_enter_signal(Service *s, ServiceState state, ServiceResult f
 
         if (wait_for_exit) {
                 if (s->timeout_stop_usec > 0) {
-                        r = unit_watch_timer(UNIT(s), s->timeout_stop_usec, &s->timer_watch);
+                        r = unit_watch_timer(UNIT(s), CLOCK_MONOTONIC, true, s->timeout_stop_usec, &s->timer_watch);
                         if (r < 0)
                                 goto fail;
                 }
@@ -2313,7 +2240,7 @@ static void service_enter_restart(Service *s) {
                 /* Don't restart things if we are going down anyway */
                 log_info("Stop job pending for unit, delaying automatic restart.");
 
-                r = unit_watch_timer(UNIT(s), s->restart_usec, &s->timer_watch);
+                r = unit_watch_timer(UNIT(s), CLOCK_MONOTONIC, true, s->restart_usec, &s->timer_watch);
                 if (r < 0)
                         goto fail;
 
@@ -2491,6 +2418,7 @@ static int service_start_limit_test(Service *s) {
 
         case SERVICE_START_LIMIT_REBOOT_IMMEDIATE:
                 log_warning("%s start request repeated too quickly, rebooting immediately.", UNIT(s)->id);
+                sync();
                 reboot(RB_AUTOBOOT);
                 break;
 
@@ -3540,7 +3468,7 @@ static int service_enumerate(Manager *m) {
 
                                 if (de->d_name[0] == 'S')  {
 
-                                        if (rcnd_table[i].type == RUNLEVEL_UP || rcnd_table[i].type == RUNLEVEL_SYSINIT) {
+                                        if (rcnd_table[i].type == RUNLEVEL_UP) {
                                                 SERVICE(service)->sysv_start_priority_from_rcnd =
                                                         MAX(a*10 + b, SERVICE(service)->sysv_start_priority_from_rcnd);
 
@@ -3554,8 +3482,7 @@ static int service_enumerate(Manager *m) {
                                                 goto finish;
 
                                 } else if (de->d_name[0] == 'K' &&
-                                           (rcnd_table[i].type == RUNLEVEL_DOWN ||
-                                            rcnd_table[i].type == RUNLEVEL_SYSINIT)) {
+                                           (rcnd_table[i].type == RUNLEVEL_DOWN)) {
 
                                         if ((r = set_ensure_allocated(&shutdown_services, trivial_hash_func, trivial_compare_func)) < 0)
                                                 goto finish;
@@ -3589,9 +3516,7 @@ static int service_enumerate(Manager *m) {
          * runlevels we assume the stop jobs will be implicitly added
          * by the core logic. Also, we don't really distinguish here
          * between the runlevels 0 and 6 and just add them to the
-         * special shutdown target. On SUSE the boot.d/ runlevel is
-         * also used for shutdown, so we add links for that too to the
-         * shutdown target.*/
+         * special shutdown target. */
         SET_FOREACH(service, shutdown_services, j) {
                 service = unit_follow_merge(service);