shithub: 9pro

Download patch

ref: 15a990218c5f519ce071c0ffb8956e9ec4cf5ab3
parent: 5c310b8ad0f9072852e6f08e075eb25cefefdccd
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Sun Dec 22 14:49:38 EST 2019

minor fixes

--- a/9pex.c
+++ b/9pex.c
@@ -1,20 +1,20 @@
 #define _FILE_OFFSET_BITS 64
-#include <errno.h>
-#include <stdio.h>
-#include <stdint.h>
 #include <dirent.h>
+#include <errno.h>
 #include <fcntl.h>
-#include <aio.h>
+#include <grp.h>
+#include <inttypes.h>
+#include <pwd.h>
 #include <signal.h>
 #include <stdarg.h>
-#include <string.h>
+#include <stdint.h>
+#include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
+#include <sys/select.h>
 #include <sys/stat.h>
 #include <sys/time.h>
-#include <sys/select.h>
 #include <unistd.h>
-#include <pwd.h>
-#include <grp.h>
 #include "c9.h"
 
 #define max(a,b) ((a)>(b)?(a):(b))
@@ -49,19 +49,19 @@
 }Tag;
 
 static char *t2s[] = {
-	[Tversion-Tversion] "Tversion",
-	[Tauth-Tversion]    "Tauth",
-	[Tattach-Tversion]  "Tattach",
-	[Tflush-Tversion]   "Tflush",
-	[Twalk-Tversion]    "Twalk",
-	[Topen-Tversion]    "Topen",
-	[Tcreate-Tversion]  "Tcreate",
-	[Tread-Tversion]    "Tread",
-	[Twrite-Tversion]   "Twrite",
-	[Tclunk-Tversion]   "Tclunk",
-	[Tremove-Tversion]  "Tremove",
-	[Tstat-Tversion]    "Tstat",
-	[Twstat-Tversion]   "Twstat",
+	[Tversion-Tversion] = "Tversion",
+	[Tauth-Tversion] = "Tauth",
+	[Tattach-Tversion] = "Tattach",
+	[Tflush-Tversion] = "Tflush",
+	[Twalk-Tversion] = "Twalk",
+	[Topen-Tversion] = "Topen",
+	[Tcreate-Tversion] = "Tcreate",
+	[Tread-Tversion] = "Tread",
+	[Twrite-Tversion] = "Twrite",
+	[Tclunk-Tversion] = "Tclunk",
+	[Tremove-Tversion] = "Tremove",
+	[Tstat-Tversion] = "Tstat",
+	[Twstat-Tversion] = "Twstat",
 };
 
 static char *Enoauth = "authentication not required";
@@ -93,6 +93,7 @@
 static uint8_t *wrbuf;
 static int wroff;
 
+__attribute__ ((format (printf, 1, 2)))
 static void
 trace(const char *fmt, ...)
 {
@@ -403,26 +404,26 @@
 }
 
 static int
-stat2c9stat(char *name, struct stat *st, C9stat *out, char **err)
+stat2c9stat(char *name, struct stat *st, C9stat *stout, char **err)
 {
 	int fmt;
 
-	memset(out, 0, sizeof(*out));
-	out->size = st->st_size;
-	stat2qid(st, &out->qid, NULL);
-	out->name = name;
-	out->atime = st->st_atime;
-	out->mtime = st->st_ctime;
+	memset(stout, 0, sizeof(*stout));
+	stout->size = st->st_size;
+	stat2qid(st, &stout->qid, NULL);
+	stout->name = name;
+	stout->atime = st->st_atime;
+	stout->mtime = st->st_ctime;
 
 	fmt = st->st_mode & S_IFMT;
 	if (fmt == S_IFDIR)
-		out->mode |= C9stdir;
+		stout->mode |= C9stdir;
 	if (fmt == S_IFCHR || fmt == S_IFCHR || fmt == S_IFSOCK || fmt == S_IFIFO)
-		out->mode |= C9stappend;
-	out->mode |= st->st_mode & 0x1ff;
-	if ((out->uid = uid2str(st->st_uid, err)) == NULL)
+		stout->mode |= C9stappend;
+	stout->mode |= st->st_mode & 0x1ff;
+	if ((stout->uid = uid2str(st->st_uid, err)) == NULL)
 		return -1;
-	if ((out->gid = gid2str(st->st_gid, err)) == NULL)
+	if ((stout->gid = gid2str(st->st_gid, err)) == NULL)
 		return -1;
 
 	return 0;
@@ -429,7 +430,7 @@
 }
 
 static int
-statfid(Fid *f, C9stat *out, char **err)
+statfid(Fid *f, C9stat *stout, char **err)
 {
 	struct stat st;
 	int r;
@@ -443,7 +444,7 @@
 		return -1;
 	}
 
-	return stat2c9stat(f->name, &st, out, err);
+	return stat2c9stat(f->name, &st, stout, err);
 }
 
 static uint8_t *
@@ -488,6 +489,18 @@
 	return 0;
 }
 
+__attribute__ ((format (printf, 1, 2)))
+static void
+ctxerror(const char *fmt, ...)
+{
+	va_list ap;
+
+	va_start(ap, fmt);
+	vfprintf(stderr, fmt, ap);
+	fprintf(stderr, "\n");
+	va_end(ap);
+}
+
 static int
 s9do(C9error e, char **err)
 {
@@ -537,7 +550,7 @@
 		}
 		if (s9do(s9read(c, tag, p, n), err) != 0)
 			return -1;
-		trace("<- Rread tag=%d count=%d ...\n", tag, n);
+		trace("<- Rread tag=%d count=%zd ...\n", tag, n);
 		return 0;
 	}
 
@@ -590,7 +603,7 @@
 {
 	Fid *f;
 	C9qid *qids[C9maxpathel+1];
-	char *err;
+	char *err, *err2;
 	C9stat st;
 	int i;
 
@@ -653,7 +666,7 @@
 			err = Enocreate;
 			break;
 		case Tread:
-			trace(" fid=%d offset=%lld count=%d\n", t->fid, t->read.offset, t->read.size);
+			trace(" fid=%d offset=%"PRIu64" count=%"PRIu32"\n", t->fid, t->read.offset, t->read.size);
 			if ((f = findfid(t->fid, &err)) != NULL) {
 				if ((f->dir == NULL && f->fd < 0) || (f->mode & 0xf) == C9write)
 					err = Ebotch;
@@ -687,10 +700,10 @@
 	}
 
 	if (err != NULL) {
-		if (s9error(c, t->tag, err) == 0)
+		if (s9do(s9error(c, t->tag, err), &err2) == 0)
 			trace("<- Rerror tag=%d \"%s\"\n", t->tag, err);
 		else
-			trace("failed to send an error response\n");
+			trace("s9error: %s\n", err2);
 	}
 }
 
@@ -699,6 +712,7 @@
 {
 	Fid *f;
 	int can, i;
+	char *err;
 
 	used(argc); used(argv);
 
@@ -722,18 +736,22 @@
 	ctx.begin = ctxbegin;
 	ctx.end = ctxend;
 	ctx.t = ctxt;
-	ctx.error = trace;
+	ctx.error = ctxerror;
 
 	rdbuf = calloc(1, ctx.msize);
 	wrbuf = calloc(1, ctx.msize);
 	wroff = 0;
 
+	err = NULL;
 	for (; !eof;) {
 		if ((can = canrw(1)) < 0)
 			break;
-		if ((can & Canrd) != 0 && s9proc(&ctx) != 0)
+		if ((can & Canrd) != 0 && s9do(s9proc(&ctx), &err) != 0)
 			break;
 	}
+
+	if (err != NULL)
+		trace("s9proc: %s\n", err);
 
 	for (i = 0; i < numfids; i++) {
 		if ((f = fids[i]) != NULL) {
--- a/build.sh
+++ b/build.sh
@@ -1,2 +1,2 @@
 #!/bin/sh
-gcc -DC9_NO_CLIENT -lrt -O -ggdb -Wall -Wextra -Werror c9/*.c -Ic9 9pex.c -o 9pex
+gcc -DC9_NO_CLIENT -lrt -O -ggdb -Wall -Wextra -Wshadow -Wpedantic -Werror c9/*.c -Ic9 9pex.c -o 9pex