shithub: riscv

Download patch

ref: c86a9608806b7d6bc95b68f1baa2e32451fd6ca8
parent: c924edb91ddb256ebe7a3654697494ac30eff8da
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Mon Dec 7 09:22:30 EST 2020

rio: simplify filsysinit() by using getuser(), format pid's as ulongs

--- a/sys/src/cmd/rio/fsys.c
+++ b/sys/src/cmd/rio/fsys.c
@@ -118,10 +118,9 @@
 Filsys*
 filsysinit(Channel *cxfidalloc)
 {
-	int n, fd, pid, p0;
+	int p0;
 	Filsys *fs;
 	Channel *c;
-	char buf[128];
 
 	fs = emalloc(sizeof(Filsys));
 	if(cexecpipe(&fs->cfd, &fs->sfd) < 0)
@@ -128,20 +127,11 @@
 		goto Rescue;
 	fmtinstall('F', fcallfmt);
 	clockfd = open("/dev/time", OREAD|OCEXEC);
-	fd = open("/dev/user", OREAD);
-	strcpy(buf, "Jean-Paul_Belmondo");
-	if(fd >= 0){
-		n = read(fd, buf, sizeof buf-1);
-		if(n > 0)
-			buf[n] = 0;
-		close(fd);
-	}
-	fs->user = estrdup(buf);
+	fs->user = getuser();
 	fs->csyncflush = chancreate(sizeof(int), 0);
 	if(fs->csyncflush == nil)
 		error("chancreate syncflush");
 	fs->cxfidalloc = cxfidalloc;
-	pid = getpid();
 
 	/*
 	 * Create and post wctl pipe
@@ -148,7 +138,7 @@
 	 */
 	if(cexecpipe(&p0, &wctlfd) < 0)
 		goto Rescue;
-	snprint(srvwctl, sizeof(srvwctl), "/srv/riowctl.%s.%d", fs->user, pid);
+	snprint(srvwctl, sizeof(srvwctl), "/srv/riowctl.%s.%lud", fs->user, (ulong)getpid());
 	post(srvwctl, "wctl", p0);
 	close(p0);
 
@@ -165,7 +155,7 @@
 	/*
 	 * Post srv pipe
 	 */
-	snprint(srvpipe, sizeof(srvpipe), "/srv/rio.%s.%d", fs->user, pid);
+	snprint(srvpipe, sizeof(srvpipe), "/srv/rio.%s.%lud", fs->user, (ulong)getpid());
 	post(srvpipe, "wsys", fs->cfd);
 
 	return fs;
@@ -234,7 +224,7 @@
 	char buf[32];
 
 	close(fs->sfd);	/* close server end so mount won't hang if exiting */
-	sprint(buf, "%d", id);
+	snprint(buf, sizeof buf, "%d", id);
 	if(mount(fs->cfd, -1, "/mnt/wsys", MREPL, buf) == -1){
 		fprint(2, "mount failed: %r\n");
 		return -1;