X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fsystemctl.c;h=23e659756f8e84fd75236d83295c7a2365749eec;hb=267632f0ab26bbcec6bc93682cf43d0f983c41d8;hp=b33a89f63d76d9bd3ae05d28db2f5b35a75aca4d;hpb=8e20e31a65ec9e637abf3821087946e9160001ac;p=elogind.git diff --git a/src/systemctl.c b/src/systemctl.c index b33a89f63..23e659756 100644 --- a/src/systemctl.c +++ b/src/systemctl.c @@ -112,6 +112,7 @@ static enum dot { static bool private_bus = false; static pid_t pager_pid = 0; +static pid_t agent_pid = 0; static int daemon_reload(DBusConnection *bus, char **args, unsigned n); static void pager_open(void); @@ -132,7 +133,10 @@ static bool on_tty(void) { } static void spawn_ask_password_agent(void) { - pid_t parent, child; + pid_t parent; + + if (agent_pid > 0) + return; /* We check STDIN here, not STDOUT, since this is about input, * not output */ @@ -150,16 +154,11 @@ static void spawn_ask_password_agent(void) { /* Spawns a temporary TTY agent, making sure it goes away when * we go away */ - if ((child = fork()) < 0) + if ((agent_pid = fork()) < 0) return; - if (child == 0) { + if (agent_pid == 0) { /* In the child */ - const char * const args[] = { - SYSTEMD_TTY_ASK_PASSWORD_AGENT_BINARY_PATH, - "--watch", - NULL - }; int fd; bool stdout_is_tty, stderr_is_tty; @@ -202,7 +201,9 @@ static void spawn_ask_password_agent(void) { close(fd); } - execv(args[0], (char **) args); + execl(SYSTEMD_TTY_ASK_PASSWORD_AGENT_BINARY_PATH, SYSTEMD_TTY_ASK_PASSWORD_AGENT_BINARY_PATH, "--watch", NULL); + + log_error("Unable to execute agent: %m"); _exit(EXIT_FAILURE); } } @@ -1248,7 +1249,7 @@ static int wait_for_jobs(DBusConnection *bus, Set *s) { log_error("Job canceled."); else if (streq(d.result, "dependency")) log_error("A dependency job failed. See system logs for details."); - else if (!streq(d.result, "done")) + else if (!streq(d.result, "done") && !streq(d.result, "skipped")) log_error("Job failed. See system logs and 'systemctl status' for details."); } @@ -1256,7 +1257,7 @@ static int wait_for_jobs(DBusConnection *bus, Set *s) { r = -ETIME; else if (streq_ptr(d.result, "canceled")) r = -ECANCELED; - else if (!streq_ptr(d.result, "done")) + else if (!streq_ptr(d.result, "done") && !streq_ptr(d.result, "skipped")) r = -EIO; else r = 0; @@ -1416,10 +1417,15 @@ static int start_unit(DBusConnection *bus, char **args, unsigned n) { streq(args[0], "stop") ? "StopUnit" : streq(args[0], "reload") ? "ReloadUnit" : streq(args[0], "restart") ? "RestartUnit" : + streq(args[0], "try-restart") || streq(args[0], "condrestart") ? "TryRestartUnit" : + streq(args[0], "reload-or-restart") ? "ReloadOrRestartUnit" : + streq(args[0], "reload-or-try-restart") || + streq(args[0], "condreload") || + streq(args[0], "force-reload") ? "ReloadOrTryRestartUnit" : "StartUnit"; @@ -2368,6 +2374,25 @@ static int print_property(const char *name, DBusMessageIter *iter) { return 0; + } else if (dbus_message_iter_get_element_type(iter) == DBUS_TYPE_STRUCT && streq(name, "EnvironmentFiles")) { + DBusMessageIter sub, sub2; + + dbus_message_iter_recurse(iter, &sub); + while (dbus_message_iter_get_arg_type(&sub) == DBUS_TYPE_STRUCT) { + const char *path; + dbus_bool_t ignore; + + dbus_message_iter_recurse(&sub, &sub2); + + if (bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_STRING, &path, true) >= 0 && + bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_BOOLEAN, &ignore, false) >= 0) + printf("EnvironmentFile=%s (ignore=%s)\n", path, yes_no(ignore)); + + dbus_message_iter_next(&sub); + } + + return 0; + } else if (dbus_message_iter_get_element_type(iter) == DBUS_TYPE_STRUCT && streq(name, "Paths")) { DBusMessageIter sub, sub2; @@ -4047,7 +4072,7 @@ static int install_info_apply(const char *verb, LookupPaths *paths, InstallInfo argv[1] = file_name_from_path(sysv); argv[2] = streq(verb, "enable") ? "on" : - streq(verb, "disable") ? "off" : NULL; + streq(verb, "disable") ? "off" : "--level=3"; log_info("Executing %s %s %s", argv[0], argv[1], strempty(argv[2])); @@ -4066,10 +4091,15 @@ static int install_info_apply(const char *verb, LookupPaths *paths, InstallInfo return r; if (status.si_code == CLD_EXITED) { - if (status.si_status == 0 && (streq(verb, "enable") || streq(verb, "disable"))) + + if (streq(verb, "is-enabled")) + return status.si_status == 0 ? 1 : 0; + + if (status.si_status == 0) n_symlinks ++; return status.si_status == 0 ? 0 : -EINVAL; + } else return -EPROTO; } @@ -4172,6 +4202,8 @@ static int enable_unit(DBusConnection *bus, char **args, unsigned n) { goto finish; } + r = 0; + while ((i = hashmap_first(will_install))) { int q; @@ -5165,6 +5197,7 @@ static int systemctl_main(DBusConnection *bus, int argc, char *argv[], DBusError { "reload-or-restart", MORE, 2, start_unit }, { "reload-or-try-restart", MORE, 2, start_unit }, { "force-reload", MORE, 2, start_unit }, /* For compatibility with SysV */ + { "condreload", MORE, 2, start_unit }, /* For compatibility with ALTLinux */ { "condrestart", MORE, 2, start_unit }, /* For compatibility with RH */ { "isolate", EQUAL, 2, start_unit }, { "kill", MORE, 2, kill_unit }, @@ -5447,6 +5480,7 @@ static int runlevel_main(void) { static void pager_open(void) { int fd[2]; const char *pager; + pid_t parent_pid; if (pager_pid > 0) return; @@ -5467,6 +5501,8 @@ static void pager_open(void) { return; } + parent_pid = getpid(); + pager_pid = fork(); if (pager_pid < 0) { log_error("Failed to fork pager: %m"); @@ -5482,7 +5518,14 @@ static void pager_open(void) { setenv("LESS", "FRSX", 0); - prctl(PR_SET_PDEATHSIG, SIGTERM); + /* Make sure the pager goes away when the parent dies */ + if (prctl(PR_SET_PDEATHSIG, SIGTERM) < 0) + _exit(EXIT_FAILURE); + + /* Check whether our parent died before we were able + * to set the death signal */ + if (getppid() != parent_pid) + _exit(EXIT_SUCCESS); if (pager) { execlp(pager, pager, NULL); @@ -5519,10 +5562,24 @@ static void pager_close(void) { /* Inform pager that we are done */ fclose(stdout); + kill(pager_pid, SIGCONT); wait_for_terminate(pager_pid, &dummy); pager_pid = 0; } +static void agent_close(void) { + siginfo_t dummy; + + if (agent_pid <= 0) + return; + + /* Inform agent that we are done */ + kill(agent_pid, SIGTERM); + kill(agent_pid, SIGCONT); + wait_for_terminate(agent_pid, &dummy); + agent_pid = 0; +} + int main(int argc, char*argv[]) { int r, retval = EXIT_FAILURE; DBusConnection *bus = NULL; @@ -5605,6 +5662,7 @@ finish: strv_free(arg_property); pager_close(); + agent_close(); return retval; }