I think it's best to just check the parent directories first and
then create the temp name.

 - todd

Index: server.c
===================================================================
RCS file: /cvs/src/usr.bin/rdistd/server.c,v
retrieving revision 1.40
diff -u -p -u -r1.40 server.c
--- server.c    22 Dec 2015 08:48:39 -0000      1.40
+++ server.c    28 Mar 2016 02:01:32 -0000
@@ -750,12 +750,9 @@ recvfile(char *new, opt_t opts, int mode
        /*
         * Create temporary file
         */
-       if ((f = mkstemp(new)) < 0) {
-               if (errno != ENOENT || chkparent(new, opts) < 0 ||
-                   (f = mkstemp(new)) < 0) {
-                       error("%s: create failed: %s", new, SYSERR);
-                       return;
-               }
+       if (chkparent(new, opts) < 0 || (f = mkstemp(new)) < 0) {
+               error("%s: create failed: %s", new, SYSERR);
+               return;
        }
 
        /*
@@ -1161,13 +1158,10 @@ recvlink(char *new, opt_t opts, int mode
        /*
         * Make new symlink using a temporary name
         */
-       if (mktemp(new) == NULL || symlink(dbuf, new) < 0) {
-               if (errno != ENOENT || chkparent(new, opts) < 0 ||
-                   mktemp(new) == NULL || symlink(dbuf, new) < 0) {
-                       error("%s -> %s: symlink failed: %s", new, dbuf,
-                           SYSERR);
-                       return;
-               }
+       if (chkparent(new, opts) < 0 || mktemp(new) == NULL ||
+           symlink(dbuf, new) < 0) {
+               error("%s -> %s: symlink failed: %s", new, dbuf, SYSERR);
+               return;
        }
 
        /*

Reply via email to