remove old files on build; fix fsread() a little bit; add options for different service models
This commit is contained in:
parent
9d81d9d6ab
commit
ed686913d2
2 changed files with 36 additions and 14 deletions
1
build.sh
1
build.sh
|
@ -2,5 +2,6 @@
|
||||||
|
|
||||||
clang-format -i ./*.c
|
clang-format -i ./*.c
|
||||||
|
|
||||||
|
mk clean
|
||||||
mk o.xrxs
|
mk o.xrxs
|
||||||
mv o.xrxs xrxs
|
mv o.xrxs xrxs
|
||||||
|
|
49
xrxs.c
49
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 */
|
/* clang-format on */
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
void fsread(Req* r) {
|
void fsread(Req* r) {
|
||||||
static int i = 0;
|
char numReads[32];
|
||||||
char numReads[16];
|
i++;
|
||||||
i = i + 1;
|
sprintf(numReads, "Hello from 9p!\n%d reads\n", i);
|
||||||
sprintf(numReads, "%d reads\n", i);
|
|
||||||
readstr(r, "Hello from 9P!\n");
|
|
||||||
readstr(r, numReads);
|
readstr(r, numReads);
|
||||||
respond(r, nil);
|
respond(r, nil);
|
||||||
}
|
}
|
||||||
|
@ -36,21 +36,42 @@ Srv fs = {
|
||||||
.read = fsread,
|
.read = fsread,
|
||||||
};
|
};
|
||||||
|
|
||||||
void threadmain(int argc, char** argv) {
|
void threadmain(int argc, char* argv[]) {
|
||||||
Tree* tree;
|
Tree* tree;
|
||||||
char* mtpt = argv[1];
|
char* mtpt = nil;
|
||||||
|
char* usocket = nil;
|
||||||
|
int i;
|
||||||
|
|
||||||
if (argc < 1)
|
/* if -m PATH is supplied, mount on PATH */
|
||||||
sysfatal("supply a mountpoint");
|
/* 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);
|
tree = alloctree(nil, nil, DMDIR | 0555, nil);
|
||||||
fs.tree = tree;
|
fs.tree = tree;
|
||||||
fs.foreground = 1;
|
fs.foreground = 1;
|
||||||
createfile(tree->root, "hello", nil, 0555, nil);
|
createfile(tree->root, "hello", nil, 0555, nil);
|
||||||
|
|
||||||
if (mtpt && access(mtpt, AEXIST) < 0 && access(mtpt, AEXIST) < 0)
|
if (argc >= 3) {
|
||||||
sysfatal("mountpoint %s does not exist", mtpt);
|
if (mtpt != nil && access(mtpt, AEXIST) < 0 && access(mtpt, AEXIST) < 0)
|
||||||
|
sysfatal("mountpoint %s does not exist", mtpt);
|
||||||
|
|
||||||
threadpostmountsrv(&fs, nil, mtpt, MREPL | MCREATE);
|
threadpostmountsrv(&fs, usocket, mtpt, MREPL | MCREATE);
|
||||||
threadexits(0);
|
threadexits(0);
|
||||||
}
|
} else {
|
||||||
|
srv(&fs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue