chiark / gitweb /
execute: if the main process of a service already owns the TTY, don't wait for acquir...
authorLennart Poettering <lennart@poettering.net>
Thu, 8 Jul 2010 02:09:17 +0000 (04:09 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 8 Jul 2010 02:09:17 +0000 (04:09 +0200)
src/execute.c
src/execute.h
src/kmod-setup.c
src/manager.c
src/mount.c
src/service.c
src/socket.c

index d7239d544000f40f8073d3c9c25e3263d26c0a8e..138d38817fef92945040b64ad66217344c8dd463 100644 (file)
@@ -232,7 +232,10 @@ static bool is_terminal_input(ExecInput i) {
                 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)
                 return EXEC_INPUT_NULL;
@@ -248,12 +251,12 @@ static int fixup_output(ExecOutput std_output, int socket_fd) {
         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;
 
         assert(context);
 
-        i = fixup_input(context->std_input, socket_fd);
+        i = fixup_input(context->std_input, socket_fd, apply_tty_stdin);
 
         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;
         ExecInput i;
 
         assert(context);
         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);
 
         /* 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;
         ExecInput i;
 
         assert(context);
         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);
         e = fixup_output(context->std_error, socket_fd);
 
@@ -889,6 +892,7 @@ int exec_spawn(ExecCommand *command,
                char **environment,
                bool apply_permissions,
                bool apply_chroot,
+               bool apply_tty_stdin,
                bool confirm_spawn,
                CGroupBonding *cgroup_bondings,
                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;
 
                         /* Set up terminal for the question */
@@ -1018,18 +1024,18 @@ int exec_spawn(ExecCommand *command,
                 }
 
                 if (!keep_stdin)
-                        if (setup_input(context, socket_fd) < 0) {
+                        if (setup_input(context, socket_fd, apply_tty_stdin) < 0) {
                                 r = EXIT_STDIN;
                                 goto fail;
                         }
 
                 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;
                                 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;
                         goto fail;
                 }
index 2e0e6cca3c7bc7f983f5d59cc8e83ea2b05bb1fc..a9075fe0eb6d7541bbd2a592f8697492dc765833 100644 (file)
@@ -196,6 +196,7 @@ int exec_spawn(ExecCommand *command,
                char **environment,
                bool apply_permissions,
                bool apply_chroot,
+               bool apply_tty_stdin,
                bool confirm_spawn,
                struct CGroupBonding *cgroup_bondings,
                pid_t *ret);
index e3925c5ac92bf0dc450a5d60032cd34a4353157c..3ce6fcc77b4734b6b4b9a23fb7b68aad6a8af6bc 100644 (file)
@@ -70,7 +70,7 @@ int kmod_setup(void) {
         command.argv = (char**) cmdline;
 
         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);
 
         if (r < 0)
index 9cbf9c87484783ba87eb92e2cff4d0d9c42c8282..adff54639731d2e3fd7fb0850a1e8324450c47e9 100644 (file)
@@ -1273,7 +1273,7 @@ static int transaction_add_job_and_dependencies(
         assert(unit);
 
         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;
         }
 
index 50fe85cb7c309c69a1346645175bd194fc0f92a3..e7fdcc84f358993a8cc0aa154bd9102d9c82ef92 100644 (file)
@@ -535,6 +535,7 @@ static int mount_spawn(Mount *m, ExecCommand *c, pid_t *_pid) {
                             true,
                             true,
                             m->meta.manager->confirm_spawn,
+                            true,
                             m->meta.cgroup_bondings,
                             &pid)) < 0)
                 goto fail;
index 75439be376a5bcaf461f70eb853014ef6bd4afee..2ca0c17ec221d096f4b1a618707901f6e4669396 100644 (file)
@@ -1323,6 +1323,7 @@ static int service_spawn(
                 bool pass_fds,
                 bool apply_permissions,
                 bool apply_chroot,
+                bool apply_tty_stdin,
                 bool set_notify_socket,
                 pid_t *_pid) {
 
@@ -1395,6 +1396,7 @@ static int service_spawn(
                        final_env,
                        apply_permissions,
                        apply_chroot,
+                       apply_tty_stdin,
                        s->meta.manager->confirm_spawn,
                        s->meta.cgroup_bondings,
                        &pid);
@@ -1505,6 +1507,7 @@ static void service_enter_stop_post(Service *s, bool success) {
                                        false,
                                        !s->permissions_start_only,
                                        !s->root_directory_start_only,
+                                       true,
                                        false,
                                        &s->control_pid)) < 0)
                         goto fail;
@@ -1605,6 +1608,7 @@ static void service_enter_stop(Service *s, bool success) {
                                        !s->permissions_start_only,
                                        !s->root_directory_start_only,
                                        false,
+                                       false,
                                        &s->control_pid)) < 0)
                         goto fail;
 
@@ -1653,6 +1657,7 @@ static void service_enter_start_post(Service *s) {
                                        !s->permissions_start_only,
                                        !s->root_directory_start_only,
                                        false,
+                                       false,
                                        &s->control_pid)) < 0)
                         goto fail;
 
@@ -1687,6 +1692,7 @@ static void service_enter_start(Service *s) {
                                true,
                                true,
                                true,
+                               true,
                                s->notify_access != NOTIFY_NONE,
                                &pid)) < 0)
                 goto fail;
@@ -1747,6 +1753,7 @@ static void service_enter_start_pre(Service *s) {
                                        false,
                                        !s->permissions_start_only,
                                        !s->root_directory_start_only,
+                                       true,
                                        false,
                                        &s->control_pid)) < 0)
                         goto fail;
@@ -1800,6 +1807,7 @@ static void service_enter_reload(Service *s) {
                                        !s->permissions_start_only,
                                        !s->root_directory_start_only,
                                        false,
+                                       false,
                                        &s->control_pid)) < 0)
                         goto fail;
 
@@ -1835,6 +1843,7 @@ static void service_run_next(Service *s, bool success) {
                                !s->permissions_start_only,
                                !s->root_directory_start_only,
                                false,
+                               false,
                                &s->control_pid)) < 0)
                 goto fail;
 
index b8643d9f437fcfb71a299054472ccc8344c6ce1f..ee75de04d647b09210e50f71cc6f86d2a57d5caf 100644 (file)
@@ -822,6 +822,7 @@ static int socket_spawn(Socket *s, ExecCommand *c, pid_t *_pid) {
                        s->meta.manager->environment,
                        true,
                        true,
+                       true,
                        s->meta.manager->confirm_spawn,
                        s->meta.cgroup_bondings,
                        &pid);