X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fexecute.c;h=10ce951c599fb02ecede8ca9718b9a14b8286956;hb=ba035df230e41bf9d70ebb47915c9472b7884412;hp=b5afa681082c7cfa2d07bc6dfd95b71a6162693d;hpb=52661efd21608dc7e0ac26b714a9254ed6180ddb;p=elogind.git diff --git a/src/execute.c b/src/execute.c index b5afa6810..10ce951c5 100644 --- a/src/execute.c +++ b/src/execute.c @@ -1252,7 +1252,7 @@ int exec_spawn(ExecCommand *command, } } - if (!(our_env = new0(char*, 6))) { + if (!(our_env = new0(char*, 7))) { r = EXIT_MEMORY; goto fail; } @@ -1277,7 +1277,15 @@ int exec_spawn(ExecCommand *command, goto fail; } - assert(n_env <= 6); + if (is_terminal_input(context->std_input) || + context->std_output == EXEC_OUTPUT_TTY || + context->std_error == EXEC_OUTPUT_TTY) + if (!(our_env[n_env++] = strdup(default_term_for_tty(tty_path(context))))) { + r = EXIT_MEMORY; + goto fail; + } + + assert(n_env <= 7); if (!(final_env = strv_env_merge( 4, @@ -1295,6 +1303,8 @@ int exec_spawn(ExecCommand *command, goto fail; } + final_env = strv_env_clean(final_env); + execve(command->path, final_argv, final_env); r = EXIT_EXEC; @@ -1339,6 +1349,7 @@ void exec_context_init(ExecContext *c) { c->syslog_level_prefix = true; c->mount_flags = MS_SHARED; c->kill_signal = SIGTERM; + c->send_sigkill = true; } void exec_context_done(ExecContext *c) { @@ -1396,6 +1407,9 @@ void exec_context_done(ExecContext *c) { if (c->cpuset) CPU_FREE(c->cpuset); + + free(c->utmp_id); + c->utmp_id = NULL; } void exec_command_done(ExecCommand *c) { @@ -1605,9 +1619,11 @@ void exec_context_dump(ExecContext *c, FILE* f, const char *prefix) { fprintf(f, "%sKillMode: %s\n" - "%sKillSignal: SIG%s\n", + "%sKillSignal: SIG%s\n" + "%sSendSIGKILL: %s\n", prefix, kill_mode_to_string(c->kill_mode), - prefix, signal_to_string(c->kill_signal)); + prefix, signal_to_string(c->kill_signal), + prefix, yes_no(c->send_sigkill)); if (c->utmp_id) fprintf(f, @@ -1797,6 +1813,8 @@ static const char* const exec_input_table[_EXEC_INPUT_MAX] = { [EXEC_INPUT_SOCKET] = "socket" }; +DEFINE_STRING_TABLE_LOOKUP(exec_input, ExecInput); + static const char* const exec_output_table[_EXEC_OUTPUT_MAX] = { [EXEC_OUTPUT_INHERIT] = "inherit", [EXEC_OUTPUT_NULL] = "null", @@ -1808,4 +1826,19 @@ static const char* const exec_output_table[_EXEC_OUTPUT_MAX] = { DEFINE_STRING_TABLE_LOOKUP(exec_output, ExecOutput); -DEFINE_STRING_TABLE_LOOKUP(exec_input, ExecInput); +static const char* const kill_mode_table[_KILL_MODE_MAX] = { + [KILL_CONTROL_GROUP] = "control-group", + [KILL_PROCESS_GROUP] = "process-group", + [KILL_PROCESS] = "process", + [KILL_NONE] = "none" +}; + +DEFINE_STRING_TABLE_LOOKUP(kill_mode, KillMode); + +static const char* const kill_who_table[_KILL_WHO_MAX] = { + [KILL_MAIN] = "main", + [KILL_CONTROL] = "control", + [KILL_ALL] = "all" +}; + +DEFINE_STRING_TABLE_LOOKUP(kill_who, KillWho);