X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fservice.c;h=547a55567abef7ea133d4cd3030739b94038d74e;hp=2ce95f5a9f2016e38e619e4aeea405e02db6db15;hb=17586c16bac1d5ecf7d60ef57d18e82e36c288c1;hpb=1f48cf56cb2693b84fdc76dc8df0b048ed50ef43 diff --git a/src/service.c b/src/service.c index 2ce95f5a9..547a55567 100644 --- a/src/service.c +++ b/src/service.c @@ -40,7 +40,7 @@ typedef enum RunlevelType { RUNLEVEL_UP, RUNLEVEL_DOWN, - RUNLEVEL_BASIC + RUNLEVEL_SYSINIT } RunlevelType; static const struct { @@ -58,10 +58,10 @@ static const struct { { "rc6.d", SPECIAL_RUNLEVEL6_TARGET, RUNLEVEL_DOWN }, /* SUSE style boot.d */ - { "boot.d", SPECIAL_BASIC_TARGET, RUNLEVEL_BASIC }, + { "boot.d", SPECIAL_SYSINIT_TARGET, RUNLEVEL_SYSINIT }, /* Debian style rcS.d */ - { "rcS.d", SPECIAL_BASIC_TARGET, RUNLEVEL_BASIC }, + { "rcS.d", SPECIAL_SYSINIT_TARGET, RUNLEVEL_SYSINIT }, }; #define RUNLEVELS_UP "12345" @@ -675,7 +675,7 @@ static int service_load_sysv_name(Service *s, const char *name) { endswith(name, ".sh.service")) return -ENOENT; - STRV_FOREACH(p, UNIT(s)->meta.manager->sysvinit_path) { + STRV_FOREACH(p, UNIT(s)->meta.manager->lookup_paths.sysvinit_path) { char *path; int r; @@ -726,7 +726,7 @@ static int service_load_sysv(Service *s) { /* Load service data from SysV init scripts, preferably with * LSB headers ... */ - if (strv_isempty(UNIT(s)->meta.manager->sysvinit_path)) + if (strv_isempty(UNIT(s)->meta.manager->lookup_paths.sysvinit_path)) return 0; if ((t = UNIT(s)->meta.id)) @@ -936,6 +936,9 @@ static int service_load_pid_file(Service *s) { if ((unsigned long) (pid_t) p != p) return -ERANGE; + if (p <= 1) + return -ERANGE; + if (kill((pid_t) p, 0) < 0 && errno != EPERM) { log_warning("PID %llu read from file %s does not exist. Your service or init script might be broken.", (unsigned long long) p, s->pid_file); @@ -1377,7 +1380,7 @@ static void service_enter_stop_post(Service *s, bool success) { return; fail: - log_warning("%s failed to run stop-post executable: %s", UNIT(s)->meta.id, strerror(-r)); + log_warning("%s failed to run 'stop-post' task: %s", UNIT(s)->meta.id, strerror(-r)); service_enter_signal(s, SERVICE_FINAL_SIGTERM, false); } @@ -1473,7 +1476,7 @@ static void service_enter_stop(Service *s, bool success) { return; fail: - log_warning("%s failed to run stop executable: %s", UNIT(s)->meta.id, strerror(-r)); + log_warning("%s failed to run 'stop' task: %s", UNIT(s)->meta.id, strerror(-r)); service_enter_signal(s, SERVICE_STOP_SIGTERM, false); } @@ -1518,7 +1521,7 @@ static void service_enter_start_post(Service *s) { return; fail: - log_warning("%s failed to run start-post executable: %s", UNIT(s)->meta.id, strerror(-r)); + log_warning("%s failed to run 'start-post' task: %s", UNIT(s)->meta.id, strerror(-r)); service_enter_stop(s, false); } @@ -1584,7 +1587,7 @@ static void service_enter_start(Service *s) { return; fail: - log_warning("%s failed to run start exectuable: %s", UNIT(s)->meta.id, strerror(-r)); + log_warning("%s failed to run 'start' task: %s", UNIT(s)->meta.id, strerror(-r)); service_enter_signal(s, SERVICE_FINAL_SIGTERM, false); } @@ -1613,7 +1616,7 @@ static void service_enter_start_pre(Service *s) { return; fail: - log_warning("%s failed to run start-pre executable: %s", UNIT(s)->meta.id, strerror(-r)); + log_warning("%s failed to run 'start-pre' task: %s", UNIT(s)->meta.id, strerror(-r)); service_enter_dead(s, false, true); } @@ -1660,7 +1663,7 @@ static void service_enter_reload(Service *s) { return; fail: - log_warning("%s failed to run reload executable: %s", UNIT(s)->meta.id, strerror(-r)); + log_warning("%s failed to run 'reload' task: %s", UNIT(s)->meta.id, strerror(-r)); service_enter_stop(s, false); } @@ -1690,7 +1693,7 @@ static void service_run_next(Service *s, bool success) { return; fail: - log_warning("%s failed to run spawn next executable: %s", UNIT(s)->meta.id, strerror(-r)); + log_warning("%s failed to run spawn next task: %s", UNIT(s)->meta.id, strerror(-r)); if (s->state == SERVICE_START_PRE) service_enter_signal(s, SERVICE_FINAL_SIGTERM, false); @@ -1963,14 +1966,18 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) { break; case SERVICE_START: - assert(s->type == SERVICE_FINISH); + if (s->type == SERVICE_FINISH) { + /* This was our main goal, so let's go on */ + if (success) + service_enter_start_post(s); + else + service_enter_signal(s, SERVICE_FINAL_SIGTERM, false); + break; + } else { + assert(s->type == SERVICE_DBUS); - /* This was our main goal, so let's go on */ - if (success) - service_enter_start_post(s); - else - service_enter_signal(s, SERVICE_FINAL_SIGTERM, false); - break; + /* Fall through */ + } case SERVICE_RUNNING: service_enter_running(s, success); @@ -2197,7 +2204,7 @@ static int service_enumerate(Manager *m) { assert(m); - STRV_FOREACH(p, m->sysvrcnd_path) + STRV_FOREACH(p, m->lookup_paths.sysvrcnd_path) for (i = 0; i < ELEMENTSOF(rcnd_table); i ++) { struct dirent *de; @@ -2264,7 +2271,7 @@ static int service_enumerate(Manager *m) { } if (de->d_name[0] == 'S' && - (rcnd_table[i].type == RUNLEVEL_UP || rcnd_table[i].type == RUNLEVEL_BASIC)) + (rcnd_table[i].type == RUNLEVEL_UP || rcnd_table[i].type == RUNLEVEL_SYSINIT)) SERVICE(service)->sysv_start_priority = MAX(a*10 + b, SERVICE(service)->sysv_start_priority); @@ -2283,7 +2290,9 @@ static int service_enumerate(Manager *m) { if ((r = unit_add_dependency(service, UNIT_BEFORE, runlevel_target, true)) < 0) goto finish; - } else if (de->d_name[0] == 'K' && rcnd_table[i].type == RUNLEVEL_DOWN) { + } else if (de->d_name[0] == 'K' && + (rcnd_table[i].type == RUNLEVEL_DOWN || + rcnd_table[i].type == RUNLEVEL_SYSINIT)) { Unit *shutdown_target; /* We honour K links only for @@ -2295,7 +2304,12 @@ static int service_enumerate(Manager *m) { * really distuingish here * between the runlevels 0 and * 6 and just add them to the - * special shutdown target. */ + * 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.*/ if ((r = manager_load_unit(m, SPECIAL_SHUTDOWN_TARGET, NULL, &shutdown_target)) < 0) goto finish;