commit 74476aaabcc2c3e9eb5e05051de5a8814642f0cb
parent bef99226073b8ccaa3a7b200674081eebbbb04d6
Author: Pavel Renev <an2qzavok@gmail.com>
Date: Mon, 23 Aug 2021 20:47:50 +0000
-s srvname argument, some code rearranging, a threadsetname
Diffstat:
3 files changed, 41 insertions(+), 27 deletions(-)
diff --git a/fs.c b/fs.c
@@ -11,6 +11,34 @@
File *new, *ctl;
Object *newobj;
+void fs_open(Req *);
+void fs_read(Req *);
+void fs_write(Req *);
+void ftree_destroy(File *);
+
+Fsctl *
+initfs(char *srvname)
+{
+ Fsctl *fsctl;
+ static Srv srv = {
+ .open = fs_open,
+ .read = fs_read,
+ .write = fs_write,
+ };
+ newobj = nil;
+ fsctl = mallocz(sizeof(Fsctl), 1);
+ fsctl->c = chancreate(sizeof(int), 0);
+ srv.tree = alloctree("richterm", "richterm", DMDIR|0555, ftree_destroy);
+ if (srv.tree == nil) return nil;
+ fsctl->tree = srv.tree;
+ new = createfile(srv.tree->root, "new", "richterm", 0666, fsctl);
+ if (new == nil) return nil;
+ ctl = createfile(srv.tree->root, "ctl", "richterm", 0666, fsctl);
+ if (ctl == nil) return nil;
+ threadpostmountsrv(&srv, srvname, "/mnt/richterm", MREPL);
+ return fsctl;
+}
+
char *
ctlcmd(char *buf)
{
@@ -112,29 +140,6 @@ fs_write(Req *r)
} else respond(r, "fs_write: f->aux is nil");
}
-Fsctl *
-initfs(void)
-{
- Fsctl *fsctl;
- static Srv srv = {
- .open = fs_open,
- .read = fs_read,
- .write = fs_write,
- };
- newobj = nil;
- fsctl = mallocz(sizeof(Fsctl), 1);
- fsctl->c = chancreate(sizeof(int), 0);
- srv.tree = alloctree("richterm", "richterm", DMDIR|0555, ftree_destroy);
- if (srv.tree == nil) return nil;
- fsctl->tree = srv.tree;
- new = createfile(srv.tree->root, "new", "richterm", 0666, fsctl);
- if (new == nil) return nil;
- ctl = createfile(srv.tree->root, "ctl", "richterm", 0666, fsctl);
- if (ctl == nil) return nil;
- threadpostmountsrv(&srv, "richterm", "/mnt/richterm", MREPL);
- return fsctl;
-}
-
void
arrayread(Req *r, void *v)
{
diff --git a/richterm.c b/richterm.c
@@ -38,6 +38,8 @@ Fsctl *fsctl;
Array *fonts;
Image *Iscrollbar, *Ilink, *Inormbg, *Iselbg, *Itext;
+char *srvname;
+
char *mitems[] = {"paste", "snarf", "plumb", nil};
void (*mfunc[])(Rich *) = {mpaste, msnarf, mplumb, nil};
@@ -60,7 +62,7 @@ enum {
void
usage(void)
{
- fprint(2, "usage: %s [-D] [cmd]\n", argv0);
+ fprint(2, "usage: %s [-D] [-s srvname] [cmd [args]]\n", argv0);
exits("usage");
}
@@ -77,13 +79,16 @@ threadmain(int argc, char **argv)
case 'D':
chatty9p++;
break;
+ case 's':
+ srvname = EARGF(usage());
+ break;
default:
usage();
} ARGEND
mmode = MM_NONE;
- if (initdraw(0, 0, "richterm") < 0)
+ if (initdraw(0, 0, argv0) < 0)
sysfatal("%s: %r", argv0);
if ((mctl = initmouse(nil, screen)) == nil)
sysfatal("%s: %r", argv0);
@@ -126,6 +131,7 @@ threadmain(int argc, char **argv)
if(rfork(RFENVG) < 0)
sysfatal("rfork: %r");
+ quotefmtinstall();
atexit(shutdown);
pidchan = chancreate(sizeof(int), 0);
@@ -139,6 +145,9 @@ threadmain(int argc, char **argv)
{kctl->c, &kv, CHANRCV},
{nil, nil, CHANEND},
};
+
+ threadsetname("main");
+
for (;;) {
switch(alt(alts)) {
case MOUSE:
@@ -472,7 +481,7 @@ runcmd(void *args)
if ((dctl = initdevfs()) == nil)
sysfatal("initdevfs failed: %r");
- if ((fsctl = initfs()) == nil)
+ if ((fsctl = initfs(srvname)) == nil)
sysfatal("initfs failed: %r");
rfork(RFFDG);
diff --git a/richterm.h b/richterm.h
@@ -79,7 +79,7 @@ struct Fsctl {
extern Fsctl *fsctl;
-Fsctl * initfs(void);
+Fsctl * initfs(char *);
typedef struct Faux Faux;