ref: 041d05f3113a8c3b9e4dcc9893fa228c88c1d3a5
parent: 1a4dd4a79798cd6acd9050f7ce5a05df84669b50
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Sun Dec 22 16:05:05 EST 2019
add options to 9pex
--- a/9pex.c
+++ b/9pex.c
@@ -16,6 +16,7 @@
#include <sys/time.h>
#include <unistd.h>
#include "c9.h"
+#include "parg.h"
#define max(a,b) ((a)>(b)?(a):(b))
#define used(x) ((void)(x))
@@ -81,7 +82,7 @@
static int in, out, eof;
static C9ctx ctx;
-static int debug = 1;
+static int debug;
static Fid **fids;
static int numfids;
static Tag **tags;
@@ -627,7 +628,7 @@
trace(" afid=%d fid=%d uname=\"%s\" aname=\"%s\"\n", t->attach.afid, t->fid, t->attach.uname, t->attach.aname);
if (t->attach.afid != C9nofid) {
err = Eunknownfid;
- } else if ((f = newfid(t->fid, ".", &err)) != NULL) {
+ } else if ((f = newfid(t->fid, rootpath, &err)) != NULL) {
f->name = "/";
if (s9do(s9attach(c, t->tag, &f->qid), &err) == 0)
trace("<- Rattach\n");
@@ -710,14 +711,50 @@
int
main(int argc, char **argv)
{
- Fid *f;
- int can, i;
+ const char *dir;
char *err;
+ Fid *f;
+ struct parg_state ps;
+ int can, i, c;
- used(argc); used(argv);
+ parg_init(&ps);
- if ((rootpath = realpath(".", NULL)) == NULL) {
- trace("root: %s\n", strerror(errno));
+ debug = 0;
+ dir = NULL;
+ while ((c = parg_getopt(&ps, argc, argv, "dh")) >= 0) {
+ switch (c) {
+ case 1:
+ if (dir != NULL) {
+ fprintf(stderr, "only one dir can be specified\n");
+ return 1;
+ }
+ dir = ps.optarg;
+ break;
+ case 'd':
+ debug++;
+ break;
+ case 'h':
+ fprintf(stderr, "usage: 9pex [-d] DIR\n");
+ return 0;
+ break;
+ case '?':
+ fprintf(stderr, "unknown option -%c\n", ps.optopt);
+ return 1;
+ break;
+ default:
+ fprintf(stderr, "unhandled option -%c\n", c);
+ return 1;
+ break;
+ }
+ }
+
+ if (dir == NULL) {
+ fprintf(stderr, "no dir specified\n");
+ return 1;
+ }
+
+ if ((rootpath = realpath(dir, NULL)) == NULL) {
+ trace("%s: %s\n", dir, strerror(errno));
return 1;
}
rootlen = strlen(rootpath);
--- a/README.md
+++ b/README.md
@@ -2,7 +2,7 @@
Plan9-related tools for Unix-like operating systems.
- * 9pex - share current directory over stdin/stdout, can be used with socat/inetd
+ * 9pex - share a directory over stdin/stdout, can be used with socat/inetd
This is all _WIP_ still. 9pex is working in read-only mode so far but
lacks proper auth, async IO, some more error control etc.
--- a/build.sh
+++ b/build.sh
@@ -1,2 +1,2 @@
#!/bin/sh
-gcc -DC9_NO_CLIENT -lrt -O -ggdb -Wall -Wextra -Wshadow -Wpedantic -Werror c9/*.c -Ic9 9pex.c -o 9pex
+gcc -DC9_NO_CLIENT -lrt -O -ggdb -Wall -Wextra -Wshadow -Wpedantic -Werror c9/*.c parg/*.c -Ic9 -Iparg 9pex.c -o 9pex