manager: switch service unit type over to using new handoff timestamping logic
Also: rename Handover → Handoff. I think it makes it clearer that this is not really about handing over any resources, but that the executor is out off the game from that point on.
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
#define BUS_EXEC_STATUS_VTABLE(prefix, offset, flags) \
|
||||
BUS_PROPERTY_DUAL_TIMESTAMP(prefix "StartTimestamp", (offset) + offsetof(ExecStatus, start_timestamp), flags), \
|
||||
BUS_PROPERTY_DUAL_TIMESTAMP(prefix "ExitTimestamp", (offset) + offsetof(ExecStatus, exit_timestamp), flags), \
|
||||
BUS_PROPERTY_DUAL_TIMESTAMP(prefix "HandoverTimestamp", (offset) + offsetof(ExecStatus, handover_timestamp), flags), \
|
||||
BUS_PROPERTY_DUAL_TIMESTAMP(prefix "HandoffTimestamp", (offset) + offsetof(ExecStatus, handoff_timestamp), flags), \
|
||||
SD_BUS_PROPERTY(prefix "PID", "u", bus_property_get_pid, (offset) + offsetof(ExecStatus, pid), flags), \
|
||||
SD_BUS_PROPERTY(prefix "Code", "i", bus_property_get_int, (offset) + offsetof(ExecStatus, code), flags), \
|
||||
SD_BUS_PROPERTY(prefix "Status", "i", bus_property_get_int, (offset) + offsetof(ExecStatus, status), flags)
|
||||
|
||||
+16
-3
@@ -1842,6 +1842,19 @@ void exec_status_exit(ExecStatus *s, const ExecContext *context, pid_t pid, int
|
||||
(void) utmp_put_dead_process(context->utmp_id, pid, code, status);
|
||||
}
|
||||
|
||||
void exec_status_handoff(ExecStatus *s, const struct ucred *ucred, const dual_timestamp *ts) {
|
||||
assert(s);
|
||||
assert(ucred);
|
||||
assert(ts);
|
||||
|
||||
if (ucred->pid != s->pid)
|
||||
*s = (ExecStatus) {
|
||||
.pid = ucred->pid,
|
||||
};
|
||||
|
||||
s->handoff_timestamp = *ts;
|
||||
}
|
||||
|
||||
void exec_status_reset(ExecStatus *s) {
|
||||
assert(s);
|
||||
|
||||
@@ -1866,10 +1879,10 @@ void exec_status_dump(const ExecStatus *s, FILE *f, const char *prefix) {
|
||||
"%sStart Timestamp: %s\n",
|
||||
prefix, FORMAT_TIMESTAMP(s->start_timestamp.realtime));
|
||||
|
||||
if (dual_timestamp_is_set(&s->handover_timestamp))
|
||||
if (dual_timestamp_is_set(&s->handoff_timestamp))
|
||||
fprintf(f,
|
||||
"%sHandover Timestamp: %s\n",
|
||||
prefix, FORMAT_TIMESTAMP(s->handover_timestamp.realtime));
|
||||
"%sHandoff Timestamp: %s\n",
|
||||
prefix, FORMAT_TIMESTAMP(s->handoff_timestamp.realtime));
|
||||
|
||||
if (dual_timestamp_is_set(&s->exit_timestamp))
|
||||
fprintf(f,
|
||||
|
||||
+3
-4
@@ -91,7 +91,7 @@ typedef enum ExecKeyringMode {
|
||||
struct ExecStatus {
|
||||
dual_timestamp start_timestamp;
|
||||
dual_timestamp exit_timestamp;
|
||||
dual_timestamp handover_timestamp;
|
||||
dual_timestamp handoff_timestamp;
|
||||
pid_t pid;
|
||||
int code; /* as in siginfo_t::si_code */
|
||||
int status; /* as in siginfo_t::si_status */
|
||||
@@ -444,9 +444,7 @@ struct ExecParameters {
|
||||
int stdout_fd;
|
||||
int stderr_fd;
|
||||
|
||||
/* An fd that is closed by the execve(), and thus will result in EOF when the execve() is done. It
|
||||
* will also be used to send a timestamp taken as the very last operation before execve, for
|
||||
* tracking purposes. */
|
||||
/* An fd that is closed by the execve(), and thus will result in EOF when the execve() is done. */
|
||||
int exec_fd;
|
||||
|
||||
char *notify_socket;
|
||||
@@ -547,6 +545,7 @@ char** exec_context_get_restrict_filesystems(const ExecContext *c);
|
||||
|
||||
void exec_status_start(ExecStatus *s, pid_t pid);
|
||||
void exec_status_exit(ExecStatus *s, const ExecContext *context, pid_t pid, int code, int status);
|
||||
void exec_status_handoff(ExecStatus *s, const struct ucred *ucred, const dual_timestamp *ts);
|
||||
void exec_status_dump(const ExecStatus *s, FILE *f, const char *prefix);
|
||||
void exec_status_reset(ExecStatus *s);
|
||||
|
||||
|
||||
+27
-3
@@ -3009,7 +3009,7 @@ static int service_serialize(Unit *u, FILE *f, FDSet *fds) {
|
||||
(void) serialize_item_format(f, "main-exec-status-pid", PID_FMT, s->main_exec_status.pid);
|
||||
(void) serialize_dual_timestamp(f, "main-exec-status-start", &s->main_exec_status.start_timestamp);
|
||||
(void) serialize_dual_timestamp(f, "main-exec-status-exit", &s->main_exec_status.exit_timestamp);
|
||||
(void) serialize_dual_timestamp(f, "main-exec-status-handover", &s->main_exec_status.handover_timestamp);
|
||||
(void) serialize_dual_timestamp(f, "main-exec-status-handoff", &s->main_exec_status.handoff_timestamp);
|
||||
|
||||
if (dual_timestamp_is_set(&s->main_exec_status.exit_timestamp)) {
|
||||
(void) serialize_item_format(f, "main-exec-status-code", "%i", s->main_exec_status.code);
|
||||
@@ -3294,8 +3294,8 @@ static int service_deserialize_item(Unit *u, const char *key, const char *value,
|
||||
deserialize_dual_timestamp(value, &s->main_exec_status.start_timestamp);
|
||||
else if (streq(key, "main-exec-status-exit"))
|
||||
deserialize_dual_timestamp(value, &s->main_exec_status.exit_timestamp);
|
||||
else if (streq(key, "main-exec-status-handover"))
|
||||
deserialize_dual_timestamp(value, &s->main_exec_status.handover_timestamp);
|
||||
else if (streq(key, "main-exec-status-handoff"))
|
||||
deserialize_dual_timestamp(value, &s->main_exec_status.handoff_timestamp);
|
||||
else if (streq(key, "notify-access-override")) {
|
||||
NotifyAccess notify_access;
|
||||
|
||||
@@ -4578,6 +4578,29 @@ static void service_notify_message(
|
||||
unit_add_to_dbus_queue(u);
|
||||
}
|
||||
|
||||
static void service_handoff_timestamp(
|
||||
Unit *u,
|
||||
const struct ucred *ucred,
|
||||
const dual_timestamp *ts) {
|
||||
|
||||
Service *s = ASSERT_PTR(SERVICE(u));
|
||||
|
||||
assert(ucred);
|
||||
assert(ts);
|
||||
|
||||
if (s->main_pid.pid == ucred->pid) {
|
||||
if (s->main_command)
|
||||
exec_status_handoff(&s->main_command->exec_status, ucred, ts);
|
||||
|
||||
exec_status_handoff(&s->main_exec_status, ucred, ts);
|
||||
} else if (s->control_pid.pid == ucred->pid && s->control_command)
|
||||
exec_status_handoff(&s->control_command->exec_status, ucred, ts);
|
||||
else
|
||||
return;
|
||||
|
||||
unit_add_to_dbus_queue(u);
|
||||
}
|
||||
|
||||
static int service_get_timeout(Unit *u, usec_t *timeout) {
|
||||
Service *s = ASSERT_PTR(SERVICE(u));
|
||||
uint64_t t;
|
||||
@@ -5163,6 +5186,7 @@ const UnitVTable service_vtable = {
|
||||
.notify_cgroup_empty = service_notify_cgroup_empty_event,
|
||||
.notify_cgroup_oom = service_notify_cgroup_oom_event,
|
||||
.notify_message = service_notify_message,
|
||||
.notify_handoff_timestamp = service_handoff_timestamp,
|
||||
|
||||
.main_pid = service_main_pid,
|
||||
.control_pid = service_control_pid,
|
||||
|
||||
Reference in New Issue
Block a user