Compare commits
3 Commits
2c0d50a401
...
e01d8d5e1a
Author | SHA1 | Date | |
---|---|---|---|
e01d8d5e1a | |||
44b5aa305c | |||
c94ef4d990 |
@ -22,6 +22,10 @@ int32_t parse_args(char **argv, size_t argc, Arg *defs) {
|
||||
case ARG_BOOL:
|
||||
*((bool *)def->ptr) = string_strcmp(argv[i+1], "yes") == 0;
|
||||
break;
|
||||
case ARG_INT: {
|
||||
char *end;
|
||||
*((int32_t *)def->ptr) = string_conv_strtol(argv[i+1], &end, 10);
|
||||
} break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
@ -10,7 +10,11 @@ size_t argslen(void);
|
||||
|
||||
typedef struct {
|
||||
char *shortname;
|
||||
enum { ARG_STRING, ARG_BOOL } expected_value;
|
||||
enum {
|
||||
ARG_STRING,
|
||||
ARG_BOOL,
|
||||
ARG_INT,
|
||||
} expected_value;
|
||||
void *ptr;
|
||||
bool end;
|
||||
} Arg;
|
||||
|
@ -7,6 +7,23 @@
|
||||
#include <uprintf.h>
|
||||
#include <string/string.h>
|
||||
#include <dlmalloc/malloc.h>
|
||||
#include <args/args.h>
|
||||
#include "ls.h"
|
||||
#include "macros.h"
|
||||
|
||||
struct {
|
||||
char *specificproc;
|
||||
int32_t pid;
|
||||
} PCTL_LS_CONFIG = {
|
||||
.specificproc = NULL,
|
||||
.pid = -1,
|
||||
};
|
||||
|
||||
static Arg ARGS[] = {
|
||||
ARG("-proc", ARG_STRING, &PCTL_LS_CONFIG.specificproc),
|
||||
ARG("-pid", ARG_INT, &PCTL_LS_CONFIG.pid),
|
||||
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 +58,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 +80,15 @@ 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;
|
||||
}
|
||||
|
||||
if (PCTL_LS_CONFIG.pid != -1 && stat.pid != PCTL_LS_CONFIG.pid) {
|
||||
continue;
|
||||
}
|
||||
|
||||
string_memcpy(namebuf, stat.name, 30);
|
||||
namebuf[31] = namebuf[32] = namebuf[33] = '.';
|
||||
|
||||
|
7
user/pctl/macros.h
Normal file
7
user/pctl/macros.h
Normal file
@ -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_
|
Reference in New Issue
Block a user