]> err.no Git - systemd/commitdiff
dbus: complete exec status coverage
authorLennart Poettering <lennart@poettering.net>
Sun, 4 Jul 2010 16:49:58 +0000 (18:49 +0200)
committerLennart Poettering <lennart@poettering.net>
Sun, 4 Jul 2010 16:49:58 +0000 (18:49 +0200)
src/dbus-execute.h
src/dbus-service.c
src/execute.c
src/execute.h
src/mount.c
src/service.c
src/socket.c

index f6cca9c49395ceeaba3562ba3e8f616adeab956d..1ab196ff2185d0e17d0efb6586c4afb710017394 100644 (file)
 
 #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"     \
         { 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);
index 84c4730ce542b49f287e5f580e391ee38da7838c..26524f402c62b473b7a2a977134d9d48223eec40 100644 (file)
@@ -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                  },
index 0bdd60000bba15f60b6fbd3555d9041fc540ef03..f3f95ff754e5d15b76d3d42642288bd7e2f56cf1 100644 (file)
@@ -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);
 
index 9fb48e6446b761460511ddf6802c41384cd55f1b..aa5f56667759ecd521d6244c28b57be669a75293 100644 (file)
@@ -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);
index 6b38741c35407a51dc0a1d8dd69f7d486b7d66c3..b99e5ffe8b9f9e28b0955dde12133db87bb72acd 100644 (file)
@@ -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;
         }
index 04ed6843935e6b719cc74c06b49463646574435a..ae8a763e7c1647c495e9d2dcd8202949b75ed41f 100644 (file)
@@ -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;
 
index 03e556c30e18012cb53cb15a8cdf1e5df7b2b78c..00e0685aadec8476dc7b33aeb17b0d27a41afd55 100644 (file)
@@ -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);