]> granicus.if.org Git - procps-ng/commitdiff
pgrep.c: Replacing seconds_since_boot with uptime as suggested by Craig Small
authored <ed@s5h.net>
Thu, 21 Mar 2019 20:21:09 +0000 (20:21 +0000)
committerCraig Small <csmall@dropbear.xyz>
Sun, 17 May 2020 11:53:39 +0000 (21:53 +1000)
Makefile.am
pgrep.c

index 956f8a365fb7517c7a87e6d6333f889aa818a722..013424269c15b2d0cdce4d8c9a28d66b1774ac9c 100644 (file)
@@ -189,8 +189,8 @@ else
 endif
 
 free_SOURCES = free.c lib/strutils.c lib/fileutils.c
-pgrep_SOURCES = pgrep.c lib/fileutils.c lib/nsutils.c ps/global.c
-pkill_SOURCES = pgrep.c lib/fileutils.c lib/nsutils.c ps/global.c
+pgrep_SOURCES = pgrep.c lib/fileutils.c lib/nsutils.c
+pkill_SOURCES = pgrep.c lib/fileutils.c lib/nsutils.c
 pmap_SOURCES = pmap.c lib/fileutils.c
 if !CYGWIN
 pwdx_SOURCES = pwdx.c lib/fileutils.c
diff --git a/pgrep.c b/pgrep.c
index 64e75b417e331283a49d0409e0871d8e2b8e47e0..1e08992b3feb4ade2312cc8717615766b11231d3 100644 (file)
--- a/pgrep.c
+++ b/pgrep.c
@@ -53,7 +53,6 @@
 #include "proc/sig.h"
 #include "proc/devname.h"
 #include "proc/sysinfo.h"
-#include "ps/common.h"
 
 #define grow_size(x) do { \
        if ((x) < 0 || (size_t)(x) >= INT_MAX / 5 / sizeof(struct el)) \
@@ -531,17 +530,21 @@ static struct el * select_procs (int *num)
        char *cmdoutput = xmalloc(cmdlen);
        proc_t ns_task;
        time_t now;
+       double uptime_secs, idle_secs;
+
 
        ptp = do_openproc();
        preg = do_regcomp();
 
        now = time(NULL);
+       if (uptime(&uptime_secs, &idle_secs) == 0)
+               xerrx(EXIT_FAILURE, "uptime");
+
        if (opt_newest) saved_start_time =  0ULL;
        else saved_start_time = ~0ULL;
 
        if (opt_newest) saved_pid = 0;
        if (opt_oldest) saved_pid = INT_MAX;
-       if (opt_older) reset_global();
        if (opt_ns_pid && ns_read(opt_ns_pid, &ns_task)) {
                fputs(_("Error reading reference namespace information\n"),
                      stderr);
@@ -551,7 +554,6 @@ static struct el * select_procs (int *num)
        memset(&task, 0, sizeof (task));
        memset(&subtask, 0, sizeof (subtask));
        while(readproc(ptp, &task)) {
-               /* printf( "Process state %c\n", task.state ); */
                int match = 1;
 
                if (task.XXXID == myself)
@@ -587,7 +589,7 @@ static struct el * select_procs (int *num)
                        }
                }
                else if (opt_older)
-                       if(now - seconds_since_boot + (task.start_time / Hertz) + opt_older > now) match = 0;
+                       if(now - uptime_secs + (task.start_time / Hertz) + opt_older > now) match = 0;
                else if (opt_runstates) {
                        match = 0;
                        if (strchr(opt_runstates, task.state)) match = 1;