remove old files on build; fix fsread() a little bit; add options for different service models

This commit is contained in:
Iris Lightshard 2021-06-14 14:23:06 -06:00
parent 9d81d9d6ab
commit ed686913d2
Signed by: Iris Lightshard
GPG key ID: 3B7FBC22144E6398
2 changed files with 36 additions and 14 deletions

View file

@ -2,5 +2,6 @@
clang-format -i ./*.c
mk clean
mk o.xrxs
mv o.xrxs xrxs

49
xrxs.c
View file

@ -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);
}
threadpostmountsrv(&fs, usocket, mtpt, MREPL | MCREATE);
threadexits(0);
} else {
srv(&fs);
}
}