diff options
author | Christopher Ferris <cferris@google.com> | 2016-01-28 16:08:08 -0800 |
---|---|---|
committer | Christopher Ferris <cferris@google.com> | 2016-01-28 16:08:08 -0800 |
commit | 78e08066f272c2adb41a1c80a7d566bd8b31d607 (patch) | |
tree | d9eeccc91db1fa79b3ee4fd5dce34caa5096f9be /toolbox | |
parent | 53529ecacdffbbffb5c9fbc4ab38103703dde32e (diff) | |
download | system_core-78e08066f272c2adb41a1c80a7d566bd8b31d607.tar.gz system_core-78e08066f272c2adb41a1c80a7d566bd8b31d607.tar.bz2 system_core-78e08066f272c2adb41a1c80a7d566bd8b31d607.zip |
Always have ps output to stdout at least one line.
There is at least one app that assumes that you will always get at least
one line of output in stdout from ps.
To fix this, move error output to stdout, and move the check of whether
/proc can be opened until after the ps header is printed.
Bug: 26554285
Change-Id: I6d9342aafd5c6f728735507cdd87a48a8e0373ac
Diffstat (limited to 'toolbox')
-rw-r--r-- | toolbox/ps.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/toolbox/ps.c b/toolbox/ps.c index ecc1c9f81..7e70c71c0 100644 --- a/toolbox/ps.c +++ b/toolbox/ps.c @@ -264,9 +264,6 @@ int ps_main(int argc, char **argv) int pidfilter = 0; int threads = 0; - d = opendir("/proc"); - if(d == 0) return -1; - while(argc > 1){ if(!strcmp(argv[1],"-t")) { threads = 1; @@ -287,7 +284,10 @@ int ps_main(int argc, char **argv) } else if(!strcmp(argv[1],"--ppid")) { ppid_filter = atoi(argv[2]); if (ppid_filter == 0) { - fprintf(stderr, "bad ppid '%s'\n", argv[2]); + /* Bug 26554285: Use printf because some apps require at least + * one line of output to stdout even for errors. + */ + printf("bad ppid '%s'\n", argv[2]); return 1; } argc--; @@ -295,7 +295,10 @@ int ps_main(int argc, char **argv) } else { pidfilter = atoi(argv[1]); if (pidfilter == 0) { - fprintf(stderr, "bad pid '%s'\n", argv[1]); + /* Bug 26554285: Use printf because some apps require at least + * one line of output to stdout even for errors. + */ + printf("bad pid '%s'\n", argv[1]); return 1; } } @@ -313,6 +316,9 @@ int ps_main(int argc, char **argv) (int) PC_WIDTH, "PC", (display_flags&SHOW_ABI)?"ABI " : ""); + d = opendir("/proc"); + if(d == 0) return -1; + while((de = readdir(d)) != 0){ if(isdigit(de->d_name[0])){ int pid = atoi(de->d_name); |