| 1 |
Description: library: procps_uptime -> clock_gettime, in <pids> api |
| 2 |
Use clock_gettime instead of procps_uptime for boot time. |
| 3 |
This will mean we can get the correct clock even if the system |
| 4 |
is in a container or pidfs mounted with subset=pid |
| 5 |
Author: Jim Warner <[email protected]> |
| 6 |
Origin: upstream |
| 7 |
Bug-Debian: https://bugs.debian.org/842879 |
| 8 |
Applied-Upstream: 4.0.5 |
| 9 |
Last-Update: 2025-04-14 <YYYY-MM-DD, last update of the meta-information, optional> |
| 10 |
--- |
| 11 |
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/ |
| 12 |
--- a/library/pids.c |
| 13 |
+++ b/library/pids.c |
| 14 |
@@ -30,12 +30,12 @@ |
| 15 |
#include <stdlib.h> |
| 16 |
#include <string.h> |
| 17 |
#include <unistd.h> |
| 18 |
+#include <time.h> |
| 19 |
|
| 20 |
#include <sys/stat.h> |
| 21 |
#include <sys/types.h> |
| 22 |
|
| 23 |
#include "devname.h" |
| 24 |
-#include "misc.h" |
| 25 |
#include "numa.h" |
| 26 |
#include "readproc.h" |
| 27 |
#include "wchan.h" |
| 28 |
@@ -1416,7 +1416,7 @@ |
| 29 |
struct pids_info *info, |
| 30 |
enum pids_fetch_type which) |
| 31 |
{ |
| 32 |
- double up_secs; |
| 33 |
+ struct timespec ts; |
| 34 |
|
| 35 |
errno = EINVAL; |
| 36 |
if (info == NULL) |
| 37 |
@@ -1444,11 +1444,9 @@ |
| 38 |
} |
| 39 |
errno = 0; |
| 40 |
|
| 41 |
- /* when in a namespace with proc mounted subset=pid, |
| 42 |
- we will be restricted to process information only */ |
| 43 |
info->boot_tics = 0; |
| 44 |
- if (0 >= procps_uptime(&up_secs, NULL)) |
| 45 |
- info->boot_tics = up_secs * info->hertz; |
| 46 |
+ if (0 >= clock_gettime(CLOCK_BOOTTIME, &ts)) |
| 47 |
+ info->boot_tics = (ts.tv_sec + ts.tv_nsec * 1.0e-9) * info->hertz; |
| 48 |
|
| 49 |
if (NULL == info->read_something(info->get_PT, &info->get_proc)) |
| 50 |
return NULL; |
| 51 |
@@ -1469,7 +1467,7 @@ |
| 52 |
struct pids_info *info, |
| 53 |
enum pids_fetch_type which) |
| 54 |
{ |
| 55 |
- double up_secs; |
| 56 |
+ struct timespec ts; |
| 57 |
int rc; |
| 58 |
|
| 59 |
errno = EINVAL; |
| 60 |
@@ -1487,11 +1485,9 @@ |
| 61 |
return NULL; |
| 62 |
info->read_something = which ? readeither : readproc; |
| 63 |
|
| 64 |
- /* when in a namespace with proc mounted subset=pid, |
| 65 |
- we will be restricted to process information only */ |
| 66 |
info->boot_tics = 0; |
| 67 |
- if (0 >= procps_uptime(&up_secs, NULL)) |
| 68 |
- info->boot_tics = up_secs * info->hertz; |
| 69 |
+ if (0 >= clock_gettime(CLOCK_BOOTTIME, &ts)) |
| 70 |
+ info->boot_tics = (ts.tv_sec + ts.tv_nsec * 1.0e-9) * info->hertz; |
| 71 |
|
| 72 |
rc = pids_stacks_fetch(info); |
| 73 |
|
| 74 |
@@ -1569,7 +1565,7 @@ |
| 75 |
enum pids_select_type which) |
| 76 |
{ |
| 77 |
unsigned ids[FILL_ID_MAX + 1]; |
| 78 |
- double up_secs; |
| 79 |
+ struct timespec ts; |
| 80 |
int rc; |
| 81 |
|
| 82 |
errno = EINVAL; |
| 83 |
@@ -1594,11 +1590,9 @@ |
| 84 |
return NULL; |
| 85 |
info->read_something = (which & PIDS_FETCH_THREADS_TOO) ? readeither : readproc; |
| 86 |
|
| 87 |
- /* when in a namespace with proc mounted subset=pid, |
| 88 |
- we will be restricted to process information only */ |
| 89 |
info->boot_tics = 0; |
| 90 |
- if (0 >= procps_uptime(&up_secs, NULL)) |
| 91 |
- info->boot_tics = up_secs * info->hertz; |
| 92 |
+ if (0 >= clock_gettime(CLOCK_BOOTTIME, &ts)) |
| 93 |
+ info->boot_tics = (ts.tv_sec + ts.tv_nsec * 1.0e-9) * info->hertz; |
| 94 |
|
| 95 |
rc = pids_stacks_fetch(info); |
| 96 |
|