From ed686913d24dd38bd8225bc3296f702e92305a26 Mon Sep 17 00:00:00 2001 From: Derek Stevens Date: Mon, 14 Jun 2021 14:23:06 -0600 Subject: [PATCH] remove old files on build; fix fsread() a little bit; add options for different service models --- build.sh | 1 + xrxs.c | 49 +++++++++++++++++++++++++++++++++++-------------- 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/build.sh b/build.sh index d7308df..84b6024 100755 --- a/build.sh +++ b/build.sh @@ -2,5 +2,6 @@ clang-format -i ./*.c +mk clean mk o.xrxs mv o.xrxs xrxs diff --git a/xrxs.c b/xrxs.c index eb01a61..7911c3a 100644 --- a/xrxs.c +++ b/xrxs.c @@ -22,12 +22,12 @@ char *ccat(char *dst, char c) { int len = slen(dst); dst[len] = c; dst[len + 1] /* clang-format on */ +int i = 0; + void fsread(Req* r) { - static int i = 0; - char numReads[16]; - i = i + 1; - sprintf(numReads, "%d reads\n", i); - readstr(r, "Hello from 9P!\n"); + char numReads[32]; + i++; + sprintf(numReads, "Hello from 9p!\n%d reads\n", i); readstr(r, numReads); respond(r, nil); } @@ -36,21 +36,42 @@ Srv fs = { .read = fsread, }; -void threadmain(int argc, char** argv) { +void threadmain(int argc, char* argv[]) { Tree* tree; - char* mtpt = argv[1]; + char* mtpt = nil; + char* usocket = nil; + int i; - if (argc < 1) - sysfatal("supply a mountpoint"); + /* if -m PATH is supplied, mount on PATH */ + /* if -s NAME is supplied, create a socket for the namespace */ + /* otherwise, just use srv() (for wrapping with socat or inetd) */ + + if (argc >= 3) { + for (i = 0; i < argc; i++) { + if (scmp(argv[i], "-m")) { + mtpt = argv[++i]; + printf("serving on %s", mtpt); + } else if (scmp(argv[i], "-s")) { + usocket = argv[++i]; + printf("serving socket namespace %s", usocket); + } + } + } + + /* create a single file called 'hello'. reading it calls fsread() */ tree = alloctree(nil, nil, DMDIR | 0555, nil); fs.tree = tree; fs.foreground = 1; createfile(tree->root, "hello", nil, 0555, nil); - if (mtpt && access(mtpt, AEXIST) < 0 && access(mtpt, AEXIST) < 0) - sysfatal("mountpoint %s does not exist", mtpt); + if (argc >= 3) { + if (mtpt != nil && access(mtpt, AEXIST) < 0 && access(mtpt, AEXIST) < 0) + sysfatal("mountpoint %s does not exist", mtpt); - threadpostmountsrv(&fs, nil, mtpt, MREPL | MCREATE); - threadexits(0); -} \ No newline at end of file + threadpostmountsrv(&fs, usocket, mtpt, MREPL | MCREATE); + threadexits(0); + } else { + srv(&fs); + } +}