Date: Sun, 17 May 2015 03:50:43 +0000 (UTC) From: Mark Johnston <markj@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r283024 - head/cddl/contrib/opensolaris/lib/libdtrace/common Message-ID: <201505170350.t4H3ohGA002691@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
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); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201505170350.t4H3ohGA002691>