| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 1 | /* |
| 2 | htop - ProcessList.c |
| 3 | (C) 2004,2005 Hisham H. Muhammad |
| 4 | Released under the GNU GPL, see the COPYING file |
| 5 | in the source distribution for its full text. |
| 6 | */ |
| 7 | |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 8 | #include "ProcessList.h" |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 9 | |
| Hisham Muhammad | 84281bd | 2011-12-26 21:35:57 +0000 | [diff] [blame] | 10 | #include "CRT.h" |
| 11 | #include "String.h" |
| Hisham Muhammad | 84281bd | 2011-12-26 21:35:57 +0000 | [diff] [blame] | 12 | |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 13 | #include <stdlib.h> |
| Hisham Muhammad | 84281bd | 2011-12-26 21:35:57 +0000 | [diff] [blame] | 14 | #include <string.h> |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 15 | |
| 16 | /*{ |
| Hisham Muhammad | 84281bd | 2011-12-26 21:35:57 +0000 | [diff] [blame] | 17 | #include "Vector.h" |
| 18 | #include "Hashtable.h" |
| 19 | #include "UsersTable.h" |
| 20 | #include "Panel.h" |
| 21 | #include "Process.h" |
| Hisham Muhammad | 3383d8e | 2015-01-21 23:27:31 -0200 | [diff] [blame^] | 22 | #include "Settings.h" |
| Hisham Muhammad | 6486229 | 2010-08-24 23:20:38 +0000 | [diff] [blame] | 23 | |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 24 | #ifndef MAX_NAME |
| Hisham Muhammad | 86d6313 | 2006-03-24 03:39:04 +0000 | [diff] [blame] | 25 | #define MAX_NAME 128 |
| 26 | #endif |
| 27 | |
| 28 | #ifndef MAX_READ |
| Hisham Muhammad | 5d48ab8 | 2006-07-11 06:13:32 +0000 | [diff] [blame] | 29 | #define MAX_READ 2048 |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 30 | #endif |
| 31 | |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 32 | typedef struct ProcessList_ { |
| Hisham Muhammad | 3383d8e | 2015-01-21 23:27:31 -0200 | [diff] [blame^] | 33 | Settings* settings; |
| 34 | |
| Hisham Muhammad | a853faa | 2006-05-30 13:45:40 +0000 | [diff] [blame] | 35 | Vector* processes; |
| 36 | Vector* processes2; |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 37 | Hashtable* processTable; |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 38 | UsersTable* usersTable; |
| 39 | |
| Hisham Muhammad | bfd86a6 | 2011-12-01 12:31:57 +0000 | [diff] [blame] | 40 | Panel* panel; |
| Hisham Muhammad | 1a604a0 | 2012-02-02 23:45:40 +0000 | [diff] [blame] | 41 | int following; |
| Hisham Muhammad | bfd86a6 | 2011-12-01 12:31:57 +0000 | [diff] [blame] | 42 | uid_t userId; |
| Hisham Muhammad | bfd86a6 | 2011-12-01 12:31:57 +0000 | [diff] [blame] | 43 | const char* incFilter; |
| Hisham Muhammad | e6c6d7f | 2012-08-10 21:54:41 +0000 | [diff] [blame] | 44 | Hashtable* pidWhiteList; |
| Hisham Muhammad | bfd86a6 | 2011-12-01 12:31:57 +0000 | [diff] [blame] | 45 | |
| Hisham Muhammad | bc87a8f | 2011-11-21 02:52:41 +0000 | [diff] [blame] | 46 | #ifdef HAVE_LIBHWLOC |
| Hisham Muhammad | ec17b70 | 2011-09-24 00:30:47 +0000 | [diff] [blame] | 47 | hwloc_topology_t topology; |
| 48 | bool topologyOk; |
| 49 | #endif |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 50 | |
| Hisham Muhammad | 3383d8e | 2015-01-21 23:27:31 -0200 | [diff] [blame^] | 51 | int cpuCount; |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 52 | |
| 53 | } ProcessList; |
| Hisham Muhammad | ca6b923 | 2011-11-03 22:12:12 +0000 | [diff] [blame] | 54 | |
| Hisham Muhammad | 3383d8e | 2015-01-21 23:27:31 -0200 | [diff] [blame^] | 55 | ProcessList* ProcessList_new(UsersTable* ut, Hashtable* pidWhiteList, uid_t userId); |
| Hisham Muhammad | cda6bdd | 2014-11-27 17:48:38 -0200 | [diff] [blame] | 56 | void ProcessList_delete(ProcessList* pl); |
| Hisham Muhammad | eb229d9 | 2014-11-24 18:55:03 -0200 | [diff] [blame] | 57 | void ProcessList_scan(ProcessList* pl); |
| 58 | |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 59 | }*/ |
| 60 | |
| Hisham Muhammad | 3383d8e | 2015-01-21 23:27:31 -0200 | [diff] [blame^] | 61 | ProcessList* ProcessList_init(ProcessList* this, UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId) { |
| Hisham Muhammad | 00b324b | 2012-12-05 15:12:20 +0000 | [diff] [blame] | 62 | this->processes = Vector_new(Class(Process), true, DEFAULT_SIZE); |
| Hisham Muhammad | 7ca1081 | 2011-11-18 06:08:56 +0000 | [diff] [blame] | 63 | this->processTable = Hashtable_new(140, false); |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 64 | this->usersTable = usersTable; |
| Hisham Muhammad | e6c6d7f | 2012-08-10 21:54:41 +0000 | [diff] [blame] | 65 | this->pidWhiteList = pidWhiteList; |
| Hisham Muhammad | 3383d8e | 2015-01-21 23:27:31 -0200 | [diff] [blame^] | 66 | this->userId = userId; |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 67 | |
| Hisham Muhammad | eb229d9 | 2014-11-24 18:55:03 -0200 | [diff] [blame] | 68 | // tree-view auxiliary buffers |
| Hisham Muhammad | 00b324b | 2012-12-05 15:12:20 +0000 | [diff] [blame] | 69 | this->processes2 = Vector_new(Class(Process), true, DEFAULT_SIZE); |
| Hisham Muhammad | 86d6313 | 2006-03-24 03:39:04 +0000 | [diff] [blame] | 70 | |
| Hisham Muhammad | eb229d9 | 2014-11-24 18:55:03 -0200 | [diff] [blame] | 71 | // set later by platform-specific code |
| 72 | this->cpuCount = 0; |
| Hisham Muhammad | ec17b70 | 2011-09-24 00:30:47 +0000 | [diff] [blame] | 73 | |
| Hisham Muhammad | bc87a8f | 2011-11-21 02:52:41 +0000 | [diff] [blame] | 74 | #ifdef HAVE_LIBHWLOC |
| Hisham Muhammad | ec17b70 | 2011-09-24 00:30:47 +0000 | [diff] [blame] | 75 | this->topologyOk = false; |
| 76 | int topoErr = hwloc_topology_init(&this->topology); |
| 77 | if (topoErr == 0) { |
| 78 | topoErr = hwloc_topology_load(this->topology); |
| Hisham Muhammad | 3fbd1ef | 2014-04-21 19:17:46 -0300 | [diff] [blame] | 79 | } |
| 80 | if (topoErr == 0) { |
| Hisham Muhammad | ec17b70 | 2011-09-24 00:30:47 +0000 | [diff] [blame] | 81 | this->topologyOk = true; |
| 82 | } |
| 83 | #endif |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 84 | |
| Hisham Muhammad | 05a78c8 | 2012-03-30 01:20:32 +0000 | [diff] [blame] | 85 | this->following = -1; |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 86 | |
| 87 | return this; |
| 88 | } |
| 89 | |
| Hisham Muhammad | cda6bdd | 2014-11-27 17:48:38 -0200 | [diff] [blame] | 90 | void ProcessList_done(ProcessList* this) { |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 91 | Hashtable_delete(this->processTable); |
| Hisham Muhammad | a853faa | 2006-05-30 13:45:40 +0000 | [diff] [blame] | 92 | Vector_delete(this->processes); |
| 93 | Vector_delete(this->processes2); |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 94 | } |
| 95 | |
| Hisham Muhammad | bfd86a6 | 2011-12-01 12:31:57 +0000 | [diff] [blame] | 96 | void ProcessList_setPanel(ProcessList* this, Panel* panel) { |
| 97 | this->panel = panel; |
| 98 | } |
| 99 | |
| Hisham Muhammad | d8e1480 | 2010-11-22 12:40:20 +0000 | [diff] [blame] | 100 | void ProcessList_printHeader(ProcessList* this, RichString* header) { |
| 101 | RichString_prune(header); |
| Hisham Muhammad | 3383d8e | 2015-01-21 23:27:31 -0200 | [diff] [blame^] | 102 | ProcessField* fields = this->settings->fields; |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 103 | for (int i = 0; fields[i]; i++) { |
| Hisham Muhammad | 3383d8e | 2015-01-21 23:27:31 -0200 | [diff] [blame^] | 104 | const char* field = Process_fields[fields[i]].title; |
| 105 | if (!field) field = "- "; |
| 106 | if (!this->settings->treeView && this->settings->sortKey == fields[i]) |
| Hisham Muhammad | d8e1480 | 2010-11-22 12:40:20 +0000 | [diff] [blame] | 107 | RichString_append(header, CRT_colors[PANEL_HIGHLIGHT_FOCUS], field); |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 108 | else |
| Hisham Muhammad | d8e1480 | 2010-11-22 12:40:20 +0000 | [diff] [blame] | 109 | RichString_append(header, CRT_colors[PANEL_HEADER_FOCUS], field); |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 110 | } |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 111 | } |
| 112 | |
| Hisham Muhammad | eb229d9 | 2014-11-24 18:55:03 -0200 | [diff] [blame] | 113 | void ProcessList_add(ProcessList* this, Process* p) { |
| Hisham Muhammad | febe259 | 2006-11-08 20:12:57 +0000 | [diff] [blame] | 114 | assert(Vector_indexOf(this->processes, p, Process_pidCompare) == -1); |
| 115 | assert(Hashtable_get(this->processTable, p->pid) == NULL); |
| Hisham Muhammad | 6486229 | 2010-08-24 23:20:38 +0000 | [diff] [blame] | 116 | |
| Hisham Muhammad | a853faa | 2006-05-30 13:45:40 +0000 | [diff] [blame] | 117 | Vector_add(this->processes, p); |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 118 | Hashtable_put(this->processTable, p->pid, p); |
| Hisham Muhammad | 6486229 | 2010-08-24 23:20:38 +0000 | [diff] [blame] | 119 | |
| Hisham Muhammad | febe259 | 2006-11-08 20:12:57 +0000 | [diff] [blame] | 120 | assert(Vector_indexOf(this->processes, p, Process_pidCompare) != -1); |
| 121 | assert(Hashtable_get(this->processTable, p->pid) != NULL); |
| Hisham Muhammad | 3d62edb | 2006-11-12 21:53:56 +0000 | [diff] [blame] | 122 | assert(Hashtable_count(this->processTable) == Vector_count(this->processes)); |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 123 | } |
| 124 | |
| Hisham Muhammad | eb229d9 | 2014-11-24 18:55:03 -0200 | [diff] [blame] | 125 | void ProcessList_remove(ProcessList* this, Process* p) { |
| Hisham Muhammad | febe259 | 2006-11-08 20:12:57 +0000 | [diff] [blame] | 126 | assert(Vector_indexOf(this->processes, p, Process_pidCompare) != -1); |
| 127 | assert(Hashtable_get(this->processTable, p->pid) != NULL); |
| 128 | Process* pp = Hashtable_remove(this->processTable, p->pid); |
| Hisham Muhammad | 8adc7ac | 2006-11-08 21:49:52 +0000 | [diff] [blame] | 129 | assert(pp == p); (void)pp; |
| Hisham Muhammad | a227b20 | 2007-04-05 19:53:23 +0000 | [diff] [blame] | 130 | unsigned int pid = p->pid; |
| Hisham Muhammad | 8f23092 | 2010-02-25 01:37:31 +0000 | [diff] [blame] | 131 | int idx = Vector_indexOf(this->processes, p, Process_pidCompare); |
| 132 | assert(idx != -1); |
| 133 | if (idx >= 0) Vector_remove(this->processes, idx); |
| Hisham Muhammad | 8adc7ac | 2006-11-08 21:49:52 +0000 | [diff] [blame] | 134 | assert(Hashtable_get(this->processTable, pid) == NULL); (void)pid; |
| Hisham Muhammad | 3d62edb | 2006-11-12 21:53:56 +0000 | [diff] [blame] | 135 | assert(Hashtable_count(this->processTable) == Vector_count(this->processes)); |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 136 | } |
| 137 | |
| Hisham Muhammad | 8f23092 | 2010-02-25 01:37:31 +0000 | [diff] [blame] | 138 | Process* ProcessList_get(ProcessList* this, int idx) { |
| 139 | return (Process*) (Vector_get(this->processes, idx)); |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | int ProcessList_size(ProcessList* this) { |
| Hisham Muhammad | a853faa | 2006-05-30 13:45:40 +0000 | [diff] [blame] | 143 | return (Vector_size(this->processes)); |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 144 | } |
| 145 | |
| Hisham Muhammad | 9eb9121 | 2010-06-17 19:02:03 +0000 | [diff] [blame] | 146 | static void ProcessList_buildTree(ProcessList* this, pid_t pid, int level, int indent, int direction, bool show) { |
| Hisham Muhammad | 00b324b | 2012-12-05 15:12:20 +0000 | [diff] [blame] | 147 | Vector* children = Vector_new(Class(Process), false, DEFAULT_SIZE); |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 148 | |
| Hisham Muhammad | febe259 | 2006-11-08 20:12:57 +0000 | [diff] [blame] | 149 | for (int i = Vector_size(this->processes) - 1; i >= 0; i--) { |
| Hisham Muhammad | a853faa | 2006-05-30 13:45:40 +0000 | [diff] [blame] | 150 | Process* process = (Process*) (Vector_get(this->processes, i)); |
| Hisham Muhammad | a7c2aed | 2007-11-08 23:23:01 +0000 | [diff] [blame] | 151 | if (process->tgid == pid || (process->tgid == process->pid && process->ppid == pid)) { |
| Hisham Muhammad | 8f23092 | 2010-02-25 01:37:31 +0000 | [diff] [blame] | 152 | process = (Process*) (Vector_take(this->processes, i)); |
| Hisham Muhammad | a853faa | 2006-05-30 13:45:40 +0000 | [diff] [blame] | 153 | Vector_add(children, process); |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 154 | } |
| 155 | } |
| Hisham Muhammad | a853faa | 2006-05-30 13:45:40 +0000 | [diff] [blame] | 156 | int size = Vector_size(children); |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 157 | for (int i = 0; i < size; i++) { |
| Hisham Muhammad | a853faa | 2006-05-30 13:45:40 +0000 | [diff] [blame] | 158 | Process* process = (Process*) (Vector_get(children, i)); |
| Hisham Muhammad | d8e1480 | 2010-11-22 12:40:20 +0000 | [diff] [blame] | 159 | if (!show) |
| 160 | process->show = false; |
| Hisham Muhammad | d8e1480 | 2010-11-22 12:40:20 +0000 | [diff] [blame] | 161 | int s = this->processes2->items; |
| 162 | if (direction == 1) |
| 163 | Vector_add(this->processes2, process); |
| 164 | else |
| 165 | Vector_insert(this->processes2, 0, process); |
| 166 | assert(this->processes2->items == s+1); (void)s; |
| 167 | int nextIndent = indent | (1 << level); |
| Hisham Muhammad | 5effb12 | 2010-11-24 12:00:34 +0000 | [diff] [blame] | 168 | ProcessList_buildTree(this, process->pid, level+1, (i < size - 1) ? nextIndent : indent, direction, show ? process->showChildren : false); |
| Hisham Muhammad | ca6b923 | 2011-11-03 22:12:12 +0000 | [diff] [blame] | 169 | if (i == size - 1) |
| 170 | process->indent = -nextIndent; |
| 171 | else |
| 172 | process->indent = nextIndent; |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 173 | } |
| Hisham Muhammad | a853faa | 2006-05-30 13:45:40 +0000 | [diff] [blame] | 174 | Vector_delete(children); |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | void ProcessList_sort(ProcessList* this) { |
| Hisham Muhammad | 3383d8e | 2015-01-21 23:27:31 -0200 | [diff] [blame^] | 178 | if (!this->settings->treeView) { |
| Hisham Muhammad | 7ca1081 | 2011-11-18 06:08:56 +0000 | [diff] [blame] | 179 | Vector_insertionSort(this->processes); |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 180 | } else { |
| Hisham Muhammad | a7c2aed | 2007-11-08 23:23:01 +0000 | [diff] [blame] | 181 | // Save settings |
| Hisham Muhammad | 3383d8e | 2015-01-21 23:27:31 -0200 | [diff] [blame^] | 182 | int direction = this->settings->direction; |
| 183 | int sortKey = this->settings->sortKey; |
| Hisham Muhammad | a7c2aed | 2007-11-08 23:23:01 +0000 | [diff] [blame] | 184 | // Sort by PID |
| Hisham Muhammad | 3383d8e | 2015-01-21 23:27:31 -0200 | [diff] [blame^] | 185 | this->settings->sortKey = PID; |
| 186 | this->settings->direction = 1; |
| Hisham Muhammad | 7ca1081 | 2011-11-18 06:08:56 +0000 | [diff] [blame] | 187 | Vector_quickSort(this->processes); |
| Hisham Muhammad | a7c2aed | 2007-11-08 23:23:01 +0000 | [diff] [blame] | 188 | // Restore settings |
| Hisham Muhammad | 3383d8e | 2015-01-21 23:27:31 -0200 | [diff] [blame^] | 189 | this->settings->sortKey = sortKey; |
| 190 | this->settings->direction = direction; |
| Hisham Muhammad | a7c2aed | 2007-11-08 23:23:01 +0000 | [diff] [blame] | 191 | // Take PID 1 as root and add to the new listing |
| Hisham Muhammad | 3d62edb | 2006-11-12 21:53:56 +0000 | [diff] [blame] | 192 | int vsize = Vector_size(this->processes); |
| Hisham Muhammad | a853faa | 2006-05-30 13:45:40 +0000 | [diff] [blame] | 193 | Process* init = (Process*) (Vector_take(this->processes, 0)); |
| Hisham Muhammad | eb229d9 | 2014-11-24 18:55:03 -0200 | [diff] [blame] | 194 | if (!init) return; |
| Hisham Muhammad | a2f6eea | 2008-09-23 06:29:03 +0000 | [diff] [blame] | 195 | // This assertion crashes on hardened kernels. |
| 196 | // I wonder how well tree view works on those systems. |
| 197 | // assert(init->pid == 1); |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 198 | init->indent = 0; |
| Hisham Muhammad | a853faa | 2006-05-30 13:45:40 +0000 | [diff] [blame] | 199 | Vector_add(this->processes2, init); |
| Hisham Muhammad | a7c2aed | 2007-11-08 23:23:01 +0000 | [diff] [blame] | 200 | // Recursively empty list |
| Hisham Muhammad | 9eb9121 | 2010-06-17 19:02:03 +0000 | [diff] [blame] | 201 | ProcessList_buildTree(this, init->pid, 0, 0, direction, true); |
| Hisham Muhammad | a7c2aed | 2007-11-08 23:23:01 +0000 | [diff] [blame] | 202 | // Add leftovers |
| Hisham Muhammad | 3d62edb | 2006-11-12 21:53:56 +0000 | [diff] [blame] | 203 | while (Vector_size(this->processes)) { |
| 204 | Process* p = (Process*) (Vector_take(this->processes, 0)); |
| 205 | p->indent = 0; |
| 206 | Vector_add(this->processes2, p); |
| Hisham Muhammad | 9eb9121 | 2010-06-17 19:02:03 +0000 | [diff] [blame] | 207 | ProcessList_buildTree(this, p->pid, 0, 0, direction, p->showChildren); |
| Hisham Muhammad | 3d62edb | 2006-11-12 21:53:56 +0000 | [diff] [blame] | 208 | } |
| 209 | assert(Vector_size(this->processes2) == vsize); (void)vsize; |
| 210 | assert(Vector_size(this->processes) == 0); |
| Hisham Muhammad | a7c2aed | 2007-11-08 23:23:01 +0000 | [diff] [blame] | 211 | // Swap listings around |
| Hisham Muhammad | a853faa | 2006-05-30 13:45:40 +0000 | [diff] [blame] | 212 | Vector* t = this->processes; |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 213 | this->processes = this->processes2; |
| 214 | this->processes2 = t; |
| 215 | } |
| 216 | } |
| 217 | |
| Hisham Muhammad | 2338ad5 | 2008-03-14 18:50:49 +0000 | [diff] [blame] | 218 | |
| 219 | ProcessField ProcessList_keyAt(ProcessList* this, int at) { |
| 220 | int x = 0; |
| Hisham Muhammad | 3383d8e | 2015-01-21 23:27:31 -0200 | [diff] [blame^] | 221 | ProcessField* fields = this->settings->fields; |
| Hisham Muhammad | 2338ad5 | 2008-03-14 18:50:49 +0000 | [diff] [blame] | 222 | ProcessField field; |
| 223 | for (int i = 0; (field = fields[i]); i++) { |
| Hisham Muhammad | 3383d8e | 2015-01-21 23:27:31 -0200 | [diff] [blame^] | 224 | const char* title = Process_fields[field].title; |
| 225 | if (!title) title = "- "; |
| 226 | int len = strlen(title); |
| Hisham Muhammad | 2338ad5 | 2008-03-14 18:50:49 +0000 | [diff] [blame] | 227 | if (at >= x && at <= x + len) { |
| 228 | return field; |
| 229 | } |
| 230 | x += len; |
| 231 | } |
| 232 | return COMM; |
| 233 | } |
| Hisham Muhammad | 6486229 | 2010-08-24 23:20:38 +0000 | [diff] [blame] | 234 | |
| 235 | void ProcessList_expandTree(ProcessList* this) { |
| 236 | int size = Vector_size(this->processes); |
| 237 | for (int i = 0; i < size; i++) { |
| 238 | Process* process = (Process*) Vector_get(this->processes, i); |
| 239 | process->showChildren = true; |
| 240 | } |
| 241 | } |
| Hisham Muhammad | bfd86a6 | 2011-12-01 12:31:57 +0000 | [diff] [blame] | 242 | |
| Hisham Muhammad | 3383d8e | 2015-01-21 23:27:31 -0200 | [diff] [blame^] | 243 | void ProcessList_rebuildPanel(ProcessList* this) { |
| 244 | int following = this->following; |
| 245 | const char* incFilter = this->incFilter; |
| Hisham Muhammad | bfd86a6 | 2011-12-01 12:31:57 +0000 | [diff] [blame] | 246 | |
| 247 | int currPos = Panel_getSelectedIndex(this->panel); |
| Hisham Muhammad | 3383d8e | 2015-01-21 23:27:31 -0200 | [diff] [blame^] | 248 | pid_t currPid = this->following != -1 ? this->following : 0; |
| Hisham Muhammad | bfd86a6 | 2011-12-01 12:31:57 +0000 | [diff] [blame] | 249 | int currScrollV = this->panel->scrollV; |
| Hisham Muhammad | bfd86a6 | 2011-12-01 12:31:57 +0000 | [diff] [blame] | 250 | |
| 251 | Panel_prune(this->panel); |
| 252 | int size = ProcessList_size(this); |
| 253 | int idx = 0; |
| 254 | for (int i = 0; i < size; i++) { |
| 255 | bool hidden = false; |
| 256 | Process* p = ProcessList_get(this, i); |
| 257 | |
| 258 | if ( (!p->show) |
| Hisham Muhammad | 3383d8e | 2015-01-21 23:27:31 -0200 | [diff] [blame^] | 259 | || (this->userId != (uid_t) -1 && (p->st_uid != this->userId)) |
| Hisham Muhammad | 2a73405 | 2012-11-10 00:31:37 +0000 | [diff] [blame] | 260 | || (incFilter && !(String_contains_i(p->comm, incFilter))) |
| Hisham Muhammad | e6c6d7f | 2012-08-10 21:54:41 +0000 | [diff] [blame] | 261 | || (this->pidWhiteList && !Hashtable_get(this->pidWhiteList, p->pid)) ) |
| Hisham Muhammad | bfd86a6 | 2011-12-01 12:31:57 +0000 | [diff] [blame] | 262 | hidden = true; |
| 263 | |
| 264 | if (!hidden) { |
| 265 | Panel_set(this->panel, idx, (Object*)p); |
| Hisham Muhammad | 3383d8e | 2015-01-21 23:27:31 -0200 | [diff] [blame^] | 266 | if ((this->following == -1 && idx == currPos) || (this->following != -1 && p->pid == currPid)) { |
| Hisham Muhammad | bfd86a6 | 2011-12-01 12:31:57 +0000 | [diff] [blame] | 267 | Panel_setSelected(this->panel, idx); |
| 268 | this->panel->scrollV = currScrollV; |
| 269 | } |
| 270 | idx++; |
| 271 | } |
| 272 | } |
| 273 | } |
| Hisham Muhammad | eb229d9 | 2014-11-24 18:55:03 -0200 | [diff] [blame] | 274 | |