]> granicus.if.org Git - procps-ng/commitdiff
snice: Fix matching on PID
authorCraig Small <csmall@dropbear.xyz>
Mon, 21 Oct 2019 21:14:35 +0000 (08:14 +1100)
committerCraig Small <csmall@dropbear.xyz>
Mon, 21 Oct 2019 21:14:35 +0000 (08:14 +1100)
@MarsChan correctly pointed out that the read() always returns 128
bytes, so skipping on >= 128 will always mean we skip. Their suggestion
was to remove the equality, but read will never go past 128 bytes so
I just removed that part of the check.

References:
 procps-ng/procps!89

NEWS
skill.c

diff --git a/NEWS b/NEWS
index 0401562b05da78db63165ad6111c539cb7d698c6..0a009857600d8ddc91b15c119da5ec21e81f337b 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,7 @@ procps-ng-NEXT
   * docs: Use correct symbols for -h option in free.1      Debian #898774
   * docs: ps.1 now warns about command name length         issue #101
   * pgrep: Match on runstate                               issue #109, Debian #919381
+  * snice: Fix matching on pid                             merge #89
   * top: can now exploit 256-color terminals               issue #96
   * top: preserves 'other filters' in configuration file   issue #99
   * top: can now collapse/expand forest view children      issue #99
diff --git a/skill.c b/skill.c
index 3bc331f67d5f638f6de6d4c195b84d694789a745..c91aa7b79353bdee330b4075d298d896826f1bf5 100644 (file)
--- a/skill.c
+++ b/skill.c
@@ -200,9 +200,9 @@ static void check_proc(int pid, struct run_time_conf_t *run_time)
                        goto closure;
        }
        len = read(fd, buf, sizeof(buf));
-       if (len <= 0 || (size_t)len >= sizeof(buf))
+       if (len <= 0)
                goto closure;
-       buf[len] = '\0';
+       buf[sizeof(buf) -1] = '\0';
        tmp = strrchr(buf, ')');
        if (!tmp)
                goto closure;