shithub: riscv

Download patch

ref: f466d3894c7c83f2dbde773c5b886a18b57d799e
parent: ea64fd3ad52bd7ff34889fcfd435443a39ddd6d8
author: cinap_lenrek <[email protected]>
date: Wed Aug 8 15:03:10 EDT 2012

ndb/dns: cleanup

--- a/sys/src/cmd/ndb/dns.c
+++ b/sys/src/cmd/ndb/dns.c
@@ -274,7 +274,17 @@
 	char buf[32];
 
 	if(pipe(p) < 0)
-		abort(); /* "pipe failed" */;
+		sysfatal("pipe failed: %r");
+
+	/*
+	 *  make a /srv/dns
+	 */
+	if((f = create(service, OWRITE|ORCLOSE, 0666)) < 0)
+		sysfatal("create %s failed: %r", service);
+	snprint(buf, sizeof buf, "%d", p[1]);
+	if(write(f, buf, strlen(buf)) != strlen(buf))
+		sysfatal("write %s failed: %r", service);
+
 	/* copy namespace to avoid a deadlock */
 	switch(rfork(RFFDG|RFPROC|RFNAMEG)){
 	case 0:			/* child: hang around and (re)start main proc */
@@ -282,20 +292,9 @@
 		procsetname("%s restarter", mntpt);
 		break;
 	case -1:
-		abort(); /* "fork failed\n" */;
+		sysfatal("fork failed: %r");
 	default:		/* parent: make /srv/dns, mount it, exit */
 		close(p[0]);
-
-		/*
-		 *  make a /srv/dns
-		 */
-		f = create(service, 1, 0666);
-		if(f < 0)
-			abort(); /* service */;
-		snprint(buf, sizeof buf, "%d", p[1]);
-		if(write(f, buf, strlen(buf)) != strlen(buf))
-			abort(); /* "write %s", service */;
-		close(f);
 
 		/*
 		 *  put ourselves into the file system
--- a/sys/src/cmd/ndb/dnudpserver.c
+++ b/sys/src/cmd/ndb/dnudpserver.c
@@ -288,8 +288,12 @@
 	}
 
 	/* turn on header style interface */
-	if(write(ctl, hmsg, strlen(hmsg)) != strlen(hmsg))
-		abort();			/* hmsg */
+	if(write(ctl, hmsg, strlen(hmsg)) != strlen(hmsg)){
+		close(ctl);
+		if(!whined++)
+			warning("can't enable headers on %s", datafile);
+		return -1;
+	}
 
 	snprint(datafile, sizeof(datafile), "%s/data", dir);
 	data = open(datafile, ORDWR);