diff options
| -rw-r--r-- | procps/top.c | 39 |
1 files changed, 20 insertions, 19 deletions
diff --git a/procps/top.c b/procps/top.c index 38211b345..8e5767e41 100644 --- a/procps/top.c +++ b/procps/top.c | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * A tiny 'top' utility. | 2 | * A tiny 'top' utility. |
| 3 | * | 3 | * |
| 4 | * This is written specifically for the linux 2.4 /proc/<PID>/status | 4 | * This is written specifically for the linux /proc/<PID>/status |
| 5 | * file format, but it checks that the file actually conforms to the | 5 | * file format, but it checks that the file actually conforms to the |
| 6 | * format that this utility expects. | 6 | * format that this utility expects. |
| 7 | 7 | ||
| @@ -151,19 +151,21 @@ static void display_status(int count, const status_t *s) | |||
| 151 | /* checks if given 'buf' for process starts with 'id' + ':' + TAB | 151 | /* checks if given 'buf' for process starts with 'id' + ':' + TAB |
| 152 | * and stores rest of the buf to 'store' with max size 'size' | 152 | * and stores rest of the buf to 'store' with max size 'size' |
| 153 | */ | 153 | */ |
| 154 | static void process_status(const char *buf, const char *id, char *store, size_t size) | 154 | static int process_status(const char *buf, const char *id, char *store, size_t size) |
| 155 | { | 155 | { |
| 156 | int len, i; | 156 | int len, i; |
| 157 | 157 | ||
| 158 | if (!store) { | ||
| 159 | /* ignoring this field */ | ||
| 160 | return; | ||
| 161 | } | ||
| 162 | |||
| 163 | /* check status field name */ | 158 | /* check status field name */ |
| 164 | len = strlen(id); | 159 | len = strlen(id); |
| 165 | if (strncmp(buf, id, len) != 0) { | 160 | if (strncmp(buf, id, len) != 0) { |
| 166 | error_msg_and_die("ERROR status: line doesn't start with '%s' in:\n%s\n", id, buf); | 161 | if(store) |
| 162 | error_msg_and_die("ERROR status: line doesn't start with '%s' in:\n%s\n", id, buf); | ||
| 163 | else | ||
| 164 | return 0; | ||
| 165 | } | ||
| 166 | if (!store) { | ||
| 167 | /* ignoring this field */ | ||
| 168 | return 1; | ||
| 167 | } | 169 | } |
| 168 | buf += len; | 170 | buf += len; |
| 169 | 171 | ||
| @@ -193,9 +195,9 @@ static void process_status(const char *buf, const char *id, char *store, size_t | |||
| 193 | *store++ = *buf++; | 195 | *store++ = *buf++; |
| 194 | } | 196 | } |
| 195 | *store = '\0'; | 197 | *store = '\0'; |
| 198 | return 1; | ||
| 196 | } | 199 | } |
| 197 | 200 | ||
| 198 | |||
| 199 | /* read process statuses */ | 201 | /* read process statuses */ |
| 200 | static void read_status(int num, status_t *s) | 202 | static void read_status(int num, status_t *s) |
| 201 | { | 203 | { |
| @@ -219,20 +221,20 @@ static void read_status(int num, status_t *s) | |||
| 219 | fgets(buf, sizeof(buf), fp); | 221 | fgets(buf, sizeof(buf), fp); |
| 220 | process_status(buf, "State", s->state, sizeof(s->state)); | 222 | process_status(buf, "State", s->state, sizeof(s->state)); |
| 221 | fgets(buf, sizeof(buf), fp); | 223 | fgets(buf, sizeof(buf), fp); |
| 222 | process_status(buf, "Tgid", NULL, 0); | 224 | if(process_status(buf, "Tgid", NULL, 0)) |
| 223 | fgets(buf, sizeof(buf), fp); | 225 | fgets(buf, sizeof(buf), fp); |
| 224 | process_status(buf, "Pid", NULL, 0); | 226 | process_status(buf, "Pid", NULL, 0); |
| 225 | fgets(buf, sizeof(buf), fp); | 227 | fgets(buf, sizeof(buf), fp); |
| 226 | process_status(buf, "PPid", s->ppid, sizeof(s->ppid)); | 228 | process_status(buf, "PPid", s->ppid, sizeof(s->ppid)); |
| 227 | fgets(buf, sizeof(buf), fp); | 229 | fgets(buf, sizeof(buf), fp); |
| 228 | process_status(buf, "TracePid", NULL, 0); | 230 | if(process_status(buf, "TracerPid", NULL, 0)) |
| 229 | fgets(buf, sizeof(buf), fp); | 231 | fgets(buf, sizeof(buf), fp); |
| 230 | process_status(buf, "Uid", s->uid, sizeof(s->uid)); | 232 | process_status(buf, "Uid", s->uid, sizeof(s->uid)); |
| 231 | fgets(buf, sizeof(buf), fp); | 233 | fgets(buf, sizeof(buf), fp); |
| 232 | process_status(buf, "Gid", NULL, 0); | 234 | process_status(buf, "Gid", NULL, 0); |
| 233 | fgets(buf, sizeof(buf), fp); | 235 | fgets(buf, sizeof(buf), fp); |
| 234 | process_status(buf, "FDSize", NULL, 0); | 236 | if(process_status(buf, "FDSize", NULL, 0)) |
| 235 | fgets(buf, sizeof(buf), fp); | 237 | fgets(buf, sizeof(buf), fp); |
| 236 | process_status(buf, "Groups", NULL, 0); | 238 | process_status(buf, "Groups", NULL, 0); |
| 237 | fgets(buf, sizeof(buf), fp); | 239 | fgets(buf, sizeof(buf), fp); |
| 238 | /* only user space processes have command line | 240 | /* only user space processes have command line |
| @@ -342,7 +344,6 @@ static int num_sort(const void *a, const void *b) | |||
| 342 | } | 344 | } |
| 343 | } | 345 | } |
| 344 | 346 | ||
| 345 | |||
| 346 | int top_main(int argc, char **argv) | 347 | int top_main(int argc, char **argv) |
| 347 | { | 348 | { |
| 348 | status_t *statuslist; | 349 | status_t *statuslist; |
| @@ -353,8 +354,8 @@ int top_main(int argc, char **argv) | |||
| 353 | #endif | 354 | #endif |
| 354 | /* Default update rate is 5 seconds */ | 355 | /* Default update rate is 5 seconds */ |
| 355 | interval = 5; | 356 | interval = 5; |
| 356 | /* Default to 25 lines */ | 357 | /* Default to 25 lines - 5 lines for status */ |
| 357 | lines = 25; | 358 | lines = 25 - 5; |
| 358 | 359 | ||
| 359 | /* do normal option parsing */ | 360 | /* do normal option parsing */ |
| 360 | while ((opt = getopt(argc, argv, "d:")) > 0) { | 361 | while ((opt = getopt(argc, argv, "d:")) > 0) { |
| @@ -370,7 +371,7 @@ int top_main(int argc, char **argv) | |||
| 370 | #if defined CONFIG_FEATURE_AUTOWIDTH && defined CONFIG_FEATURE_USE_TERMIOS | 371 | #if defined CONFIG_FEATURE_AUTOWIDTH && defined CONFIG_FEATURE_USE_TERMIOS |
| 371 | ioctl(fileno(stdout), TIOCGWINSZ, &win); | 372 | ioctl(fileno(stdout), TIOCGWINSZ, &win); |
| 372 | if (win.ws_row > 4) | 373 | if (win.ws_row > 4) |
| 373 | lines = win.ws_row - 6; | 374 | lines = win.ws_row - 5; |
| 374 | #endif | 375 | #endif |
| 375 | 376 | ||
| 376 | /* change to proc */ | 377 | /* change to proc */ |
