diff options
author | Ingo Schwarze <schwarze@openbsd.org> | 2017-08-26 12:59:17 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@openbsd.org> | 2017-08-26 12:59:17 +0000 |
commit | e154b36d2bbda0660363039b44e8e0881cdf18fa (patch) | |
tree | 8756759c97c02b5b1d0f01c05999c447d64905bd | |
parent | c4b90a5dcc35ed7ec424e14554c34bddee7f4728 (diff) | |
download | mandoc-e154b36d2bbda0660363039b44e8e0881cdf18fa.tar.gz |
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@.
-rw-r--r-- | mandocdb.c | 23 |
1 files changed, 3 insertions, 20 deletions
@@ -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 |