X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fservice.c;h=e765004e4fe4434df26f0d66aa7472cfef74e960;hp=6b6ce30855a182d7daba8221b844af39a279713f;hb=ba035df230e41bf9d70ebb47915c9472b7884412;hpb=f5c88ec1330b61787441156de7d764a140774bd2 diff --git a/src/service.c b/src/service.c index 6b6ce3085..e765004e4 100644 --- a/src/service.c +++ b/src/service.c @@ -237,16 +237,20 @@ 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) + 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"); - else if (endswith(name, ".sh")) - /* Drop Debian-style .sh suffix */ - strcpy(stpcpy(r, name) - 3, ".service"); -#ifdef TARGET_ARCH - else if (startswith(name, "@")) - /* Drop Arch-style background prefix */ - strcpy(stpcpy(r, name + 1), ".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 */ @@ -273,23 +277,24 @@ static int sysv_translate_facility(const char *name, const char *filename, char "syslog", SPECIAL_SYSLOG_TARGET, "time", SPECIAL_RTC_SET_TARGET, - /* Debian extensions */ + /* common extensions */ + "mail-transfer-agent", SPECIAL_MAIL_TRANSFER_AGENT_TARGET, + "x-display-manager", SPECIAL_DISPLAY_MANAGER_SERVICE, + "null", NULL, + #if defined(TARGET_DEBIAN) || defined(TARGET_UBUNTU) "mail-transport-agent", SPECIAL_MAIL_TRANSFER_AGENT_TARGET, #endif - "mail-transfer-agent", SPECIAL_MAIL_TRANSFER_AGENT_TARGET, - "x-display-manager", SPECIAL_DISPLAY_MANAGER_SERVICE, #ifdef TARGET_FEDORA - /* Fedora extensions */ "MTA", SPECIAL_MAIL_TRANSFER_AGENT_TARGET, "smtpdaemon", SPECIAL_MAIL_TRANSFER_AGENT_TARGET, "httpd", SPECIAL_HTTP_DAEMON_TARGET, #endif - /* SuSE extensions */ - "null", NULL - +#ifdef TARGET_SUSE + "smtp", SPECIAL_MAIL_TRANSFER_AGENT_TARGET, +#endif }; unsigned i; @@ -318,10 +323,13 @@ static int sysv_translate_facility(const char *name, const char *filename, char /* If we don't know this name, fallback heuristics to figure * out whether something is a target or a service alias. */ - if (*name == '$') + if (*name == '$') { + if (!unit_prefix_is_valid(n)) + return -EINVAL; + /* Facilities starting with $ are most likely targets */ r = unit_name_build(n, NULL, ".target"); - else if (filename && streq(name, filename)) + } else if (filename && streq(name, filename)) /* Names equalling the file name of the services are redundant */ return 0; else @@ -674,10 +682,14 @@ static int service_load_sysv_path(Service *s, const char *path) { } r = sysv_translate_facility(n, file_name_from_path(path), &m); - free(n); - if (r < 0) - goto finish; + if (r < 0) { + log_error("[%s:%u] Failed to translate LSB dependency %s, ignoring: %s", path, line, n, strerror(-r)); + free(n); + continue; + } + + free(n); if (r == 0) continue; @@ -849,11 +861,22 @@ static int service_load_sysv_name(Service *s, const char *name) { assert(s); assert(name); - /* For SysV services we strip the boot. or .sh + /* For SysV services we strip the boot.*, rc.* and *.sh * prefixes/suffixes. */ - if (startswith(name, "boot.") || - endswith(name, ".sh.service")) +#if defined(TARGET_DEBIAN) || defined(TARGET_UBUNTU) + 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, s->meta.manager->lookup_paths.sysvinit_path) { char *path; @@ -867,24 +890,42 @@ 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) if (r >= 0 && s->meta.load_state == UNIT_STUB) { - /* Try Debian style xxx.sh source'able init scripts */ + /* 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 && s->meta.load_state == UNIT_STUB) { - /* Try SUSE style boot.xxx init scripts */ + /* Try SUSE style boot.* init scripts */ if (asprintf(&path, "%s/boot.%s", *p, name) < 0) 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 && s->meta.load_state == UNIT_STUB) { + /* Try Frugalware style rc.* init scripts */ + + if (asprintf(&path, "%s/rc.%s", *p, name) < 0) + return -ENOMEM; + + /* Drop .service suffix */ + path[strlen(path)-8] = 0; + r = service_load_sysv_path(s, path); + free(path); + } +#endif if (r < 0) return r; @@ -2671,8 +2712,14 @@ static void service_timer_event(Unit *u, uint64_t elapsed, Watch* w) { break; case SERVICE_STOP_SIGTERM: - log_warning("%s stopping timed out. Killing.", u->meta.id); - service_enter_signal(s, SERVICE_STOP_SIGKILL, false); + if (s->exec_context.send_sigkill) { + log_warning("%s stopping timed out. Killing.", u->meta.id); + service_enter_signal(s, SERVICE_STOP_SIGKILL, false); + } else { + log_warning("%s stopping timed out. Skipping SIGKILL.", u->meta.id); + service_enter_stop_post(s, false); + } + break; case SERVICE_STOP_SIGKILL: @@ -2690,8 +2737,14 @@ static void service_timer_event(Unit *u, uint64_t elapsed, Watch* w) { break; case SERVICE_FINAL_SIGTERM: - log_warning("%s stopping timed out (2). Killing.", u->meta.id); - service_enter_signal(s, SERVICE_FINAL_SIGKILL, false); + if (s->exec_context.send_sigkill) { + log_warning("%s stopping timed out (2). Killing.", u->meta.id); + service_enter_signal(s, SERVICE_FINAL_SIGKILL, false); + } else { + log_warning("%s stopping timed out (2). Skipping SIGKILL. Entering failed mode.", u->meta.id); + service_enter_dead(s, false, true); + } + break; case SERVICE_FINAL_SIGKILL: @@ -2826,67 +2879,9 @@ static int service_enumerate(Manager *m) { Unit *service; Iterator j; int r; -#ifdef TARGET_ARCH - Unit *previous = NULL; - char *arch_daemons = NULL; - char *arch_daemons_stripped = NULL; - char **arch_daemons_split = NULL; -#endif assert(m); -#ifdef TARGET_ARCH - if ((r = parse_env_file("/etc/rc.conf", NEWLINE, - "DAEMONS", &arch_daemons, - NULL)) < 0) { - - if (r != -ENOENT) - log_warning("Failed to read /etc/rc.conf: %s", strerror(-r)); - - } else if (arch_daemons) { - if (!(arch_daemons_stripped = strchr(arch_daemons, '('))) - arch_daemons_stripped = arch_daemons; - else - arch_daemons_stripped++; /* strip start paren */ - - arch_daemons_stripped[strcspn(arch_daemons_stripped, ")")] = 0; /* strip end paren */ - - if (!(arch_daemons_split = strv_split_quoted(arch_daemons_stripped))) { - r = -ENOMEM; - goto finish; - } - - STRV_FOREACH(p, arch_daemons_split) { - - free(name); - name = NULL; - - if (**p == '!') /* daemons prefixed with ! are disabled, so ignore them */ - continue; - - if (!(name = sysv_translate_name(*p))) { - r = -ENOMEM; - goto finish; - } - - if ((r = manager_load_unit_prepare(m, name, NULL, NULL, &service)) < 0) { - log_warning("Failed to prepare unit %s: %s", name, strerror(-r)); - continue; - } - - if ((r = unit_add_two_dependencies_by_name_inverse(service, UNIT_AFTER, UNIT_WANTS, "multi-user.target", NULL, true)) < 0) - goto finish; - - if (previous) - if ((r = unit_add_dependency(service, UNIT_AFTER, previous, true)) < 0) - goto finish; - - if (**p != '@') /* daemons prefixed with @ can be started in the background */ - previous = service; - } - } -#endif - zero(runlevel_services); STRV_FOREACH(p, m->lookup_paths.sysvrcnd_path) @@ -3024,10 +3019,6 @@ finish: free(path); free(fpath); free(name); -#ifdef TARGET_ARCH - free(arch_daemons); - free(arch_daemons_split); -#endif for (i = 0; i < ELEMENTSOF(rcnd_table); i++) set_free(runlevel_services[i]);