top: Actually implement DragonFly code for the interactive 'c' command.
authorImre Vadász <imre@vdsz.com>
Tue, 10 Nov 2015 21:18:28 +0000 (22:18 +0100)
committerImre Vadász <imre@vdsz.com>
Tue, 10 Nov 2015 22:02:02 +0000 (23:02 +0100)
Using the 'c' command now allows filtering displayed processes by
command name, as documented in top(1). Filtering by command name displays
only processes whose command contains the given substring.
This matches thte behaviour of the 'g' option in OpenBSD's top.

Using 'c' again and just pressing enter without entering a command name,
disables filtering and displays all processes again.

usr.bin/top/m_dragonfly.c

index 6ad315e..6e6385e 100644 (file)
@@ -456,6 +456,7 @@ get_process_info(struct system_info *si, struct process_select *sel,
        int show_system;
        int show_uid;
        int show_threads;
+       char *match_command;
 
        show_threads = sel->threads;
 
@@ -477,6 +478,7 @@ get_process_info(struct system_info *si, struct process_select *sel,
        show_system = sel->system;
        show_uid = sel->uid != -1;
        show_fullcmd = sel->fullcmd;
+       match_command = sel->command;
 
        /* count up process states and get pointers to interesting procs */
        total_procs = 0;
@@ -502,7 +504,9 @@ get_process_info(struct system_info *si, struct process_select *sel,
                                process_states[pstate]++;
                        if ((show_system && (LP(pp, pid) == -1)) ||
                            (show_idle || (LP(pp, pctcpu) != 0) ||
-                           (lpstate == LSRUN)) &&
+                            (lpstate == LSRUN)) &&
+                           (match_command == NULL ||
+                            strstr(PP(pp, comm), match_command)) &&
                            (!show_uid || PP(pp, ruid) == (uid_t) sel->uid)) {
                                *prefp++ = pp;
                                active_procs++;