diff options
| author | Paul Eggert | 2025-06-17 12:23:41 -0700 |
|---|---|---|
| committer | Paul Eggert | 2025-06-17 12:25:16 -0700 |
| commit | 73cebbb87b72effb948f0d73e756a0dc0c55b71c (patch) | |
| tree | 46db9263bdc7d5a732d3c0f7c3ea60d2234b6918 /src | |
| parent | 3f720049614d825bd83d584e07d68e6461cf9708 (diff) | |
| download | emacs-73cebbb87b72effb948f0d73e756a0dc0c55b71c.tar.gz emacs-73cebbb87b72effb948f0d73e756a0dc0c55b71c.zip | |
process-attributes uses /proc/stat for boot time
With a Linux kernel, use /proc/stat rather than get_boot_time
to get boot time, since when Emacs is running in a container
we want the underlying host boot time, not the container boot time.
This should be a better way to fix Bug#63496.
* src/sysdep.c: Do not include boot-time.h.
(get_host_boot_time) [GNU_LINUX || CYGWIN || __ANDROID__]:
New function.
(system_process_attributes) [GNU_LINUX || CYGWIN || __ANDROID__]:
Use it instead of get_boot_time.
Diffstat (limited to 'src')
| -rw-r--r-- | src/sysdep.c | 45 |
1 files changed, 43 insertions, 2 deletions
diff --git a/src/sysdep.c b/src/sysdep.c index 71108f50db1..1836891ab88 100644 --- a/src/sysdep.c +++ b/src/sysdep.c | |||
| @@ -30,7 +30,6 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ | |||
| 30 | #include <sys/random.h> | 30 | #include <sys/random.h> |
| 31 | #include <unistd.h> | 31 | #include <unistd.h> |
| 32 | 32 | ||
| 33 | #include <boot-time.h> | ||
| 34 | #include <c-ctype.h> | 33 | #include <c-ctype.h> |
| 35 | #include <close-stream.h> | 34 | #include <close-stream.h> |
| 36 | #include <pathmax.h> | 35 | #include <pathmax.h> |
| @@ -3454,6 +3453,48 @@ put_jiffies (Lisp_Object attrs, Lisp_Object propname, | |||
| 3454 | return Fcons (Fcons (propname, time_from_jiffies (ticks, hz, Qnil)), attrs); | 3453 | return Fcons (Fcons (propname, time_from_jiffies (ticks, hz, Qnil)), attrs); |
| 3455 | } | 3454 | } |
| 3456 | 3455 | ||
| 3456 | /* Get the host boot time into *BT and return 0 if successful; | ||
| 3457 | otherwise, possibly set *BT and return -1. | ||
| 3458 | Do not use get_boot_time, which returns a container's | ||
| 3459 | boot time instead of the underlying host's boot time. */ | ||
| 3460 | static int | ||
| 3461 | get_host_boot_time (struct timespec *bt) | ||
| 3462 | { | ||
| 3463 | int ret = -1; | ||
| 3464 | |||
| 3465 | block_input (); | ||
| 3466 | FILE *fp = emacs_fopen ("/proc/stat", "r"); | ||
| 3467 | |||
| 3468 | if (fp) | ||
| 3469 | { | ||
| 3470 | /* Look for "btime SECONDS" at line start, and return SECONDS if found. | ||
| 3471 | N counts bytes currently matched in BTIME_PAT. | ||
| 3472 | It starts at 1 to pretend scanning starts just after '\n'. */ | ||
| 3473 | int n = 1; | ||
| 3474 | static char const btime_pat[7] ATTRIBUTE_NONSTRING = "\nbtime "; | ||
| 3475 | |||
| 3476 | for (int c; 0 <= (c = getc (fp)); ) | ||
| 3477 | { | ||
| 3478 | n = c == btime_pat[n] ? n + 1 : c == '\n'; | ||
| 3479 | if (n == sizeof btime_pat) | ||
| 3480 | { | ||
| 3481 | intmax_t btime; | ||
| 3482 | if (fscanf (fp, "%jd", &btime) == 1) | ||
| 3483 | { | ||
| 3484 | ret = -ckd_add (&bt->tv_sec, btime, 0); | ||
| 3485 | bt->tv_nsec = 0; | ||
| 3486 | } | ||
| 3487 | break; | ||
| 3488 | } | ||
| 3489 | } | ||
| 3490 | |||
| 3491 | emacs_fclose (fp); | ||
| 3492 | } | ||
| 3493 | unblock_input (); | ||
| 3494 | |||
| 3495 | return ret; | ||
| 3496 | } | ||
| 3497 | |||
| 3457 | # if defined GNU_LINUX || defined __ANDROID__ | 3498 | # if defined GNU_LINUX || defined __ANDROID__ |
| 3458 | #define MAJOR(d) (((unsigned)(d) >> 8) & 0xfff) | 3499 | #define MAJOR(d) (((unsigned)(d) >> 8) & 0xfff) |
| 3459 | #define MINOR(d) (((unsigned)(d) & 0xff) | (((unsigned)(d) & 0xfff00000) >> 12)) | 3500 | #define MINOR(d) (((unsigned)(d) & 0xff) | (((unsigned)(d) & 0xfff00000) >> 12)) |
| @@ -3671,7 +3712,7 @@ system_process_attributes (Lisp_Object pid) | |||
| 3671 | attrs = put_jiffies (attrs, Qctime, cstime + cutime, hz); | 3712 | attrs = put_jiffies (attrs, Qctime, cstime + cutime, hz); |
| 3672 | 3713 | ||
| 3673 | struct timespec bt; | 3714 | struct timespec bt; |
| 3674 | if (get_boot_time (&bt) == 0) | 3715 | if (get_host_boot_time (&bt) == 0) |
| 3675 | { | 3716 | { |
| 3676 | Lisp_Object boot = Ftime_convert (timespec_to_lisp (bt), hz); | 3717 | Lisp_Object boot = Ftime_convert (timespec_to_lisp (bt), hz); |
| 3677 | Lisp_Object now = Ftime_convert (Qnil, hz); | 3718 | Lisp_Object now = Ftime_convert (Qnil, hz); |