1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-11 09:18:07 +03:00

service: optionally, call setsid() on services

This commit is contained in:
Lennart Poettering 2010-04-07 23:23:58 +02:00
parent 0bc824be78
commit ee2b489421
3 changed files with 25 additions and 7 deletions

View File

@ -489,9 +489,16 @@ int exec_spawn(const ExecCommand *command,
goto fail; goto fail;
} }
if (setpgid(0, 0) < 0) { if (context->new_session) {
r = EXIT_PGID; if (setsid() < 0) {
goto fail; r = EXIT_SETSID;
goto fail;
}
} else {
if (setpgid(0, 0) < 0) {
r = EXIT_PGID;
goto fail;
}
} }
umask(context->umask); umask(context->umask);
@ -710,6 +717,12 @@ void exec_context_init(ExecContext *c) {
c->cpu_sched_set = false; c->cpu_sched_set = false;
CPU_ZERO(&c->cpu_affinity); CPU_ZERO(&c->cpu_affinity);
c->cpu_affinity_set = false; c->cpu_affinity_set = false;
c->timer_slack_ns = 0;
c->timer_slack_ns_set = false;
c->cpu_sched_reset_on_fork = false;
c->non_blocking = false;
c->new_session = false;
c->input = 0; c->input = 0;
c->output = 0; c->output = 0;
@ -790,11 +803,13 @@ void exec_context_dump(ExecContext *c, FILE* f, const char *prefix) {
"%sUMask: %04o\n" "%sUMask: %04o\n"
"%sWorkingDirectory: %s\n" "%sWorkingDirectory: %s\n"
"%sRootDirectory: %s\n" "%sRootDirectory: %s\n"
"%sNonBlocking: %s\n", "%sNonBlocking: %s\n"
"%sNewSession: %s\n",
prefix, c->umask, prefix, c->umask,
prefix, c->working_directory ? c->working_directory : "/", prefix, c->working_directory ? c->working_directory : "/",
prefix, c->root_directory ? c->root_directory : "/", prefix, c->root_directory ? c->root_directory : "/",
prefix, yes_no(c->non_blocking)); prefix, yes_no(c->non_blocking),
prefix, yes_no(c->new_session));
if (c->environment) if (c->environment)
for (e = c->environment; *e; e++) for (e = c->environment; *e; e++)

View File

@ -93,6 +93,7 @@ struct ExecContext {
bool cpu_sched_reset_on_fork; bool cpu_sched_reset_on_fork;
bool non_blocking; bool non_blocking;
bool new_session;
ExecInput input; ExecInput input;
ExecOutput output; ExecOutput output;
@ -148,7 +149,8 @@ typedef enum ExitStatus {
EXIT_GROUP, EXIT_GROUP,
EXIT_USER, EXIT_USER,
EXIT_CAPABILITIES, EXIT_CAPABILITIES,
EXIT_CGROUP EXIT_CGROUP, /* 220 */
EXIT_SETSID
} ExitStatus; } ExitStatus;
int exec_spawn(const ExecCommand *command, int exec_spawn(const ExecCommand *command,

View File

@ -1145,7 +1145,8 @@ static int load_from_path(Unit *u, const char *path, UnitLoadState *new_state) {
{ "LimitRTPRIO", config_parse_limit, &(context).rlimit[RLIMIT_RTPRIO], section }, \ { "LimitRTPRIO", config_parse_limit, &(context).rlimit[RLIMIT_RTPRIO], section }, \
{ "LimitRTTIME", config_parse_limit, &(context).rlimit[RLIMIT_RTTIME], section }, \ { "LimitRTTIME", config_parse_limit, &(context).rlimit[RLIMIT_RTTIME], section }, \
{ "NonBlocking", config_parse_bool, &(context).non_blocking, section }, \ { "NonBlocking", config_parse_bool, &(context).non_blocking, section }, \
{ "ControlGroup", config_parse_cgroup, u, section } \ { "ControlGroup", config_parse_cgroup, u, section }, \
{ "NewSession", config_parse_bool, &(context).new_session, section }
const ConfigItem items[] = { const ConfigItem items[] = {
{ "Names", config_parse_names, u, "Meta" }, { "Names", config_parse_names, u, "Meta" },