execute: if the main process of a service already owns the TTY, don't wait for acquiring it again in the reload/stop step
This commit is contained in:
parent
398ef8ba02
commit
1e3ad081ef
|
@ -232,7 +232,10 @@ static bool is_terminal_input(ExecInput i) {
|
||||||
i == EXEC_INPUT_TTY_FAIL;
|
i == EXEC_INPUT_TTY_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int fixup_input(ExecInput std_input, int socket_fd) {
|
static int fixup_input(ExecInput std_input, int socket_fd, bool apply_tty_stdin) {
|
||||||
|
|
||||||
|
if (is_terminal_input(std_input) && !apply_tty_stdin)
|
||||||
|
return EXEC_INPUT_NULL;
|
||||||
|
|
||||||
if (std_input == EXEC_INPUT_SOCKET && socket_fd < 0)
|
if (std_input == EXEC_INPUT_SOCKET && socket_fd < 0)
|
||||||
return EXEC_INPUT_NULL;
|
return EXEC_INPUT_NULL;
|
||||||
|
@ -248,12 +251,12 @@ static int fixup_output(ExecOutput std_output, int socket_fd) {
|
||||||
return std_output;
|
return std_output;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int setup_input(const ExecContext *context, int socket_fd) {
|
static int setup_input(const ExecContext *context, int socket_fd, bool apply_tty_stdin) {
|
||||||
ExecInput i;
|
ExecInput i;
|
||||||
|
|
||||||
assert(context);
|
assert(context);
|
||||||
|
|
||||||
i = fixup_input(context->std_input, socket_fd);
|
i = fixup_input(context->std_input, socket_fd, apply_tty_stdin);
|
||||||
|
|
||||||
switch (i) {
|
switch (i) {
|
||||||
|
|
||||||
|
@ -289,14 +292,14 @@ static int setup_input(const ExecContext *context, int socket_fd) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int setup_output(const ExecContext *context, int socket_fd, const char *ident) {
|
static int setup_output(const ExecContext *context, int socket_fd, const char *ident, bool apply_tty_stdin) {
|
||||||
ExecOutput o;
|
ExecOutput o;
|
||||||
ExecInput i;
|
ExecInput i;
|
||||||
|
|
||||||
assert(context);
|
assert(context);
|
||||||
assert(ident);
|
assert(ident);
|
||||||
|
|
||||||
i = fixup_input(context->std_input, socket_fd);
|
i = fixup_input(context->std_input, socket_fd, apply_tty_stdin);
|
||||||
o = fixup_output(context->std_output, socket_fd);
|
o = fixup_output(context->std_output, socket_fd);
|
||||||
|
|
||||||
/* This expects the input is already set up */
|
/* This expects the input is already set up */
|
||||||
|
@ -339,14 +342,14 @@ static int setup_output(const ExecContext *context, int socket_fd, const char *i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int setup_error(const ExecContext *context, int socket_fd, const char *ident) {
|
static int setup_error(const ExecContext *context, int socket_fd, const char *ident, bool apply_tty_stdin) {
|
||||||
ExecOutput o, e;
|
ExecOutput o, e;
|
||||||
ExecInput i;
|
ExecInput i;
|
||||||
|
|
||||||
assert(context);
|
assert(context);
|
||||||
assert(ident);
|
assert(ident);
|
||||||
|
|
||||||
i = fixup_input(context->std_input, socket_fd);
|
i = fixup_input(context->std_input, socket_fd, apply_tty_stdin);
|
||||||
o = fixup_output(context->std_output, socket_fd);
|
o = fixup_output(context->std_output, socket_fd);
|
||||||
e = fixup_output(context->std_error, socket_fd);
|
e = fixup_output(context->std_error, socket_fd);
|
||||||
|
|
||||||
|
@ -889,6 +892,7 @@ int exec_spawn(ExecCommand *command,
|
||||||
char **environment,
|
char **environment,
|
||||||
bool apply_permissions,
|
bool apply_permissions,
|
||||||
bool apply_chroot,
|
bool apply_chroot,
|
||||||
|
bool apply_tty_stdin,
|
||||||
bool confirm_spawn,
|
bool confirm_spawn,
|
||||||
CGroupBonding *cgroup_bondings,
|
CGroupBonding *cgroup_bondings,
|
||||||
pid_t *ret) {
|
pid_t *ret) {
|
||||||
|
@ -985,7 +989,9 @@ int exec_spawn(ExecCommand *command,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (confirm_spawn) {
|
/* We skip the confirmation step if we shall not apply the TTY */
|
||||||
|
if (confirm_spawn &&
|
||||||
|
(!is_terminal_input(context->std_input) || apply_tty_stdin)) {
|
||||||
char response;
|
char response;
|
||||||
|
|
||||||
/* Set up terminal for the question */
|
/* Set up terminal for the question */
|
||||||
|
@ -1018,18 +1024,18 @@ int exec_spawn(ExecCommand *command,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!keep_stdin)
|
if (!keep_stdin)
|
||||||
if (setup_input(context, socket_fd) < 0) {
|
if (setup_input(context, socket_fd, apply_tty_stdin) < 0) {
|
||||||
r = EXIT_STDIN;
|
r = EXIT_STDIN;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!keep_stdout)
|
if (!keep_stdout)
|
||||||
if (setup_output(context, socket_fd, file_name_from_path(command->path)) < 0) {
|
if (setup_output(context, socket_fd, file_name_from_path(command->path), apply_tty_stdin) < 0) {
|
||||||
r = EXIT_STDOUT;
|
r = EXIT_STDOUT;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (setup_error(context, socket_fd, file_name_from_path(command->path)) < 0) {
|
if (setup_error(context, socket_fd, file_name_from_path(command->path), apply_tty_stdin) < 0) {
|
||||||
r = EXIT_STDERR;
|
r = EXIT_STDERR;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
|
@ -196,6 +196,7 @@ int exec_spawn(ExecCommand *command,
|
||||||
char **environment,
|
char **environment,
|
||||||
bool apply_permissions,
|
bool apply_permissions,
|
||||||
bool apply_chroot,
|
bool apply_chroot,
|
||||||
|
bool apply_tty_stdin,
|
||||||
bool confirm_spawn,
|
bool confirm_spawn,
|
||||||
struct CGroupBonding *cgroup_bondings,
|
struct CGroupBonding *cgroup_bondings,
|
||||||
pid_t *ret);
|
pid_t *ret);
|
||||||
|
|
|
@ -70,7 +70,7 @@ int kmod_setup(void) {
|
||||||
command.argv = (char**) cmdline;
|
command.argv = (char**) cmdline;
|
||||||
|
|
||||||
exec_context_init(&context);
|
exec_context_init(&context);
|
||||||
r = exec_spawn(&command, NULL, &context, NULL, 0, NULL, false, false, false, NULL, &pid);
|
r = exec_spawn(&command, NULL, &context, NULL, 0, NULL, false, false, false, false, NULL, &pid);
|
||||||
exec_context_done(&context);
|
exec_context_done(&context);
|
||||||
|
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
|
|
|
@ -1273,7 +1273,7 @@ static int transaction_add_job_and_dependencies(
|
||||||
assert(unit);
|
assert(unit);
|
||||||
|
|
||||||
if (unit->meta.load_state != UNIT_LOADED) {
|
if (unit->meta.load_state != UNIT_LOADED) {
|
||||||
dbus_set_error(e, BUS_ERROR_LOAD_FAILED, "Unit %s failed to load.", unit->meta.id);
|
dbus_set_error(e, BUS_ERROR_LOAD_FAILED, "Unit %s failed to load. See logs for details.", unit->meta.id);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -535,6 +535,7 @@ static int mount_spawn(Mount *m, ExecCommand *c, pid_t *_pid) {
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
m->meta.manager->confirm_spawn,
|
m->meta.manager->confirm_spawn,
|
||||||
|
true,
|
||||||
m->meta.cgroup_bondings,
|
m->meta.cgroup_bondings,
|
||||||
&pid)) < 0)
|
&pid)) < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
|
@ -1323,6 +1323,7 @@ static int service_spawn(
|
||||||
bool pass_fds,
|
bool pass_fds,
|
||||||
bool apply_permissions,
|
bool apply_permissions,
|
||||||
bool apply_chroot,
|
bool apply_chroot,
|
||||||
|
bool apply_tty_stdin,
|
||||||
bool set_notify_socket,
|
bool set_notify_socket,
|
||||||
pid_t *_pid) {
|
pid_t *_pid) {
|
||||||
|
|
||||||
|
@ -1395,6 +1396,7 @@ static int service_spawn(
|
||||||
final_env,
|
final_env,
|
||||||
apply_permissions,
|
apply_permissions,
|
||||||
apply_chroot,
|
apply_chroot,
|
||||||
|
apply_tty_stdin,
|
||||||
s->meta.manager->confirm_spawn,
|
s->meta.manager->confirm_spawn,
|
||||||
s->meta.cgroup_bondings,
|
s->meta.cgroup_bondings,
|
||||||
&pid);
|
&pid);
|
||||||
|
@ -1505,6 +1507,7 @@ static void service_enter_stop_post(Service *s, bool success) {
|
||||||
false,
|
false,
|
||||||
!s->permissions_start_only,
|
!s->permissions_start_only,
|
||||||
!s->root_directory_start_only,
|
!s->root_directory_start_only,
|
||||||
|
true,
|
||||||
false,
|
false,
|
||||||
&s->control_pid)) < 0)
|
&s->control_pid)) < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
@ -1605,6 +1608,7 @@ static void service_enter_stop(Service *s, bool success) {
|
||||||
!s->permissions_start_only,
|
!s->permissions_start_only,
|
||||||
!s->root_directory_start_only,
|
!s->root_directory_start_only,
|
||||||
false,
|
false,
|
||||||
|
false,
|
||||||
&s->control_pid)) < 0)
|
&s->control_pid)) < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
|
@ -1653,6 +1657,7 @@ static void service_enter_start_post(Service *s) {
|
||||||
!s->permissions_start_only,
|
!s->permissions_start_only,
|
||||||
!s->root_directory_start_only,
|
!s->root_directory_start_only,
|
||||||
false,
|
false,
|
||||||
|
false,
|
||||||
&s->control_pid)) < 0)
|
&s->control_pid)) < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
|
@ -1687,6 +1692,7 @@ static void service_enter_start(Service *s) {
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
|
true,
|
||||||
s->notify_access != NOTIFY_NONE,
|
s->notify_access != NOTIFY_NONE,
|
||||||
&pid)) < 0)
|
&pid)) < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
@ -1747,6 +1753,7 @@ static void service_enter_start_pre(Service *s) {
|
||||||
false,
|
false,
|
||||||
!s->permissions_start_only,
|
!s->permissions_start_only,
|
||||||
!s->root_directory_start_only,
|
!s->root_directory_start_only,
|
||||||
|
true,
|
||||||
false,
|
false,
|
||||||
&s->control_pid)) < 0)
|
&s->control_pid)) < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
@ -1800,6 +1807,7 @@ static void service_enter_reload(Service *s) {
|
||||||
!s->permissions_start_only,
|
!s->permissions_start_only,
|
||||||
!s->root_directory_start_only,
|
!s->root_directory_start_only,
|
||||||
false,
|
false,
|
||||||
|
false,
|
||||||
&s->control_pid)) < 0)
|
&s->control_pid)) < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
|
@ -1835,6 +1843,7 @@ static void service_run_next(Service *s, bool success) {
|
||||||
!s->permissions_start_only,
|
!s->permissions_start_only,
|
||||||
!s->root_directory_start_only,
|
!s->root_directory_start_only,
|
||||||
false,
|
false,
|
||||||
|
false,
|
||||||
&s->control_pid)) < 0)
|
&s->control_pid)) < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
|
|
|
@ -822,6 +822,7 @@ static int socket_spawn(Socket *s, ExecCommand *c, pid_t *_pid) {
|
||||||
s->meta.manager->environment,
|
s->meta.manager->environment,
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
|
true,
|
||||||
s->meta.manager->confirm_spawn,
|
s->meta.manager->confirm_spawn,
|
||||||
s->meta.cgroup_bondings,
|
s->meta.cgroup_bondings,
|
||||||
&pid);
|
&pid);
|
||||||
|
|
Loading…
Reference in a new issue