diff options
author | mirabilos <tg@mirbsd.org> | 2017-11-18 12:37:08 +0100 |
---|---|---|
committer | Waldemar Brodkorb <wbx@openadk.org> | 2017-11-19 09:09:27 +0100 |
commit | 69229e524cde4412eb111180f15e073cc00366d9 (patch) | |
tree | bbe1a9e2f1157ca23b233fcf2d73a8c1f229d4a6 /package/sash/src/cmd_uclinux.c | |
parent | d68e2217231db1a738374dbff846a5612be621a0 (diff) |
clean up sash
Signed-off-by: mirabilos <tg@mirbsd.org>
Diffstat (limited to 'package/sash/src/cmd_uclinux.c')
-rw-r--r-- | package/sash/src/cmd_uclinux.c | 41 |
1 files changed, 20 insertions, 21 deletions
diff --git a/package/sash/src/cmd_uclinux.c b/package/sash/src/cmd_uclinux.c index 32886ebe4..bca2152b9 100644 --- a/package/sash/src/cmd_uclinux.c +++ b/package/sash/src/cmd_uclinux.c @@ -1,4 +1,3 @@ - #include "sash.h" #include <fcntl.h> @@ -29,37 +28,37 @@ do_ps(argc, argv) DIR * d; struct dirent * de; int l; - + printf(" PID TTY STAT TIME COMMAND\n"); - - + + d = opendir("/proc"); if (!d) return; - + while (de = readdir(d)) { for(i=0;i<strlen(de->d_name);i++) if (!isdigit(de->d_name[i])) goto next; - + sprintf(psbuf, "/proc/%s/stat", de->d_name); h = open(psbuf, O_RDONLY); - + if (h==-1) continue; - + l = read(h, psbuf, 255); if (l<=0) { perror("Unable to read status"); close(h); continue; } - + psbuf[l] = '\0'; psbuf[255] = '\0'; - - - if (sscanf(psbuf, + + + if (sscanf(psbuf, "%d %s %c", &pid, name, &statec)<3) { @@ -67,34 +66,34 @@ do_ps(argc, argv) close(h); continue; } - + state = statec; - + close(h); - + sprintf(psbuf, "/proc/%s/cmdline", de->d_name); h = open(psbuf, O_RDONLY); - + if (h == -1) { perror("Unable to open cmdline"); continue; } - + l = read(h, psbuf, 255); if (l < 0) { perror("Unable to read cmdline"); close(h); continue; } - + close(h); - + psbuf[255] = psbuf[l] = '\0'; - + printf("%5d %3s %c --:-- %s\n", pid, "", state, psbuf); next: } - + closedir(d); } #endif |