#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);
" <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" \
{ "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 },
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;
}
}
-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);
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);
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;
}
s->main_pid = pid;
s->main_pid_known = true;
+ exec_status_start(&s->main_exec_status, pid);
+
return 0;
}
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) {
} 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;
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);