chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
shared/utf8: mark char* as const
[elogind.git]
/
src
/
core
/
service.c
diff --git
a/src/core/service.c
b/src/core/service.c
index 5dc06b36cc221948b61343aa2a31643b6627ae59..e74da54eac5b288ed54c7c839335fb73a460807e 100644
(file)
--- a/
src/core/service.c
+++ b/
src/core/service.c
@@
-130,12
+130,12
@@
static const UnitActiveState state_translation_table_idle[_SERVICE_STATE_MAX] =
static void service_init(Unit *u) {
Service *s = SERVICE(u);
static void service_init(Unit *u) {
Service *s = SERVICE(u);
- int i;
assert(u);
assert(u->load_state == UNIT_STUB);
assert(u);
assert(u->load_state == UNIT_STUB);
- s->timeout_usec = DEFAULT_TIMEOUT_USEC;
+ s->timeout_start_usec = DEFAULT_TIMEOUT_USEC;
+ s->timeout_stop_usec = DEFAULT_TIMEOUT_USEC;
s->restart_usec = DEFAULT_RESTART_USEC;
s->type = _SERVICE_TYPE_INVALID;
s->restart_usec = DEFAULT_RESTART_USEC;
s->type = _SERVICE_TYPE_INVALID;
@@
-150,9
+150,7
@@
static void service_init(Unit *u) {
s->guess_main_pid = true;
exec_context_init(&s->exec_context);
s->guess_main_pid = true;
exec_context_init(&s->exec_context);
- for (i = 0; i < RLIMIT_NLIMITS; i++)
- if (UNIT(s)->manager->rlimit[i])
- s->exec_context.rlimit[i] = newdup(struct rlimit, UNIT(s)->manager->rlimit[i], 1);
+ kill_context_init(&s->kill_context);
RATELIMIT_INIT(s->start_limit, 10*USEC_PER_SEC, 5);
RATELIMIT_INIT(s->start_limit, 10*USEC_PER_SEC, 5);
@@
-567,7
+565,6
@@
static int service_load_sysv_path(Service *s, const char *path) {
goto finish;
}
goto finish;
}
- zero(st);
if (fstat(fileno(f), &st) < 0) {
r = -errno;
goto finish;
if (fstat(fileno(f), &st) < 0) {
r = -errno;
goto finish;
@@
-918,9
+915,13
@@
static int service_load_sysv_path(Service *s, const char *path) {
UNIT(s)->default_dependencies = false;
/* Don't timeout special services during boot (like fsck) */
UNIT(s)->default_dependencies = false;
/* Don't timeout special services during boot (like fsck) */
- s->timeout_usec = 0;
- } else
- s->timeout_usec = DEFAULT_SYSV_TIMEOUT_USEC;
+ s->timeout_start_usec = 0;
+ s->timeout_stop_usec = 0;
+ } else {
+ s->timeout_start_usec = DEFAULT_SYSV_TIMEOUT_USEC;
+ s->timeout_stop_usec = DEFAULT_SYSV_TIMEOUT_USEC;
+ }
+
/* Special setting for all SysV services */
s->type = SERVICE_FORKING;
/* Special setting for all SysV services */
s->type = SERVICE_FORKING;
@@
-928,7
+929,7
@@
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;
s->guess_main_pid = false;
s->restart = SERVICE_RESTART_NO;
s->exec_context.ignore_sigpipe = false;
- s->
exec
_context.kill_mode = KILL_PROCESS;
+ s->
kill
_context.kill_mode = KILL_PROCESS;
/* We use the long description only if
* no short description is set. */
/* We use the long description only if
* no short description is set. */
@@
-1164,7
+1165,7
@@
static int service_verify(Service *s) {
if (s->bus_name && s->type != SERVICE_DBUS)
log_warning("%s has a D-Bus service name specified, but is not of type dbus. Ignoring.", UNIT(s)->id);
if (s->bus_name && s->type != SERVICE_DBUS)
log_warning("%s has a D-Bus service name specified, but is not of type dbus. Ignoring.", UNIT(s)->id);
- if (s->exec_context.pam_name && s->
exec
_context.kill_mode != KILL_CONTROL_GROUP) {
+ if (s->exec_context.pam_name && s->
kill
_context.kill_mode != KILL_CONTROL_GROUP) {
log_error("%s has PAM enabled. Kill mode must be set to 'control-group'. Refusing.", UNIT(s)->id);
return -EINVAL;
}
log_error("%s has PAM enabled. Kill mode must be set to 'control-group'. Refusing.", UNIT(s)->id);
return -EINVAL;
}
@@
-1245,9
+1246,9
@@
static int service_load(Unit *u) {
if (s->type == _SERVICE_TYPE_INVALID)
s->type = s->bus_name ? SERVICE_DBUS : SERVICE_SIMPLE;
if (s->type == _SERVICE_TYPE_INVALID)
s->type = s->bus_name ? SERVICE_DBUS : SERVICE_SIMPLE;
- /* Oneshot services have disabled timeout by default */
- if (s->type == SERVICE_ONESHOT && !s->timeout_defined)
- s->timeout_usec = 0;
+ /* Oneshot services have disabled
start
timeout by default */
+ if (s->type == SERVICE_ONESHOT && !s->
start_
timeout_defined)
+ s->timeout_
start_
usec = 0;
service_fix_output(s);
service_fix_output(s);
@@
-1283,7
+1284,7
@@
static int service_load(Unit *u) {
if ((r = service_add_default_dependencies(s)) < 0)
return r;
if ((r = service_add_default_dependencies(s)) < 0)
return r;
- r = unit_
patch_working_directory(UNIT(s)
, &s->exec_context);
+ r = unit_
exec_context_defaults(u
, &s->exec_context);
if (r < 0)
return r;
}
if (r < 0)
return r;
}
@@
-1351,6
+1352,7
@@
static void service_dump(Unit *u, FILE *f, const char *prefix) {
prefix, s->bus_name,
prefix, yes_no(s->bus_name_good));
prefix, s->bus_name,
prefix, yes_no(s->bus_name_good));
+ kill_context_dump(&s->kill_context, f, prefix);
exec_context_dump(&s->exec_context, f, prefix);
for (c = 0; c < _SERVICE_EXEC_COMMAND_MAX; c++) {
exec_context_dump(&s->exec_context, f, prefix);
for (c = 0; c < _SERVICE_EXEC_COMMAND_MAX; c++) {
@@
-1606,11
+1608,10
@@
static int service_coldplug(Unit *u) {
s->deserialized_state == SERVICE_FINAL_SIGTERM ||
s->deserialized_state == SERVICE_FINAL_SIGKILL ||
s->deserialized_state == SERVICE_AUTO_RESTART) {
s->deserialized_state == SERVICE_FINAL_SIGTERM ||
s->deserialized_state == SERVICE_FINAL_SIGKILL ||
s->deserialized_state == SERVICE_AUTO_RESTART) {
-
- if (s->deserialized_state == SERVICE_AUTO_RESTART || s->timeout_usec > 0) {
+ if (s->deserialized_state == SERVICE_AUTO_RESTART || s->timeout_start_usec > 0) {
usec_t k;
usec_t k;
- k = s->deserialized_state == SERVICE_AUTO_RESTART ? s->restart_usec : s->timeout_usec;
+ k = s->deserialized_state == SERVICE_AUTO_RESTART ? s->restart_usec : s->timeout_
start_
usec;
if ((r = unit_watch_timer(UNIT(s), k, &s->timer_watch)) < 0)
return r;
if ((r = unit_watch_timer(UNIT(s), k, &s->timer_watch)) < 0)
return r;
@@
-1756,8
+1757,9
@@
static int service_spawn(
}
}
}
}
- if (timeout && s->timeout_usec) {
- if ((r = unit_watch_timer(UNIT(s), s->timeout_usec, &s->timer_watch)) < 0)
+ if (timeout && s->timeout_start_usec) {
+ r = unit_watch_timer(UNIT(s), s->timeout_start_usec, &s->timer_watch);
+ if (r < 0)
goto fail;
} else
unit_unwatch_timer(UNIT(s), &s->timer_watch);
goto fail;
} else
unit_unwatch_timer(UNIT(s), &s->timer_watch);
@@
-1967,8
+1969,8
@@
static void service_enter_signal(Service *s, ServiceState state, ServiceResult f
if (f != SERVICE_SUCCESS)
s->result = f;
if (f != SERVICE_SUCCESS)
s->result = f;
- if (s->
exec
_context.kill_mode != KILL_NONE) {
- int sig = (state == SERVICE_STOP_SIGTERM || state == SERVICE_FINAL_SIGTERM) ? s->
exec
_context.kill_signal : SIGKILL;
+ if (s->
kill
_context.kill_mode != KILL_NONE) {
+ int sig = (state == SERVICE_STOP_SIGTERM || state == SERVICE_FINAL_SIGTERM) ? s->
kill
_context.kill_signal : SIGKILL;
if (s->main_pid > 0) {
if (kill_and_sigcont(s->main_pid, sig) < 0 && errno != ESRCH)
if (s->main_pid > 0) {
if (kill_and_sigcont(s->main_pid, sig) < 0 && errno != ESRCH)
@@
-1984,9
+1986,10
@@
static void service_enter_signal(Service *s, ServiceState state, ServiceResult f
wait_for_exit = true;
}
wait_for_exit = true;
}
- if (s->
exec
_context.kill_mode == KILL_CONTROL_GROUP) {
+ if (s->
kill
_context.kill_mode == KILL_CONTROL_GROUP) {
- if (!(pid_set = set_new(trivial_hash_func, trivial_compare_func))) {
+ pid_set = set_new(trivial_hash_func, trivial_compare_func);
+ if (!pid_set) {
r = -ENOMEM;
goto fail;
}
r = -ENOMEM;
goto fail;
}
@@
-2013,9
+2016,11
@@
static void service_enter_signal(Service *s, ServiceState state, ServiceResult f
}
if (wait_for_exit) {
}
if (wait_for_exit) {
- if (s->timeout_usec > 0)
- if ((r = unit_watch_timer(UNIT(s), s->timeout_usec, &s->timer_watch)) < 0)
+ if (s->timeout_stop_usec > 0) {
+ r = unit_watch_timer(UNIT(s), s->timeout_stop_usec, &s->timer_watch);
+ if (r < 0)
goto fail;
goto fail;
+ }
service_set_state(s, state);
} else if (state == SERVICE_STOP_SIGTERM || state == SERVICE_STOP_SIGKILL)
service_set_state(s, state);
} else if (state == SERVICE_STOP_SIGTERM || state == SERVICE_STOP_SIGKILL)
@@
-3144,7
+3149,7
@@
static void service_timer_event(Unit *u, uint64_t elapsed, Watch* w) {
break;
case SERVICE_STOP_SIGTERM:
break;
case SERVICE_STOP_SIGTERM:
- if (s->
exec
_context.send_sigkill) {
+ if (s->
kill
_context.send_sigkill) {
log_warning("%s stopping timed out. Killing.", u->id);
service_enter_signal(s, SERVICE_STOP_SIGKILL, SERVICE_FAILURE_TIMEOUT);
} else {
log_warning("%s stopping timed out. Killing.", u->id);
service_enter_signal(s, SERVICE_STOP_SIGKILL, SERVICE_FAILURE_TIMEOUT);
} else {
@@
-3169,7
+3174,7
@@
static void service_timer_event(Unit *u, uint64_t elapsed, Watch* w) {
break;
case SERVICE_FINAL_SIGTERM:
break;
case SERVICE_FINAL_SIGTERM:
- if (s->
exec
_context.send_sigkill) {
+ if (s->
kill
_context.send_sigkill) {
log_warning("%s stopping timed out (2). Killing.", u->id);
service_enter_signal(s, SERVICE_FINAL_SIGKILL, SERVICE_FAILURE_TIMEOUT);
} else {
log_warning("%s stopping timed out (2). Killing.", u->id);
service_enter_signal(s, SERVICE_FINAL_SIGKILL, SERVICE_FAILURE_TIMEOUT);
} else {
@@
-3670,7
+3675,7
@@
static void service_reset_failed(Unit *u) {
RATELIMIT_RESET(s->start_limit);
}
RATELIMIT_RESET(s->start_limit);
}
-static int service_kill(Unit *u, KillWho who,
KillMode mode,
int signo, DBusError *error) {
+static int service_kill(Unit *u, KillWho who, int signo, DBusError *error) {
Service *s = SERVICE(u);
int r = 0;
Set *pid_set = NULL;
Service *s = SERVICE(u);
int r = 0;
Set *pid_set = NULL;
@@
-3697,28
+3702,33
@@
static int service_kill(Unit *u, KillWho who, KillMode mode, int signo, DBusErro
if (kill(s->main_pid, signo) < 0)
r = -errno;
if (kill(s->main_pid, signo) < 0)
r = -errno;
- if (who == KILL_ALL
&& mode == KILL_CONTROL_GROUP
) {
+ if (who == KILL_ALL) {
int q;
int q;
- if (!(pid_set = set_new(trivial_hash_func, trivial_compare_func)))
+ pid_set = set_new(trivial_hash_func, trivial_compare_func);
+ if (!pid_set)
return -ENOMEM;
/* Exclude the control/main pid from being killed via the cgroup */
return -ENOMEM;
/* Exclude the control/main pid from being killed via the cgroup */
- if (s->control_pid > 0)
- if ((q = set_put(pid_set, LONG_TO_PTR(s->control_pid))) < 0) {
+ if (s->control_pid > 0) {
+ q = set_put(pid_set, LONG_TO_PTR(s->control_pid));
+ if (q < 0) {
r = q;
goto finish;
}
r = q;
goto finish;
}
+ }
- if (s->main_pid > 0)
- if ((q = set_put(pid_set, LONG_TO_PTR(s->main_pid))) < 0) {
+ if (s->main_pid > 0) {
+ q = set_put(pid_set, LONG_TO_PTR(s->main_pid));
+ if (q < 0) {
r = q;
goto finish;
}
r = q;
goto finish;
}
+ }
+
q = cgroup_bonding_kill_list(UNIT(s)->cgroup_bondings, signo, false, false, pid_set, NULL);
q = cgroup_bonding_kill_list(UNIT(s)->cgroup_bondings, signo, false, false, pid_set, NULL);
- if (q < 0)
- if (q != -EAGAIN && q != -ESRCH && q != -ENOENT)
- r = q;
+ if (q < 0 && q != -EAGAIN && q != -ESRCH && q != -ENOENT)
+ r = q;
}
finish:
}
finish: