X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fcore%2Fservice.c;h=5dc06b36cc221948b61343aa2a31643b6627ae59;hb=d4943dc7559dff51d4d3bb737232b9328d6726e1;hp=8941271679adde950d7471d5b854cc46b254b614;hpb=98709151f3e782eb508ba15e2a12c0b46003f061;p=elogind.git diff --git a/src/core/service.c b/src/core/service.c index 894127167..5dc06b36c 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -722,7 +722,7 @@ static int service_load_sysv_path(Service *s, const char *path) { char *d = NULL; if (chkconfig_description) - d = join(chkconfig_description, " ", j, NULL); + d = strjoin(chkconfig_description, " ", j, NULL); else d = strdup(j); @@ -879,7 +879,7 @@ static int service_load_sysv_path(Service *s, const char *path) { char *d = NULL; if (long_description) - d = join(long_description, " ", t, NULL); + d = strjoin(long_description, " ", t, NULL); else d = strdup(j); @@ -928,10 +928,6 @@ static int service_load_sysv_path(Service *s, const char *path) { s->guess_main_pid = false; s->restart = SERVICE_RESTART_NO; s->exec_context.ignore_sigpipe = false; - - if (UNIT(s)->manager->sysv_console) - s->exec_context.std_output = EXEC_OUTPUT_JOURNAL_AND_CONSOLE; - s->exec_context.kill_mode = KILL_PROCESS; /* We use the long description only if @@ -1005,7 +1001,7 @@ static int service_load_sysv_name(Service *s, const char *name) { char *path; int r; - path = join(*p, "/", name, NULL); + path = strjoin(*p, "/", name, NULL); if (!path) return -ENOMEM; @@ -1027,7 +1023,7 @@ static int service_load_sysv_name(Service *s, const char *name) { if (r >= 0 && UNIT(s)->load_state == UNIT_STUB) { /* Try SUSE style boot.* init scripts */ - path = join(*p, "/boot.", name, NULL); + path = strjoin(*p, "/boot.", name, NULL); if (!path) return -ENOMEM; @@ -1042,7 +1038,7 @@ static int service_load_sysv_name(Service *s, const char *name) { if (r >= 0 && UNIT(s)->load_state == UNIT_STUB) { /* Try Frugalware style rc.* init scripts */ - path = join(*p, "/rc.", name, NULL); + path = strjoin(*p, "/rc.", name, NULL); if (!path) return -ENOMEM; @@ -1286,6 +1282,10 @@ static int service_load(Unit *u) { if (UNIT(s)->default_dependencies) if ((r = service_add_default_dependencies(s)) < 0) return r; + + r = unit_patch_working_directory(UNIT(s), &s->exec_context); + if (r < 0) + return r; } return service_verify(s); @@ -1810,6 +1810,7 @@ static int service_spawn( UNIT(s)->cgroup_bondings, UNIT(s)->cgroup_attributes, is_control ? "control" : NULL, + UNIT(s)->id, s->type == SERVICE_IDLE ? UNIT(s)->manager->idle_pipe : NULL, &pid); @@ -1891,6 +1892,8 @@ static void service_enter_dead(Service *s, ServiceResult f, bool allow_restart) if (f != SERVICE_SUCCESS) s->result = f; + service_set_state(s, s->result != SERVICE_SUCCESS ? SERVICE_FAILED : SERVICE_DEAD); + if (allow_restart && !s->forbid_restart && (s->restart == SERVICE_RESTART_ALWAYS || @@ -1904,8 +1907,7 @@ static void service_enter_dead(Service *s, ServiceResult f, bool allow_restart) goto fail; service_set_state(s, SERVICE_AUTO_RESTART); - } else - service_set_state(s, s->result != SERVICE_SUCCESS ? SERVICE_FAILED : SERVICE_DEAD); + } s->forbid_restart = false; @@ -2256,10 +2258,12 @@ static void service_enter_restart(Service *s) { assert(s); dbus_error_init(&error); - if (UNIT(s)->job) { - log_info("Job pending for unit, delaying automatic restart."); + if (UNIT(s)->job && UNIT(s)->job->type == JOB_STOP) { + /* Don't restart things if we are going down anyway */ + log_info("Stop job pending for unit, delaying automatic restart."); - if ((r = unit_watch_timer(UNIT(s), s->restart_usec, &s->timer_watch)) < 0) + r = unit_watch_timer(UNIT(s), s->restart_usec, &s->timer_watch); + if (r < 0) goto fail; return; @@ -2273,6 +2277,10 @@ static void service_enter_restart(Service *s) { if (r < 0) goto fail; + /* Note that we stay in the SERVICE_AUTO_RESTART state here, + * it will be canceled as part of the service_stop() call that + * is executed as part of JOB_RESTART. */ + log_debug("%s scheduled restart job.", UNIT(s)->id); return; @@ -2466,13 +2474,14 @@ static int service_start(Unit *u) { return 0; /* A service that will be restarted must be stopped first to - * trigger BindTo and/or OnFailure dependencies. If a user + * trigger BindsTo and/or OnFailure dependencies. If a user * does not want to wait for the holdoff time to elapse, the - * service should be manually restarted, not started. */ - if (s->state == SERVICE_AUTO_RESTART) { - log_warning("%s automatic restart is pending, must be stopped before issuing start request.", UNIT(s)->id); - return -ECANCELED; - } + * service should be manually restarted, not started. We + * simply return EAGAIN here, so that any start jobs stay + * queued, and assume that the auto restart timer will + * eventually trigger the restart. */ + if (s->state == SERVICE_AUTO_RESTART) + return -EAGAIN; assert(s->state == SERVICE_DEAD || s->state == SERVICE_FAILED); @@ -2512,7 +2521,7 @@ static int service_stop(Unit *u) { /* A restart will be scheduled or is in progress. */ if (s->state == SERVICE_AUTO_RESTART) { - service_enter_dead(s, SERVICE_SUCCESS, false); + service_set_state(s, SERVICE_DEAD); return 0; } @@ -3230,7 +3239,7 @@ static void service_cgroup_notify_event(Unit *u) { case SERVICE_FINAL_SIGTERM: case SERVICE_FINAL_SIGKILL: if (main_pid_good(s) <= 0 && !control_pid_good(s)) - service_enter_dead(s, SERVICE_SUCCESS, SERVICE_SUCCESS); + service_enter_dead(s, SERVICE_SUCCESS, true); break; @@ -3409,7 +3418,7 @@ static int service_enumerate(Manager *m) { struct dirent *de; free(path); - path = join(*p, "/", rcnd_table[i].path, NULL); + path = strjoin(*p, "/", rcnd_table[i].path, NULL); if (!path) { r = -ENOMEM; goto finish; @@ -3444,7 +3453,7 @@ static int service_enumerate(Manager *m) { continue; free(fpath); - fpath = join(path, "/", de->d_name, NULL); + fpath = strjoin(path, "/", de->d_name, NULL); if (!fpath) { r = -ENOMEM; goto finish; @@ -3657,6 +3666,8 @@ static void service_reset_failed(Unit *u) { s->result = SERVICE_SUCCESS; s->reload_result = SERVICE_SUCCESS; + + RATELIMIT_RESET(s->start_limit); } static int service_kill(Unit *u, KillWho who, KillMode mode, int signo, DBusError *error) { @@ -3798,7 +3809,6 @@ static const char* const start_limit_action_table[_SERVICE_START_LIMIT_MAX] = { DEFINE_STRING_TABLE_LOOKUP(start_limit_action, StartLimitAction); const UnitVTable service_vtable = { - .suffix = ".service", .object_size = sizeof(Service), .sections = "Unit\0"