summaryrefslogtreecommitdiff
path: root/src/cmd
diff options
context:
space:
mode:
authordzwdz2023-08-31 01:06:41 +0200
committerdzwdz2023-08-31 01:06:41 +0200
commit6cbe58797781cb8514a62bb3ab0e3e8a5d58bce2 (patch)
treebc405a3bc28dce58f1a7141640a5e0605363224c /src/cmd
parentcf7877737ff5032f8bad59d57b048f66c4813b5b (diff)
kernel: add _sys_getprocfs in place of HANDLE_PROCFS
This makes the side-effects more explicit, and feels less hacky than `HANDLE_PROCFS`. I don't think accessing a handle alone should have side-effects, even if it's a "special" one.
Diffstat (limited to 'src/cmd')
-rw-r--r--src/cmd/ps/ps.c18
-rw-r--r--src/cmd/shell/shell.c3
2 files changed, 16 insertions, 5 deletions
diff --git a/src/cmd/ps/ps.c b/src/cmd/ps/ps.c
index 76a5841..a4b2e4c 100644
--- a/src/cmd/ps/ps.c
+++ b/src/cmd/ps/ps.c
@@ -5,14 +5,24 @@
#include <stdlib.h>
#include <string.h>
+void
+usage(void)
+{
+ fprintf(stderr, "usage: ps [path]\n");
+ exit(1);
+}
+
int
-main(void)
+main(int argc, const char *argv[])
{
+ const char *path = argc >= 2 ? argv[1] : "/proc/";
+ if (argc > 2) usage();
+
char *readbuf = malloc(4096);
char *procbuf = malloc(4096);
- FILE *f = fopen("/proc/", "r");
+ FILE *f = fopen(path, "r");
if (!f) {
- err(1, "couldn't open /proc/");
+ err(1, "couldn't open %s", path);
}
// TODO library for iterating over directories
@@ -27,7 +37,7 @@ main(void)
size_t entryl = end - (readbuf+pos) + 1;
if (isdigit(readbuf[pos])) {
FILE *g;
- sprintf(procbuf, "/proc/%smem", readbuf+pos);
+ sprintf(procbuf, "%s%smem", path, readbuf+pos);
g = fopen(procbuf, "r");
if (!g) {
warn("couldn't open \"%s\"", procbuf);
diff --git a/src/cmd/shell/shell.c b/src/cmd/shell/shell.c
index df239eb..3f33756 100644
--- a/src/cmd/shell/shell.c
+++ b/src/cmd/shell/shell.c
@@ -1,5 +1,6 @@
#include "builtins.h"
#include "shell.h"
+#include <camellia.h>
#include <camellia/compat.h>
#include <camellia/flags.h>
#include <camellia/syscalls.h>
@@ -61,7 +62,7 @@ void run_args(int argc, char **argv, struct redir *redir) {
fprintf(stderr, "procmnt: missing mountpoint\n");
return;
}
- _sys_mount(HANDLE_PROCFS, argv[1], strlen(argv[1]));
+ camellia_procfs(argv[1]);
/*
if (!(3 <= argc && !strcmp(argv[2], "raw"))) {
if (!mount_at("/")) {