]> granicus.if.org Git - procps-ng/commitdiff
slabtop: Check for bad d and o option combination
authorCraig Small <csmall@dropbear.xyz>
Thu, 11 Mar 2021 11:10:37 +0000 (22:10 +1100)
committerCraig Small <csmall@dropbear.xyz>
Thu, 11 Mar 2021 11:10:37 +0000 (22:10 +1100)
If you run slabtop with the -d option and then -o option the
delay gets set to zero and it runs forever. slabtop now checks
for this combination and errors.

Adding a DEJAGNU test also found that none of the slabtop
checks were running so they got added to the list and only the
ones that need /proc/slabinfo (if not readable) are skipped.

References:
 #160

NEWS
slabtop.1
slabtop.c
testsuite/Makefile.am
testsuite/slabtop.test/slabtop.exp

diff --git a/NEWS b/NEWS
index 8fd047ebc849100103f317ae315e8cd2675c83bf..7e71021ac6ac7b2e1c731674c641260dd727008a 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,7 @@ procps-ng-NEXT
   * Rename pwait to pidwait
   * library: renamed to libproc-2 and reset to 0:0:0
   * ps: Add OOM and OOMADJ fields                          issue #198
+  * slabtop: Don't combine d and o options                 issue #160
 
 procps-ng-3.3.17
 ---------------
index 2c403ffee7e7db9b1e6bc32b7598350745ff8176..af45032baf683bc3e4ed4d8403c967e71b642999 100644 (file)
--- a/slabtop.1
+++ b/slabtop.1
@@ -2,7 +2,7 @@
 .\"
 .\" Copyright (C) 2003 Chris Rivera
 .\" Licensed under the terms of the GNU Library General Public License, v2
-.TH SLABTOP "1" "June 2011" "procps-ng" "User Commands"
+.TH SLABTOP "1" "2021-03-11" "procps-ng" "User Commands"
 .SH NAME
 slabtop \- display kernel slab cache information in real time
 .SH SYNOPSIS
@@ -25,7 +25,8 @@ Refresh the display every
 in seconds.  By default,
 .B slabtop
 refreshes the display every three seconds.  To exit the program, hit
-.BR q.
+.BR q .
+This cannot be combined with the \fB-o\fR option.
 .TP
 \fB\-s\fR, \fB\-\-sort\fR=\fIS\fR
 Sort by \fIS\fR, where \fIS\fR is one of the sort criteria.
index 64a52da098e295b1d4584f4f403a665a738e40d9..e415218e1ec0346e21b5eb1a90369d94787e6c0f 100644 (file)
--- a/slabtop.c
+++ b/slabtop.c
 #define DEFAULT_SORT  SLAB_NUM_OBJS
 #define CHAINS_ALLOC  150
 #define MAXTBL(t) (int)( sizeof(t) / sizeof(t[0]) )
+#define DEFAULT_DELAY 3
 
 static unsigned short Cols, Rows;
 static struct termios Saved_tty;
-static long Delay = 3;
+static long Delay = 0;
 static int Run_once = 0;
 
 static struct slabinfo_info *Slab_info;
@@ -181,6 +182,8 @@ static void parse_opts (int argc, char **argv)
     while ((o = getopt_long(argc, argv, "d:s:ohV", longopts, NULL)) != -1) {
         switch (o) {
         case 'd':
+           if (Run_once)
+               xerrx(EXIT_FAILURE, _("Cannot combine -d and -o options"));
             errno = 0;
             Delay = strtol_or_err(optarg, _("illegal delay"));
             if (Delay < 1)
@@ -190,8 +193,9 @@ static void parse_opts (int argc, char **argv)
             set_sort_stuff(optarg[0]);
             break;
         case 'o':
+           if (Delay != 0)
+               xerrx(EXIT_FAILURE, _("Cannot combine -d and -o options"));
             Run_once=1;
-            Delay = 0;
             break;
         case 'V':
             printf(PROCPS_NG_VERSION);
@@ -204,6 +208,8 @@ static void parse_opts (int argc, char **argv)
     }
     if (optind != argc)
         usage(stderr);
+    if (!Run_once && Delay == 0)
+       Delay = DEFAULT_DELAY;
 }
 
 static void print_summary (void)
index 10d26a003cfb829efef5b13444f5c9f7df4f19df..ec95f5ac0e972581347a27278cd95cf40af16ece 100644 (file)
@@ -31,6 +31,7 @@ DEJATOOL += \
        pkill \
        ps \
        pwdx \
+       slabtop \
        uptime \
        vmstat \
        w
@@ -51,6 +52,7 @@ EXTRA_DIST = \
     ps.test/ps_personality.exp \
     ps.test/ps_sched_batch.exp \
     pwdx.test/pwdx.exp \
+    slabtop.test/slabtop.exp \
     uptime.test/uptime.exp \
     vmstat.test/vmstat.exp \
     w.test/w.exp
index 93f997910dc68f5fea527044afc87aa0505b4542..ec43d072c024cd502bd1e3de1f53dfb90fa9ca12 100644 (file)
@@ -7,15 +7,20 @@ set avst "Active / Total"
 set used "\\\(% used\\\)\\s+:"
 set pct "\\\(\\d+\\.\\d+%\\\)"
 
-if { [ file readable "/proc/slabinfo" ] == 0 } {
-    unsupported "slabtop tests disabled as /proc/slabinfo is unreadable"
-} else {
 set slabtop_header "^ $avst Objects $used \\d+ / \\d+ ${pct}\\s+$avst Slabs $used \\d+ / \\d+ ${pct}\\s+$avst Caches $used \\d+ / \\d+ ${pct}\\s+$avst Size $used \\d+\\.\\d+K / \\d+\\.\\d+K ${pct}\\s+Minimum / Average / Maximum Object : \\d+\\.\\d+K / \\d+\\.\\d+K / \\d+\\.\\d+K\\s+OBJS ACTIVE  USE OBJ SIZE  SLABS OBJ/SLAB CACHE SIZE NAME\\s+"
 
 set test "slabtop help"
 spawn $slabtop --help
 expect_pass $test "^\\s+Usage:\\s+\(lt-\)\?slabtop \\\[options\\\]"
 
+set test "slabtop o then d options"
+spawn $slabtop -o -d 10
+expect_pass $test "Cannot combine -d and -o options"
+
+set test "slabtop d then o options"
+spawn $slabtop -d 10 -o
+expect_pass $test "Cannot combine -d and -o options"
+
 set sort_tests {
     "a" "active objects" "^\\s*\\d+\\s+(\\d+)\\s+\\d+%\\s+\\d+\\.\\d+K\\s+\\d+\\s+\\d+\\s+\\d+K\\s+\\S\[^\r\]+\\s*"
     "b" "objects per slab" "^\\s*\\d+\\s+\\d+\\s+\\d+%\\s+\\d+\\.\\d+K\\s+\\d+\\s+(\\d+)\\s+\\d+K\\s+\\S\[^\r\]+\\s*"
@@ -25,9 +30,16 @@ set sort_tests {
     "s" "object size" "^\\s*\\d+\\s+\\d+\\s+\\d+%\\s+(\\d+\\.\\d+)K\\s+\\d+\\s+\\d+\\s+\\d+K\\s+\\S\[^\r\]+\\s*" 
     "u" "utilisation" "^\\s*\\d+\\s+\\d+\\s+(\\d+)%\\s+\\d+\\.\\d+K\\s+\\d+\\s+\\d+\\s+\\d+K\\s+\\S\[^\r\]+\\s*" 
  }
+
+# BEGIN - Tests requiring /proc/slabinfo
+if { [ file readable "/proc/slabinfo" ] == 0 } {
+    unsupported "slabtop tests disabled as /proc/slabinfo is unreadable"
+} else {
+
 foreach { flag desc match } $sort_tests {
     set test "slabtop sorted by $desc"
     spawn $slabtop -o -s $flag
     expect_table_dsc $test $slabtop_header $match
 }
 }
+# END - Tests requiring /proc/slabinfo