top: Fix -Sc option combination (bug #2670)
authorJohn Marino <draco@marino.st>
Wed, 28 May 2014 16:26:52 +0000 (18:26 +0200)
committerJohn Marino <draco@marino.st>
Wed, 28 May 2014 18:51:51 +0000 (20:51 +0200)
It was reported that the "top -S" and "top -c" commands work as expected
but "top -Sc" showed repeated lines.  I confirmed a malfunction, but a
different one: all 20 lines showing in console were the same.

The following patch will revert to standard format if a system command is
detected, otherwise the desired "full command" option is shown.

< http://bugs.dragonflybsd.org/issues/2670 >

usr.bin/top/m_dragonfly.c

index 38f4d0b..9bf8fa5 100644 (file)
@@ -534,6 +534,7 @@ format_next_process(caddr_t xhandle, char *(*get_userid) (int))
        char status[16];
        int state;
        int xnice;
+       int prefer_fullcmd;
        char **comm_full;
        char *comm;
        char cputime_fmt[10], ccputime_fmt[10];
@@ -544,9 +545,11 @@ format_next_process(caddr_t xhandle, char *(*get_userid) (int))
        hp->remaining--;
 
        /* get the process's command name */
+       prefer_fullcmd = show_fullcmd;
        if (show_fullcmd) {
                if ((comm_full = kvm_getargv(kd, pp, 0)) == NULL) {
-                       return (fmt);
+                       prefer_fullcmd = 0;
+                       comm = PP(pp, comm);
                }
        }
        else {
@@ -627,7 +630,7 @@ format_next_process(caddr_t xhandle, char *(*get_userid) (int))
            ccputime_fmt,
            100.0 * pct,
            cmdlength,
-           show_fullcmd ? *comm_full : comm);
+           prefer_fullcmd ? *comm_full : comm);
 
        /* return the result */
        return (fmt);