From 2f99fb162fd35c94e5a939f04bde99e93ad2148a Mon Sep 17 00:00:00 2001 From: Giacomo Tesio Date: Thu, 2 Nov 2017 22:52:48 +0100 Subject: [PATCH] hmi/console: fix file owner for screenconsole When boot starts screenconsole, the hostowner is still empty --- sys/src/cmd/hmi/console/console.h | 2 +- sys/src/cmd/hmi/console/serve9p.c | 30 ++++++++++++++++++++++++------ sys/src/cmd/hmi/console/utils.c | 28 +--------------------------- 3 files changed, 26 insertions(+), 34 deletions(-) diff --git a/sys/src/cmd/hmi/console/console.h b/sys/src/cmd/hmi/console/console.h index 80ca8ab..305c914 100644 --- a/sys/src/cmd/hmi/console/console.h +++ b/sys/src/cmd/hmi/console/console.h @@ -65,7 +65,7 @@ extern void post(char *srv, int fd); extern int fsinit(int *, int *); -extern void fsserve(int, char*); +extern void fsserve(int); extern void passthrough(int, int); diff --git a/sys/src/cmd/hmi/console/serve9p.c b/sys/src/cmd/hmi/console/serve9p.c index 888b062..1a41b61 100644 --- a/sys/src/cmd/hmi/console/serve9p.c +++ b/sys/src/cmd/hmi/console/serve9p.c @@ -41,7 +41,6 @@ static Status status; static int rawmode; static int fspid; -static char *filesowner; static void *data; enum { @@ -533,10 +532,33 @@ invalidioreq(Fcall *req) return "bad read/write count"; return nil; } +static char* +gethostowner(void) +{ + int f, r; + char *res; + + res = (char*)malloc(256); + if(res == nil) + sysfatal("out of memory"); + f = open("#c/hostowner", OREAD); + if(f < 0) + sysfatal("open(#c/hostowner) %r"); + r = read(f, res, 255); + if(r < 0) + sysfatal("read(#c/hostowner)"); + res[r] = '\0'; + close(f); + return res; +} static int fillstat(uint64_t path, Dir *d) { struct Qtab *t; + static char *filesowner; + + if(filesowner == nil) + filesowner = gethostowner(); memset(d, 0, sizeof(Dir)); d->uid = filesowner; @@ -987,16 +1009,12 @@ fsinit(int *mnt, int *mntdev) } /* fsserve is the main loop */ void -fsserve(int connection, char *owner) +fsserve(int connection) { int r, w, syncrep; Fcall rep; Fcall *req; - if(owner == nil) - sysfatal("owner undefined"); - filesowner = strdup(owner); - fspid = getpid(); req = malloc(sizeof(Fcall)+Maxfdata); if(req == nil) diff --git a/sys/src/cmd/hmi/console/utils.c b/sys/src/cmd/hmi/console/utils.c index 624b074..0796257 100644 --- a/sys/src/cmd/hmi/console/utils.c +++ b/sys/src/cmd/hmi/console/utils.c @@ -85,24 +85,6 @@ debug(const char *fmt, ...) } /* process management */ -static char* -gethostowner(void) -{ - int f, r; - char *res; - - res = (char*)malloc(256); - if(res == nil) - sysfatal("out of memory"); - f = open("#c/hostowner", OREAD); - if(f < 0) - sysfatal("open(#c/hostowner) %r"); - r = read(f, res, 255); - if(r < 0) - sysfatal("read(#c/hostowner)"); - close(f); - return res; -} /* start the relevant services * * assumes that @@ -116,11 +98,6 @@ int servecons(StreamFilter inputFilter, StreamFilter outputFilter, int *devmnt) { int pid, input, output, fs, mnt; - char *s; - - s = gethostowner(); - if(s == nil) - sysfatal("cannot read hostowner"); pid = getpid(); @@ -142,18 +119,15 @@ servecons(StreamFilter inputFilter, StreamFilter outputFilter, int *devmnt) close(0); close(1); close(mnt); - s = strdup(s); PROVIDE(fs); rfork(RFREND); - fsserve(fs, s); + fsserve(fs); break; default: break; } WAIT_FOR(fs); - free(s); - s = nil; close(fs); /* start output device writer */