shithub: riscv

Download patch

ref: daccd2b226ff71c251931103403a982d2796061a
parent: ba20914d0158f7d5551785b1382efeaae98919cb
author: cinap_lenrek <[email protected]>
date: Sat Dec 19 10:52:41 EST 2020

aux/kbdfs: use getuser() from libc

--- a/sys/src/cmd/aux/kbdfs/kbdfs.c
+++ b/sys/src/cmd/aux/kbdfs/kbdfs.c
@@ -104,6 +104,7 @@
 int quiet = 0;
 char *sname = nil;
 char *mntpt = "/dev";
+char *user;
 
 int debug;
 
@@ -1249,36 +1250,14 @@
  * Filesystem
  */
 
-static char*
-getauser(void)
-{
-	static char user[64];
-	int fd;
-	int n;
-
-	if(*user)
-		return user;
-	if((fd = open("/dev/user", OREAD)) < 0)
-		strcpy(user, "none");
-	else {
-		n = read(fd, user, (sizeof user)-1);
-		close(fd);
-		if(n < 0)
-			strcpy(user, "none");
-		else
-			user[n] = 0;
-	}
-	return user;
-}
-
 static int
 fillstat(ulong qid, Dir *d)
 {
+	static char *user;
 	struct Qtab *t;
 
 	memset(d, 0, sizeof *d);
-	d->uid = getauser();
-	d->gid = getauser();
+	d->uid = d->gid = user;
 	d->muid = "";
 	d->qid = (Qid){qid, 0, 0};
 	d->atime = time(0);
@@ -1639,6 +1618,7 @@
 	kbdchan = chancreate(sizeof(char*), 128);
 	intchan = chancreate(sizeof(int), 0);
 
+	user = getuser();
 	threadpostmountsrv(&fs, sname, mntpt, MBEFORE);
 	threadexits(0);
 }