From b58b41160fde88a82cba1ddec4be7dfb08825e35 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sun, 4 Jul 2010 18:49:58 +0200 Subject: [PATCH] dbus: complete exec status coverage --- src/dbus-execute.h | 14 ++++++++++++++ src/dbus-service.c | 3 ++- src/execute.c | 17 ++++++++++++++--- src/execute.h | 3 ++- src/mount.c | 2 +- src/service.c | 6 ++++-- src/socket.c | 2 +- 7 files changed, 38 insertions(+), 9 deletions(-) diff --git a/src/dbus-execute.h b/src/dbus-execute.h index f6cca9c4..1ab196ff 100644 --- a/src/dbus-execute.h +++ b/src/dbus-execute.h @@ -26,6 +26,13 @@ #include "manager.h" +#define BUS_EXEC_STATUS_INTERFACE(prefix) \ + " \n" \ + " \n" \ + " \n" \ + " \n" \ + " \n" + #define BUS_EXEC_CONTEXT_INTERFACE \ " \n" \ " \n" \ @@ -130,6 +137,13 @@ { interface, "PrivateTmp", bus_property_append_bool, "b", &(context).private_tmp }, \ { interface, "NoSetSID", bus_property_append_bool, "b", &(context).no_setsid } +#define BUS_EXEC_STATUS_PROPERTIES(interface, estatus, prefix) \ + { interface, prefix "StartTimestamp", bus_property_append_usec, "t", &(estatus).start_timestamp.realtime }, \ + { interface, prefix "ExitTimestamp", bus_property_append_usec, "t", &(estatus).start_timestamp.realtime }, \ + { interface, prefix "PID", bus_property_append_pid, "u", &(estatus).pid }, \ + { interface, prefix "Code", bus_property_append_int, "i", &(estatus).code }, \ + { interface, prefix "Status", bus_property_append_int, "i", &(estatus).status } + int bus_execute_append_output(Manager *m, DBusMessageIter *i, const char *property, void *data); int bus_execute_append_input(Manager *m, DBusMessageIter *i, const char *property, void *data); int bus_execute_append_oom_adjust(Manager *m, DBusMessageIter *i, const char *property, void *data); diff --git a/src/dbus-service.c b/src/dbus-service.c index 84c4730c..26524f40 100644 --- a/src/dbus-service.c +++ b/src/dbus-service.c @@ -38,6 +38,7 @@ " \n" \ " \n" \ " \n" \ + BUS_EXEC_STATUS_INTERFACE("ExecMain") \ " \n" \ " \n" \ " \n" \ @@ -77,7 +78,7 @@ DBusHandlerResult bus_service_message_handler(Unit *u, DBusConnection *connectio { "org.freedesktop.systemd1.Service", "RootDirectoryStartOnly", bus_property_append_bool, "b", &u->service.root_directory_start_only }, { "org.freedesktop.systemd1.Service", "ValidNoProcess", bus_property_append_bool, "b", &u->service.valid_no_process }, { "org.freedesktop.systemd1.Service", "KillMode", bus_unit_append_kill_mode, "s", &u->service.kill_mode }, - /* MainExecStatus */ + BUS_EXEC_STATUS_PROPERTIES("org.freedesktop.systemd1.Service", u->service.main_exec_status, "ExecMain"), { "org.freedesktop.systemd1.Service", "MainPID", bus_property_append_pid, "u", &u->service.main_pid }, { "org.freedesktop.systemd1.Service", "ControlPID", bus_property_append_pid, "u", &u->service.control_pid }, { "org.freedesktop.systemd1.Service", "SysVPath", bus_property_append_string, "s", u->service.sysv_path }, diff --git a/src/execute.c b/src/execute.c index 0bdd6000..f3f95ff7 100644 --- a/src/execute.c +++ b/src/execute.c @@ -1281,8 +1281,7 @@ int exec_spawn(ExecCommand *command, log_debug("Forked %s as %lu", command->path, (unsigned long) pid); - command->exec_status.pid = pid; - dual_timestamp_get(&command->exec_status.start_timestamp); + exec_status_start(&command->exec_status, pid); *ret = pid; return 0; @@ -1561,9 +1560,21 @@ void exec_context_dump(ExecContext *c, FILE* f, const char *prefix) { } } -void exec_status_fill(ExecStatus *s, pid_t pid, int code, int status) { +void exec_status_start(ExecStatus *s, pid_t pid) { assert(s); + zero(*s); + s->pid = pid; + dual_timestamp_get(&s->start_timestamp); +} + +void exec_status_exit(ExecStatus *s, pid_t pid, int code, int status) { + assert(s); + + if ((s->pid && s->pid != pid) || + !s->start_timestamp.realtime <= 0) + zero(*s); + s->pid = pid; dual_timestamp_get(&s->exit_timestamp); diff --git a/src/execute.h b/src/execute.h index 9fb48e64..aa5f5666 100644 --- a/src/execute.h +++ b/src/execute.h @@ -217,7 +217,8 @@ void exec_context_init(ExecContext *c); void exec_context_done(ExecContext *c); void exec_context_dump(ExecContext *c, FILE* f, const char *prefix); -void exec_status_fill(ExecStatus *s, pid_t pid, int code, int status); +void exec_status_start(ExecStatus *s, pid_t pid); +void exec_status_exit(ExecStatus *s, pid_t pid, int code, int status); void exec_status_dump(ExecStatus *s, FILE *f, const char *prefix); const char* exec_output_to_string(ExecOutput i); diff --git a/src/mount.c b/src/mount.c index 6b38741c..b99e5ffe 100644 --- a/src/mount.c +++ b/src/mount.c @@ -936,7 +936,7 @@ static void mount_sigchld_event(Unit *u, pid_t pid, int code, int status) { m->failure = m->failure || !success; if (m->control_command) { - exec_status_fill(&m->control_command->exec_status, pid, code, status); + exec_status_exit(&m->control_command->exec_status, pid, code, status); m->control_command = NULL; m->control_command_id = _MOUNT_EXEC_COMMAND_INVALID; } diff --git a/src/service.c b/src/service.c index 04ed6843..ae8a763e 100644 --- a/src/service.c +++ b/src/service.c @@ -144,6 +144,8 @@ static int service_set_main_pid(Service *s, pid_t pid) { s->main_pid = pid; s->main_pid_known = true; + exec_status_start(&s->main_exec_status, pid); + return 0; } @@ -2082,7 +2084,7 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) { if (s->main_pid == pid) { - exec_status_fill(&s->main_exec_status, pid, code, status); + exec_status_exit(&s->main_exec_status, pid, code, status); s->main_pid = 0; if (s->type != SERVICE_FORKING) { @@ -2138,7 +2140,7 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) { } else if (s->control_pid == pid) { if (s->control_command) - exec_status_fill(&s->control_command->exec_status, pid, code, status); + exec_status_exit(&s->control_command->exec_status, pid, code, status); s->control_pid = 0; diff --git a/src/socket.c b/src/socket.c index 03e556c3..00e0685a 100644 --- a/src/socket.c +++ b/src/socket.c @@ -1397,7 +1397,7 @@ static void socket_sigchld_event(Unit *u, pid_t pid, int code, int status) { s->failure = s->failure || !success; if (s->control_command) - exec_status_fill(&s->control_command->exec_status, pid, code, status); + exec_status_exit(&s->control_command->exec_status, pid, code, status); log_debug("%s control process exited, code=%s status=%i", u->meta.id, sigchld_code_to_string(code), status); -- 2.39.5