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

Commit 5dc119a6 authored by Elliott Hughes's avatar Elliott Hughes
Browse files

Remove the name filtering from toolbox ps.

Regular ps doesn't have this, and at least in our tree everyone
seems to actually pipe to grep instead of using this anyway. But
since the switch to a more full-featured ps is going to be a nightmare
anyway, let's dip a toe in the water by removing something we don't plan
on supporting.

Change-Id: Id220ae0cfdad8368341730f643a2bfbaad3c9716
parent bb51fbc4
Loading
Loading
Loading
Loading
+57 −54
Original line number Diff line number Diff line
@@ -41,14 +41,14 @@ static int ppid_filter = 0;

static void print_exe_abi(int pid);

static int ps_line(int pid, int tid, char *namefilter)
static int ps_line(int pid, int tid)
{
    char statline[1024];
    char cmdline[1024];
    char macline[1024];
    char user[32];
    struct stat stats;
    int fd, r;
    int r;
    char *ptr, *name, *state;
    int ppid;
    unsigned rss, vss;
@@ -68,7 +68,7 @@ static int ps_line(int pid, int tid, char *namefilter)
        sprintf(statline, "/proc/%d/stat", pid);
        sprintf(cmdline, "/proc/%d/cmdline", pid);
        snprintf(macline, sizeof(macline), "/proc/%d/attr/current", pid);
        fd = open(cmdline, O_RDONLY);
        int fd = open(cmdline, O_RDONLY);
        if(fd == 0) {
            r = 0;
        } else {
@@ -79,7 +79,7 @@ static int ps_line(int pid, int tid, char *namefilter)
        cmdline[r] = 0;
    }

    fd = open(statline, O_RDONLY);
    int fd = open(statline, O_RDONLY);
    if(fd == 0) return -1;
    r = read(fd, statline, 1023);
    close(fd);
@@ -158,7 +158,6 @@ static int ps_line(int pid, int tid, char *namefilter)
        return 0;
    }

    if(!namefilter || !strncmp(cmdline[0] ? cmdline : name, namefilter, strlen(namefilter))) {
    if (display_flags & SHOW_MACLABEL) {
        fd = open(macline, O_RDONLY);
        strcpy(macline, "-");
@@ -187,7 +186,7 @@ static int ps_line(int pid, int tid, char *namefilter)
    char path[PATH_MAX];
    snprintf(path, sizeof(path), "/proc/%d/wchan", pid);
    char wchan[10];
        int fd = open(path, O_RDONLY);
    fd = open(path, O_RDONLY);
    ssize_t wchan_len = read(fd, wchan, sizeof(wchan));
    if (wchan_len == -1) {
        wchan[wchan_len = 0] = '\0';
@@ -202,7 +201,6 @@ static int ps_line(int pid, int tid, char *namefilter)
        printf(" (u:%d, s:%d)", utime, stime);

    printf("\n");
    }
    return 0;
}

@@ -240,7 +238,7 @@ static void print_exe_abi(int pid)
    }
}

void ps_threads(int pid, char *namefilter)
void ps_threads(int pid)
{
    char tmp[128];
    DIR *d;
@@ -254,7 +252,7 @@ void ps_threads(int pid, char *namefilter)
        if(isdigit(de->d_name[0])){
            int tid = atoi(de->d_name);
            if(tid == pid) continue;
            ps_line(pid, tid, namefilter);
            ps_line(pid, tid);
        }
    }
    closedir(d);
@@ -264,7 +262,6 @@ int ps_main(int argc, char **argv)
{
    DIR *d;
    struct dirent *de;
    char *namefilter = 0;
    int pidfilter = 0;
    int threads = 0;

@@ -290,12 +287,18 @@ int ps_main(int argc, char **argv)
            display_flags |= SHOW_ABI;
        } else if(!strcmp(argv[1],"--ppid")) {
            ppid_filter = atoi(argv[2]);
            if (ppid_filter == 0) {
                fprintf(stderr, "bad ppid '%s'\n", argv[2]);
                return 1;
            }
            argc--;
            argv++;
        } else if(isdigit(argv[1][0])){
            pidfilter = atoi(argv[1]);
        } else {
            namefilter = argv[1];
            pidfilter = atoi(argv[1]);
            if (pidfilter == 0) {
                fprintf(stderr, "bad pid '%s'\n", argv[1]);
                return 1;
            }
        }
        argc--;
        argv++;
@@ -315,8 +318,8 @@ int ps_main(int argc, char **argv)
        if(isdigit(de->d_name[0])){
            int pid = atoi(de->d_name);
            if(!pidfilter || (pidfilter == pid)) {
                ps_line(pid, 0, namefilter);
                if(threads) ps_threads(pid, namefilter);
                ps_line(pid, 0);
                if(threads) ps_threads(pid);
            }
        }
    }