chiark / gitweb /
service: when we cannot start due to rate limít consider that a real failure
[elogind.git] / src / service.c
index bf91561901f03d3fb8c23769049148962fdaeefa..ac83862db770c39e886b8bf44694ecd3edea3835 100644 (file)
@@ -169,7 +169,26 @@ static void service_done(Unit *u) {
         unit_unwatch_timer(u, &s->timer_watch);
 }
 
-static int sysv_translate_name(const char *name, char **_r) {
+static char *sysv_translate_name(const char *name) {
+        char *r;
+
+        if (!(r = new(char, strlen(name) + sizeof(".service"))))
+                return NULL;
+
+        if (startswith(name, "boot."))
+                /* Drop SuSE-style boot. prefix */
+                strcpy(stpcpy(r, name + 5), ".service");
+        else if (endswith(name, ".sh"))
+                /* Drop Debian-style .sh suffix */
+                strcpy(stpcpy(r, name) - 3, ".service");
+        else
+                /* Normal init scripts */
+                strcpy(stpcpy(r, name), ".service");
+
+        return r;
+}
+
+static int sysv_translate_facility(const char *name, char **_r) {
 
         static const char * const table[] = {
                 "$local_fs",  SPECIAL_LOCAL_FS_TARGET,
@@ -195,7 +214,7 @@ static int sysv_translate_name(const char *name, char **_r) {
         if (*name == '$')
                 return 0;
 
-        if (asprintf(&r, "%s.service", name) < 0)
+        if (!(r = sysv_translate_name(name)))
                 return -ENOMEM;
 
 finish:
@@ -206,7 +225,7 @@ finish:
         return 1;
 }
 
-static int sysv_chkconfig_order(Service *s) {
+static int sysv_fix_order(Service *s) {
         Meta *other;
         int r;
 
@@ -474,7 +493,7 @@ static int service_load_sysv_path(Service *s, const char *path) {
                                                 goto finish;
                                         }
 
-                                        r = sysv_translate_name(n, &m);
+                                        r = sysv_translate_facility(n, &m);
                                         free(n);
 
                                         if (r < 0)
@@ -511,7 +530,7 @@ static int service_load_sysv_path(Service *s, const char *path) {
                                                 goto finish;
                                         }
 
-                                        r = sysv_translate_name(n, &m);
+                                        r = sysv_translate_facility(n, &m);
                                         free(n);
 
                                         if (r < 0)
@@ -630,6 +649,12 @@ static int service_load_sysv_name(Service *s, const char *name) {
         assert(s);
         assert(name);
 
+        /* For SysV services we strip the boot. or .sh
+         * prefixes/suffixes. */
+        if (startswith(name, "boot.") ||
+            endswith(name, ".sh.service"))
+                return -ENOENT;
+
         STRV_FOREACH(p, UNIT(s)->meta.manager->sysvinit_path) {
                 char *path;
                 int r;
@@ -643,7 +668,7 @@ static int service_load_sysv_name(Service *s, const char *name) {
                 r = service_load_sysv_path(s, path);
 
                 if (r >= 0 && UNIT(s)->meta.load_state == UNIT_STUB) {
-                        /* Try Debian style .sh source'able init scripts */
+                        /* Try Debian style xxx.sh source'able init scripts */
                         strcat(path, ".sh");
                         r = service_load_sysv_path(s, path);
                 }
@@ -651,7 +676,7 @@ static int service_load_sysv_name(Service *s, const char *name) {
                 free(path);
 
                 if (r >= 0 && UNIT(s)->meta.load_state == UNIT_STUB) {
-                        /* Try Suse style boot.xxxx init scripts */
+                        /* Try Suse style boot.xxx init scripts */
 
                         if (asprintf(&path, "%s/boot.%s", *p, name) < 0)
                                 return -ENOMEM;
@@ -770,7 +795,7 @@ static int service_load(Unit *u) {
                 if ((r = unit_add_default_cgroup(u)) < 0)
                         return r;
 
-                if ((r = sysv_chkconfig_order(s)) < 0)
+                if ((r = sysv_fix_order(s)) < 0)
                         return r;
 
                 if (s->bus_name) {
@@ -1683,7 +1708,7 @@ static int service_start(Unit *u) {
         /* Make sure we don't enter a busy loop of some kind. */
         if (!ratelimit_test(&s->ratelimit)) {
                 log_warning("%s start request repeated too quickly, refusing to start.", u->meta.id);
-                return -EAGAIN;
+                return -ECANCELED;
         }
 
         s->failure = false;
@@ -2208,21 +2233,11 @@ static int service_enumerate(Manager *m) {
                                 }
 
                                 free(name);
-                                if (!(name = new(char, strlen(de->d_name) - 3 + 8 + 1))) {
+                                if (!(name = sysv_translate_name(de->d_name + 3))) {
                                         r = -ENOMEM;
                                         goto finish;
                                 }
 
-                                if (startswith(de->d_name+3, "boot."))
-                                        /* Drop SuSE-style boot. prefix */
-                                        strcpy(stpcpy(name, de->d_name + 3 + 5), ".service");
-                                else if (endswith(de->d_name+3, ".sh"))
-                                        /* Drop Debian-style .sh suffix */
-                                        strcpy(stpcpy(name, de->d_name + 3) - 3, ".service");
-                                else
-                                        /* Normal init scripts */
-                                        strcpy(stpcpy(name, de->d_name + 3), ".service");
-
                                 if ((r = manager_load_unit_prepare(m, name, NULL, &service)) < 0) {
                                         log_warning("Failed to prepare unit %s: %s", name, strerror(-r));
                                         continue;