remove old files on build; fix fsread() a little bit; add options for different service models
Iris Lightshard nilix@nilfm.cc
PGP Signature
-----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEkFh6dA+k/6CXFXU4O3+8IhROY5gFAmDHuqoACgkQO3+8IhRO Y5g8Zw//da5P9jhmN672zdD0R5YoAUrOaAjCq2hkTScMDKz349J3yciGfb3XD+ku K0J5jWqKgz6zoeE6K2GekNlttrTkumDOoNFywQWCfULH9KdwGEbZbI++lJD2EHrV 4uA5cUWAm9sYERJ5ey9EvlMAlV4TbU2iyN6xqKGMVUoqKmF4MN6wwN+F6NGckDzH RsZMG7sv/YjBi7tCHfjkX4ZjGczjuCIh95i36oAj9N41gvp2v4cILs0mll3bMeJr CZ05k7lYMcr5TDsHWaRrF5mRYa9mHuKlVCkZX5/kCvnRk3DPjacPvymN8BVfD0mj B6tNaIfB2Tpy1Sv4JgM+han3qkvAxcFo6xa4Qlc4e4Q+TaJmTZ49BrXifNwWNRyb 8Z3ZfZwPERCDyYFCFvS99er2myHW1Xafg24Yq7agBIKwj4lHiAlMEgROqsZH5dJJ dkpJ5Mf++3M5Lx8xHw8nGGV3R1XpcPfDRJ0nOpWOWQhzVGC/WBnbZv5C98Vb9RPq QBZkyUXY6WhUvb54pkCblJF0NmHiCQKDLAFe7SQNjy//HOCsSK8X6z7sbhMazpVI VGzCcMHTf/jh2WMNv8VnZ0MK0ktw+s94og4ynx4SeI6Fs3sKBTEnbEEinnr0d7hG ujfwtiHswMF/fvGCeBiEGGr3RNLsnPMnEsrSmxo7UAJilRFw/go= =L5GT -----END PGP SIGNATURE-----
M
xrxs.c
→
xrxs.c
@@ -22,12 +22,12 @@ char *ccat(char *dst, char c) { int len = slen(dst); dst[len] = c; dst[len + 1] = '\0'; return dst; }
/* 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 -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); + } + } + } - if (argc < 1) - sysfatal("supply a mountpoint"); + /* 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); + } +}