Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 78e08066 authored by Christopher Ferris's avatar Christopher Ferris
Browse files

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
parent 53529eca
Loading
Loading
Loading
Loading
+11 −5
Original line number Diff line number Diff line
@@ -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);