diff --git a/user/pctl/ls.c b/user/pctl/ls.c index 8664a7b..475e60d 100644 --- a/user/pctl/ls.c +++ b/user/pctl/ls.c @@ -7,6 +7,18 @@ #include #include #include +#include +#include "ls.h" +#include "macros.h" + +struct { + char *specificproc; +} PCTL_LS_CONFIG; + +static Arg ARGS[] = { + ARG("-proc", ARG_STRING, &PCTL_LS_CONFIG.specificproc), + ARG_END(), +}; const char *human_size(uint64_t bytes, char *buf, size_t bufsize) { static const char *units[] = { "B", "KiB", "MiB", "GiB", "TiB", "PiB" }; @@ -41,6 +53,12 @@ const char *human_size(uint64_t bytes, char *buf, size_t bufsize) { void pctl_ls(void) { + int32_t ret; + if ((ret = parse_args(SUBCMD_ARGS(), SUBCMD_ARGSLEN(), ARGS)) < 0) { + uprintf("pctl ls: Could not parse args: %d\n", ret); + return; + } + static const char *states[] = {"embryo", "ready", "zombie", "waiting", "died"}; uint64_t procslen = processctl(-1, PCTL_PLS_SZ, 0, 0, 0); @@ -57,6 +75,11 @@ void pctl_ls(void) { int32_t r = processctl(-1, PCTL_PLS_STAT, i, (uint64_t)&stat, 0); if (r == E_OK) { + if (PCTL_LS_CONFIG.specificproc != NULL + && string_strcmp(stat.name, PCTL_LS_CONFIG.specificproc) != 0) { + continue; + } + string_memcpy(namebuf, stat.name, 30); namebuf[31] = namebuf[32] = namebuf[33] = '.'; diff --git a/user/pctl/macros.h b/user/pctl/macros.h new file mode 100644 index 0000000..0dc7133 --- /dev/null +++ b/user/pctl/macros.h @@ -0,0 +1,7 @@ +#ifndef PCTL_MACROS_H_ +#define PCTL_MACROS_H_ + +#define SUBCMD_ARGS() (args()+1) +#define SUBCMD_ARGSLEN() (argslen()-1) + +#endif // PCTL_MACROS_H_