X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fservice.c;h=8b1fab785ac364e287befcbe14bfda708c501d08;hp=0615b51490a4235b716839ed24cce8c02745c1e2;hb=c4653a4dfe059fa5ec84157ba2cd7ab2fd7c3faa;hpb=15ca554ba3a40e6840c6d6095ec90cf448720454;ds=sidebyside diff --git a/src/service.c b/src/service.c index 0615b5149..8b1fab785 100644 --- a/src/service.c +++ b/src/service.c @@ -57,11 +57,11 @@ static const struct { { "rc5.d", SPECIAL_RUNLEVEL5_TARGET, RUNLEVEL_UP }, { "rc6.d", SPECIAL_RUNLEVEL6_TARGET, RUNLEVEL_DOWN }, - /* SuSE style boot.d */ - { "boot.d", SPECIAL_BASIC_TARGET, RUNLEVEL_BASIC }, + /* SUSE style boot.d */ + { "boot.d", SPECIAL_SYSINIT_TARGET, RUNLEVEL_BASIC }, /* Debian style rcS.d */ - { "rcS.d", SPECIAL_BASIC_TARGET, RUNLEVEL_BASIC }, + { "rcS.d", SPECIAL_SYSINIT_TARGET, RUNLEVEL_BASIC }, }; #define RUNLEVELS_UP "12345" @@ -191,13 +191,19 @@ static char *sysv_translate_name(const char *name) { static int sysv_translate_facility(const char *name, char **_r) { static const char * const table[] = { + /* LSB defined facilities */ "$local_fs", SPECIAL_LOCAL_FS_TARGET, "$network", SPECIAL_NETWORK_TARGET, "$named", SPECIAL_NSS_LOOKUP_TARGET, "$portmap", SPECIAL_RPCBIND_TARGET, "$remote_fs", SPECIAL_REMOTE_FS_TARGET, "$syslog", SPECIAL_SYSLOG_TARGET, - "$time", SPECIAL_RTC_SET_TARGET + "$time", SPECIAL_RTC_SET_TARGET, + + /* Debian extensions */ + "$mail-transport-agent", SPECIAL_MAIL_TRANSFER_AGENT_TARGET, + "$mail-transfer-agent", SPECIAL_MAIL_TRANSFER_AGENT_TARGET, + "$x-display-manager", SPECIAL_DISPLAY_MANAGER_SERVICE }; unsigned i; @@ -334,9 +340,6 @@ static int service_load_sysv_path(Service *s, const char *path) { goto finish; } - s->type = SERVICE_FORKING; - s->restart = SERVICE_ONCE; - free(s->sysv_path); if (!(s->sysv_path = strdup(path))) { r = -ENOMEM; @@ -379,7 +382,7 @@ static int service_load_sysv_path(Service *s, const char *path) { /* Try to parse Red Hat style chkconfig headers */ - if (startswith(t, "chkconfig:")) { + if (startswith_no_case(t, "chkconfig:")) { int start_priority; char runlevels[16], *k; @@ -416,7 +419,7 @@ static int service_load_sysv_path(Service *s, const char *path) { s->sysv_runlevels = d; } - } else if (startswith(t, "description:")) { + } else if (startswith_no_case(t, "description:")) { size_t k = strlen(t); char *d; @@ -434,7 +437,7 @@ static int service_load_sysv_path(Service *s, const char *path) { free(u->meta.description); u->meta.description = d; - } else if (startswith(t, "pidfile:")) { + } else if (startswith_no_case(t, "pidfile:")) { char *fn; @@ -479,7 +482,7 @@ static int service_load_sysv_path(Service *s, const char *path) { } else if (state == LSB || state == LSB_DESCRIPTION) { - if (startswith(t, "Provides:")) { + if (startswith_no_case(t, "Provides:")) { char *i, *w; size_t z; @@ -515,8 +518,10 @@ static int service_load_sysv_path(Service *s, const char *path) { goto finish; } - } else if (startswith(t, "Required-Start:") || - startswith(t, "Should-Start:")) { + } else if (startswith_no_case(t, "Required-Start:") || + startswith_no_case(t, "Should-Start:") || + startswith_no_case(t, "X-Start-Before:") || + startswith_no_case(t, "X-Start-After:")) { char *i, *w; size_t z; @@ -539,13 +544,13 @@ static int service_load_sysv_path(Service *s, const char *path) { if (r == 0) continue; - r = unit_add_dependency_by_name(u, UNIT_AFTER, m, NULL, true); + r = unit_add_dependency_by_name(u, startswith_no_case(t, "X-Start-Before:") ? UNIT_BEFORE : UNIT_AFTER, m, NULL, true); free(m); if (r < 0) goto finish; } - } else if (startswith(t, "Default-Start:")) { + } else if (startswith_no_case(t, "Default-Start:")) { char *k, *d; state = LSB; @@ -562,7 +567,7 @@ static int service_load_sysv_path(Service *s, const char *path) { s->sysv_runlevels = d; } - } else if (startswith(t, "Description:")) { + } else if (startswith_no_case(t, "Description:")) { char *d; state = LSB_DESCRIPTION; @@ -575,7 +580,7 @@ static int service_load_sysv_path(Service *s, const char *path) { free(u->meta.description); u->meta.description = d; - } else if (startswith(t, "Short-Description:") && + } else if (startswith_no_case(t, "Short-Description:") && !u->meta.description) { char *d; @@ -591,6 +596,19 @@ static int service_load_sysv_path(Service *s, const char *path) { u->meta.description = d; + } else if (startswith_no_case(t, "X-Interactive:")) { + int b; + + if ((b = parse_boolean(strstrip(t+14))) < 0) { + log_warning("[%s:%u] Couldn't parse interactive flag. Ignoring.", path, line); + continue; + } + + if (b) + s->exec_context.std_input = EXEC_INPUT_TTY; + else + s->exec_context.std_input = EXEC_INPUT_NULL; + } else if (state == LSB_DESCRIPTION) { if (startswith(l, "#\t") || startswith(l, "# ")) { @@ -629,13 +647,10 @@ static int service_load_sysv_path(Service *s, const char *path) { s->timeout_usec = 0; /* Special setting for all SysV services */ + s->type = SERVICE_FORKING; s->valid_no_process = true; s->kill_mode = KILL_PROCESS_GROUP; - - /* For SysV services log output should go to the console */ - s->exec_context.std_input = EXEC_INPUT_NULL; - s->exec_context.std_output = EXEC_OUTPUT_TTY; - s->exec_context.std_error = EXEC_OUTPUT_TTY; + s->restart = SERVICE_ONCE; u->meta.load_state = UNIT_LOADED; r = 0; @@ -654,6 +669,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; @@ -667,7 +688,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); } @@ -675,7 +696,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; @@ -1707,7 +1728,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; @@ -1942,14 +1963,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);