summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2010-07-04 18:49:58 +0200
committerLennart Poettering <lennart@poettering.net>2010-07-04 18:49:58 +0200
commitb58b41160fde88a82cba1ddec4be7dfb08825e35 (patch)
tree9f5b30cf50bcaf752fc955507c5d065d214e0222
parent14ad1d1437f51b8ebc8dc6e8d3707b41d48d0a3a (diff)
dbus: complete exec status coverage
-rw-r--r--src/dbus-execute.h14
-rw-r--r--src/dbus-service.c3
-rw-r--r--src/execute.c17
-rw-r--r--src/execute.h3
-rw-r--r--src/mount.c2
-rw-r--r--src/service.c6
-rw-r--r--src/socket.c2
7 files changed, 38 insertions, 9 deletions
diff --git a/src/dbus-execute.h b/src/dbus-execute.h
index f6cca9c493..1ab196ff21 100644
--- a/src/dbus-execute.h
+++ b/src/dbus-execute.h
@@ -26,6 +26,13 @@
#include "manager.h"
+#define BUS_EXEC_STATUS_INTERFACE(prefix) \
+ " <property name=\"" prefix "StartTimestamp\" type=\"t\" access=\"read\"/>\n" \
+ " <property name=\"" prefix "ExitTimestamp\" type=\"t\" access=\"read\"/>\n" \
+ " <property name=\"" prefix "PID\" type=\"u\" access=\"read\"/>\n" \
+ " <property name=\"" prefix "Code\" type=\"i\" access=\"read\"/>\n" \
+ " <property name=\"" prefix "Status\" type=\"i\" access=\"read\"/>\n"
+
#define BUS_EXEC_CONTEXT_INTERFACE \
" <property name=\"Environment\" type=\"as\" access=\"read\"/>\n" \
" <property name=\"UMask\" type=\"u\" access=\"read\"/>\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 84c4730ce5..26524f402c 100644
--- a/src/dbus-service.c
+++ b/src/dbus-service.c
@@ -38,6 +38,7 @@
" <property name=\"RootDirectoryStartOnly\" type=\"b\" access=\"read\"/>\n" \
" <property name=\"ValidNoProcess\" type=\"b\" access=\"read\"/>\n" \
" <property name=\"KillMode\" type=\"s\" access=\"read\"/>\n" \
+ BUS_EXEC_STATUS_INTERFACE("ExecMain") \
" <property name=\"MainPID\" type=\"u\" access=\"read\"/>\n" \
" <property name=\"ControlPID\" type=\"u\" access=\"read\"/>\n" \
" <property name=\"SysVStartPriority\" type=\"i\" access=\"read\"/>\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 0bdd60000b..f3f95ff754 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 9fb48e6446..aa5f566677 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 6b38741c35..b99e5ffe8b 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 04ed684393..ae8a763e7c 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 03e556c30e..00e0685aad 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);