source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mandoc: No need to fork and exec rm(1) -rf, we know that we have exactly
@ 2017-08-26 12:59 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2017-08-26 12:59 UTC (permalink / raw)
  To: source

Log Message:
-----------
No need to fork and exec rm(1) -rf, we know that we have exactly
one file and exactly one directory to remove.  While here, increase
the size of the buffer such that the file name actually fits.  
Minus 17 lines of code, no functional change.

Opportunity for simplification reported by George Brown <321 dot 
george at gmail dot com> on misc@.

Modified Files:
--------------
    mandoc:
        mandocdb.c

Revision Data
-------------
Index: mandocdb.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/mandocdb.c,v
retrieving revision 1.253
retrieving revision 1.254
diff -Lmandocdb.c -Lmandocdb.c -u -p -r1.253 -r1.254
--- mandocdb.c
+++ mandocdb.c
@@ -2119,7 +2119,7 @@ dbprune(struct dba *dba)
 static void
 dbwrite(struct dba *dba)
 {
-	char		 tfn[32];
+	char		 tfn[33];
 	int		 status;
 	pid_t		 child;
 
@@ -2193,26 +2193,9 @@ dbwrite(struct dba *dba)
 	}
 
 out:
+	unlink(tfn);
 	*strrchr(tfn, '/') = '\0';
-	switch (child = fork()) {
-	case -1:
-		exitcode = (int)MANDOCLEVEL_SYSERR;
-		say("", "&fork rm");
-		return;
-	case 0:
-		execlp("rm", "rm", "-rf", tfn, (char *)NULL);
-		say("", "&exec rm");
-		exit((int)MANDOCLEVEL_SYSERR);
-	default:
-		break;
-	}
-	if (waitpid(child, &status, 0) == -1) {
-		exitcode = (int)MANDOCLEVEL_SYSERR;
-		say("", "&wait rm");
-	} else if (WIFSIGNALED(status) || WEXITSTATUS(status)) {
-		exitcode = (int)MANDOCLEVEL_SYSERR;
-		say("", "%s: Cannot remove temporary directory", tfn);
-	}
+	rmdir(tfn);
 }
 
 static int
--
 To unsubscribe send an email to source+unsubscribe@mandoc.bsd.lv

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2017-08-26 12:59 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-26 12:59 mandoc: No need to fork and exec rm(1) -rf, we know that we have exactly schwarze

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).