]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core/service: try to query for new main process's starttime 32961/head
authorMike Yuan <me@yhndnzj.com>
Tue, 21 May 2024 15:43:06 +0000 (23:43 +0800)
committerMike Yuan <me@yhndnzj.com>
Wed, 22 May 2024 11:03:13 +0000 (19:03 +0800)
Currently, when service_set_main_pidref() is called
without specifying start_timestamp, exec_status_start()
always uses dual_timestamp_now(). This is not ideal,
though, as when the main pid changes halfway due to
e.g. sd_notify + MAINPID=, it's definitely spurious.

src/core/service.c

index 8ec27c463a4d8ee0f076223bb80e42d5b98ed0af..3ccb05bff4690ab6cd294361195b0760328ac2d8 100644 (file)
@@ -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);
         }