Author: markj
Date: Sun May 17 03:50:42 2015
New Revision: 283024
URL: https://svnweb.freebsd.org/changeset/base/283024

Log:
  When in lazyload mode, write the DOF to a temporary file and rename it
  rather than writing directly to the output file.
  
  CID:  1147172

Modified:
  head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_link.c

Modified: head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_link.c
==============================================================================
--- head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_link.c        Sun May 
17 00:55:44 2015        (r283023)
+++ head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_link.c        Sun May 
17 03:50:42 2015        (r283024)
@@ -1785,17 +1785,11 @@ dtrace_program_link(dtrace_hdl_t *dtp, d
                    "failed to open %s: %s", file, strerror(errno)));
        }
 #else
-       if (dtp->dt_lazyload) {
-               if ((fd = open(file, O_RDWR | O_CREAT | O_TRUNC, 0666)) < 0)
-                       return (dt_link_error(dtp, NULL, -1, NULL,
-                           "failed to open %s: %s", file, strerror(errno)));
-       } else {
-               snprintf(tfile, sizeof(tfile), "%s.XXXXXX", file);
-               if ((fd = mkstemp(tfile)) == -1)
-                       return (dt_link_error(dtp, NULL, -1, NULL,
-                           "failed to create temporary file %s: %s",
-                           tfile, strerror(errno)));
-       }
+       snprintf(tfile, sizeof(tfile), "%s.XXXXXX", file);
+       if ((fd = mkostemp(tfile, O_CLOEXEC)) == -1)
+               return (dt_link_error(dtp, NULL, -1, NULL,
+                   "failed to create temporary file %s: %s",
+                   tfile, strerror(errno)));
 #endif
 
        /*
@@ -1951,14 +1945,23 @@ dtrace_program_link(dtrace_hdl_t *dtp, d
                }
 #endif
        } else {
+#ifdef __FreeBSD__
+               if (rename(tfile, file) != 0) {
+                       ret = dt_link_error(dtp, NULL, fd, NULL,
+                           "failed to rename %s to %s: %s", tfile, file,
+                           strerror(errno));
+                       goto done;
+               }
+#endif
                (void) close(fd);
        }
 
 done:
        dtrace_dof_destroy(dtp, dof);
 
-#ifndef illumos
-       unlink(tfile);
+#ifdef illumos
+       if (!dtp->dt_lazyload)
+               (void) unlink(tfile);
 #endif
        return (ret);
 }
_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "[email protected]"

Reply via email to