mirror of
https://github.com/systemd/systemd.git
synced 2024-10-27 10:25:37 +03:00
Merge pull request #32961 from YHNdnzj/starttime-main
core/service: try to query for new main process's starttime
This commit is contained in:
commit
21f51d877f
@ -56,6 +56,7 @@
|
||||
#include "string-table.h"
|
||||
#include "string-util.h"
|
||||
#include "terminal-util.h"
|
||||
#include "time-util.h"
|
||||
#include "user-util.h"
|
||||
#include "utf8.h"
|
||||
|
||||
@ -731,7 +732,7 @@ int get_process_ppid(pid_t pid, pid_t *ret) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pid_get_start_time(pid_t pid, uint64_t *ret) {
|
||||
int pid_get_start_time(pid_t pid, usec_t *ret) {
|
||||
_cleanup_free_ char *line = NULL;
|
||||
const char *p;
|
||||
int r;
|
||||
@ -751,13 +752,12 @@ int pid_get_start_time(pid_t pid, uint64_t *ret) {
|
||||
p = strrchr(line, ')');
|
||||
if (!p)
|
||||
return -EIO;
|
||||
|
||||
p++;
|
||||
|
||||
unsigned long llu;
|
||||
|
||||
if (sscanf(p, " "
|
||||
"%*c " /* state */
|
||||
"%*c " /* state */
|
||||
"%*u " /* ppid */
|
||||
"%*u " /* pgrp */
|
||||
"%*u " /* session */
|
||||
@ -781,13 +781,13 @@ int pid_get_start_time(pid_t pid, uint64_t *ret) {
|
||||
return -EIO;
|
||||
|
||||
if (ret)
|
||||
*ret = llu;
|
||||
*ret = jiffies_to_usec(llu); /* CLOCK_BOOTTIME */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pidref_get_start_time(const PidRef *pid, uint64_t *ret) {
|
||||
uint64_t t;
|
||||
int pidref_get_start_time(const PidRef *pid, usec_t *ret) {
|
||||
usec_t t;
|
||||
int r;
|
||||
|
||||
if (!pidref_is_set(pid))
|
||||
|
@ -54,8 +54,8 @@ int get_process_cwd(pid_t pid, char **ret);
|
||||
int get_process_root(pid_t pid, char **ret);
|
||||
int get_process_environ(pid_t pid, char **ret);
|
||||
int get_process_ppid(pid_t pid, pid_t *ret);
|
||||
int pid_get_start_time(pid_t pid, uint64_t *ret);
|
||||
int pidref_get_start_time(const PidRef* pid, uint64_t *ret);
|
||||
int pid_get_start_time(pid_t pid, usec_t *ret);
|
||||
int pidref_get_start_time(const PidRef* pid, usec_t *ret);
|
||||
int get_process_umask(pid_t pid, mode_t *ret);
|
||||
|
||||
int container_get_leader(const char *machine, pid_t *pid);
|
||||
|
@ -214,6 +214,16 @@ static int service_set_main_pidref(Service *s, PidRef pidref_consume, const dual
|
||||
|
||||
if (!pidref_equal(&s->main_pid, &pidref)) {
|
||||
service_unwatch_main_pid(s);
|
||||
|
||||
dual_timestamp pid_start_time;
|
||||
|
||||
if (!start_timestamp) {
|
||||
usec_t t;
|
||||
|
||||
if (pidref_get_start_time(&pidref, &t) >= 0)
|
||||
start_timestamp = dual_timestamp_from_boottime(&pid_start_time, t);
|
||||
}
|
||||
|
||||
exec_status_start(&s->main_exec_status, pidref.pid, start_timestamp);
|
||||
}
|
||||
|
||||
|
@ -951,18 +951,18 @@ TEST(pid_get_start_time) {
|
||||
|
||||
assert_se(pidref_set_self(&pidref) >= 0);
|
||||
|
||||
uint64_t start_time;
|
||||
usec_t start_time;
|
||||
assert_se(pidref_get_start_time(&pidref, &start_time) >= 0);
|
||||
log_info("our starttime: %" PRIu64, start_time);
|
||||
log_info("our starttime: " USEC_FMT, start_time);
|
||||
|
||||
_cleanup_(pidref_done_sigkill_wait) PidRef child = PIDREF_NULL;
|
||||
|
||||
assert_se(pidref_safe_fork("(stub)", FORK_RESET_SIGNALS|FORK_CLOSE_ALL_FDS, &child) >= 0);
|
||||
|
||||
uint64_t start_time2;
|
||||
usec_t start_time2;
|
||||
assert_se(pidref_get_start_time(&child, &start_time2) >= 0);
|
||||
|
||||
log_info("child starttime: %" PRIu64, start_time2);
|
||||
log_info("child starttime: " USEC_FMT, start_time2);
|
||||
|
||||
assert_se(start_time2 >= start_time);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user