X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fcore%2Fservice.c;h=9e46dbae9478b7aab8177018c395da2e8cd3f68e;hb=464876c9c410b2f5bb997259510a13d0ee7d0af0;hp=2a4e691e789fd0a9e3a44c9b1c0b755d72fdc111;hpb=66870f90dec9b5bf4ad76f9757fafce703560a67;p=elogind.git diff --git a/src/core/service.c b/src/core/service.c index 2a4e691e7..9e46dbae9 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -322,17 +322,18 @@ static void service_done(Unit *u) { static char *sysv_translate_name(const char *name) { char *r; - if (!(r = new(char, strlen(name) + sizeof(".service")))) + r = new(char, strlen(name) + sizeof(".service")); + if (!r) return NULL; if (endswith(name, ".sh")) - /* Drop Debian-style .sh suffix */ + /* Drop .sh suffix */ strcpy(stpcpy(r, name) - 3, ".service"); if (startswith(name, "rc.")) - /* Drop Frugalware-style rc. prefix */ + /* Drop rc. prefix */ strcpy(stpcpy(r, name + 3), ".service"); else - /* Normal init scripts */ + /* Normal init script name */ strcpy(stpcpy(r, name), ".service"); return r; @@ -348,24 +349,13 @@ 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, - /* 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 */ + "local_fs", NULL, "network", SPECIAL_NETWORK_TARGET, "named", SPECIAL_NSS_LOOKUP_TARGET, "portmap", SPECIAL_RPCBIND_TARGET, "remote_fs", SPECIAL_REMOTE_FS_TARGET, - "syslog", SPECIAL_SYSLOG_TARGET, + "syslog", NULL, "time", SPECIAL_TIME_SYNC_TARGET, - - /* common extensions */ - "mail-transfer-agent", SPECIAL_MAIL_TRANSFER_AGENT_TARGET, - "x-display-manager", SPECIAL_DISPLAY_MANAGER_SERVICE, - "null", NULL, - "mail-transport-agent", SPECIAL_MAIL_TRANSFER_AGENT_TARGET, - "smtp", SPECIAL_MAIL_TRANSFER_AGENT_TARGET, }; unsigned i; @@ -385,8 +375,9 @@ static int sysv_translate_facility(const char *name, const char *filename, char if (!table[i+1]) return 0; - if (!(r = strdup(table[i+1]))) - return -ENOMEM; + r = strdup(table[i+1]); + if (!r) + return log_oom(); goto finish; } @@ -815,7 +806,6 @@ static int service_load_sysv_path(Service *s, const char *path) { } r = sysv_translate_facility(n, path_get_file_name(path), &m); - if (r < 0) { log_error_unit(u->id, "[%s:%u] Failed to translate LSB dependency %s, ignoring: %s", @@ -1012,14 +1002,14 @@ static int service_load_sysv_name(Service *s, const char *name) { r = service_load_sysv_path(s, path); if (r >= 0 && UNIT(s)->load_state == UNIT_STUB) { - /* Try Debian style *.sh source'able init scripts */ + /* Try *.sh source'able init scripts */ strcat(path, ".sh"); r = service_load_sysv_path(s, path); } free(path); if (r >= 0 && UNIT(s)->load_state == UNIT_STUB) { - /* Try Frugalware style rc.* init scripts */ + /* Try rc.* init scripts */ path = strjoin(*p, "/rc.", name, NULL); if (!path) @@ -1531,6 +1521,9 @@ static void service_set_state(Service *s, ServiceState state) { s->control_command_id = _SERVICE_EXEC_COMMAND_INVALID; } + if (state == SERVICE_FAILED) + service_notify_sockets_dead(s, s->result == SERVICE_FAILURE_START_LIMIT); + if (state == SERVICE_DEAD || state == SERVICE_STOP || state == SERVICE_STOP_SIGTERM || @@ -1538,7 +1531,6 @@ static void service_set_state(Service *s, ServiceState state) { state == SERVICE_STOP_POST || state == SERVICE_FINAL_SIGTERM || state == SERVICE_FINAL_SIGKILL || - state == SERVICE_FAILED || state == SERVICE_AUTO_RESTART) service_notify_sockets_dead(s, false); @@ -2926,15 +2918,25 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) { s->main_pid = 0; exec_status_exit(&s->main_exec_status, &s->exec_context, pid, code, status); - /* If this is not a forking service than the main - * process got started and hence we copy the exit - * status so that it is recorded both as main and as - * control process exit status */ if (s->main_command) { + /* If this is not a forking service than the + * main process got started and hence we copy + * the exit status so that it is recorded both + * as main and as control process exit + * status */ + s->main_command->exec_status = s->main_exec_status; if (s->main_command->ignore) f = SERVICE_SUCCESS; + } else if (s->exec_command[SERVICE_EXEC_START]) { + + /* If this is a forked process, then we should + * ignore the return value if this was + * configured for the starter process */ + + if (s->exec_command[SERVICE_EXEC_START]->ignore) + f = SERVICE_SUCCESS; } log_struct(f == SERVICE_SUCCESS ? LOG_DEBUG : LOG_NOTICE,