aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-07-03 22:16:17 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2009-07-03 22:16:17 +0200
commitfca70a8cce579ce8cc8caf246c22f0c6e6c6e139 (patch)
tree2c17970b64b12c34624a18cf42b2c39a2cb5329d /libbb
parentc5d07fba29a477569a96777c9cab73e53b1ddd5c (diff)
downloadbusybox-w32-fca70a8cce579ce8cc8caf246c22f0c6e6c6e139.tar.gz
busybox-w32-fca70a8cce579ce8cc8caf246c22f0c6e6c6e139.tar.bz2
busybox-w32-fca70a8cce579ce8cc8caf246c22f0c6e6c6e139.zip
ps: conditionally support additional -o FIELDs
function old new delta procps_scan 1409 1642 +233 out_spec 220 300 +80 func_ruser - 36 +36 func_rgroup - 36 +36 func_group 13 49 +36 func_nice - 29 +29 buffer_fill_and_print 179 196 +17 send_tree 355 360 +5 mkfs_vfat_main 1604 1609 +5 display_speed 85 90 +5 scriptreplay_main 194 197 +3 find_out_spec 55 58 +3 changepath 192 195 +3 sha1_process_block64 497 484 -13 ------------------------------------------------------------------------------ (add/remove: 3/0 grow/shrink: 10/1 up/down: 491/-13) Total: 478 bytes Signed-off-by: David Krakov <krakov@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb')
-rw-r--r--libbb/procps.c40
1 files changed, 38 insertions, 2 deletions
diff --git a/libbb/procps.c b/libbb/procps.c
index 445e709c8..6e122c4d5 100644
--- a/libbb/procps.c
+++ b/libbb/procps.c
@@ -151,6 +151,16 @@ static unsigned long fast_strtoul_10(char **endptr)
151 *endptr = str + 1; /* We skip trailing space! */ 151 *endptr = str + 1; /* We skip trailing space! */
152 return n; 152 return n;
153} 153}
154
155static long fast_strtol_10(char **endptr)
156{
157 if (**endptr != '-')
158 return fast_strtoul_10(endptr);
159
160 (*endptr)++;
161 return - (long)fast_strtoul_10(endptr);
162}
163
154static char *skip_fields(char *str, int count) 164static char *skip_fields(char *str, int count)
155{ 165{
156 do { 166 do {
@@ -208,7 +218,7 @@ procps_status_t* FAST_FUNC procps_scan(procps_status_t* sp, int flags)
208 if (flags & PSSCAN_UIDGID) { 218 if (flags & PSSCAN_UIDGID) {
209 if (stat(filename, &sb)) 219 if (stat(filename, &sb))
210 break; 220 break;
211 /* Need comment - is this effective or real UID/GID? */ 221 /* Effective UID/GID, not real */
212 sp->uid = sb.st_uid; 222 sp->uid = sb.st_uid;
213 sp->gid = sb.st_gid; 223 sp->gid = sb.st_gid;
214 } 224 }
@@ -293,7 +303,7 @@ procps_status_t* FAST_FUNC procps_scan(procps_status_t* sp, int flags)
293 sp->utime = fast_strtoul_10(&cp); 303 sp->utime = fast_strtoul_10(&cp);
294 sp->stime = fast_strtoul_10(&cp); 304 sp->stime = fast_strtoul_10(&cp);
295 cp = skip_fields(cp, 3); /* cutime, cstime, priority */ 305 cp = skip_fields(cp, 3); /* cutime, cstime, priority */
296 tasknice = fast_strtoul_10(&cp); 306 tasknice = fast_strtol_10(&cp);
297 cp = skip_fields(cp, 2); /* timeout, it_real_value */ 307 cp = skip_fields(cp, 2); /* timeout, it_real_value */
298 sp->start_time = fast_strtoul_10(&cp); 308 sp->start_time = fast_strtoul_10(&cp);
299 /* vsz is in bytes and we want kb */ 309 /* vsz is in bytes and we want kb */
@@ -310,6 +320,10 @@ procps_status_t* FAST_FUNC procps_scan(procps_status_t* sp, int flags)
310#endif 320#endif
311#endif /* end of !ENABLE_FEATURE_TOP_SMP_PROCESS */ 321#endif /* end of !ENABLE_FEATURE_TOP_SMP_PROCESS */
312 322
323#if ENABLE_FEATURE_PS_ADDITIONAL_COLUMNS
324 sp->niceness = tasknice;
325#endif
326
313 if (sp->vsz == 0 && sp->state[0] != 'Z') 327 if (sp->vsz == 0 && sp->state[0] != 'Z')
314 sp->state[1] = 'W'; 328 sp->state[1] = 'W';
315 else 329 else
@@ -372,7 +386,29 @@ procps_status_t* FAST_FUNC procps_scan(procps_status_t* sp, int flags)
372 fclose(file); 386 fclose(file);
373 } 387 }
374#endif /* TOPMEM */ 388#endif /* TOPMEM */
389#if ENABLE_FEATURE_PS_ADDITIONAL_COLUMNS
390 if (flags & PSSCAN_RUIDGID) {
391 FILE *file;
375 392
393 strcpy(filename_tail, "/status");
394 file = fopen_for_read(filename);
395 if (!file)
396 break;
397 while (fgets(buf, sizeof(buf), file)) {
398 char *tp;
399#define SCAN_TWO(str, name, statement) \
400 if (strncmp(buf, str, sizeof(str)-1) == 0) { \
401 tp = skip_whitespace(buf + sizeof(str)-1); \
402 sscanf(tp, "%u", &sp->name); \
403 statement; \
404 }
405 SCAN_TWO("Uid:", ruid, continue);
406 SCAN_TWO("Gid:", rgid, break);
407#undef SCAN_TWO
408 }
409 fclose(file);
410 }
411#endif /* PS_ADDITIONAL_COLUMNS */
376#if 0 /* PSSCAN_CMD is not used */ 412#if 0 /* PSSCAN_CMD is not used */
377 if (flags & (PSSCAN_CMD|PSSCAN_ARGV0)) { 413 if (flags & (PSSCAN_CMD|PSSCAN_ARGV0)) {
378 free(sp->argv0); 414 free(sp->argv0);