diff options
author | markj <markj@FreeBSD.org> | 2015-05-17 03:50:42 +0000 |
---|---|---|
committer | markj <markj@FreeBSD.org> | 2015-05-17 03:50:42 +0000 |
commit | 48547f12feb5b334a883310e8b56fc045ce292d8 (patch) | |
tree | fe8ee31006800fef636a557813bcb18def75491d /cddl/contrib/opensolaris/lib/libdtrace/common | |
parent | edcc51187304f54e79ae5136e8dfb9b152984b94 (diff) | |
download | FreeBSD-src-48547f12feb5b334a883310e8b56fc045ce292d8.zip FreeBSD-src-48547f12feb5b334a883310e8b56fc045ce292d8.tar.gz |
When in lazyload mode, write the DOF to a temporary file and rename it
rather than writing directly to the output file.
CID: 1147172
Diffstat (limited to 'cddl/contrib/opensolaris/lib/libdtrace/common')
-rw-r--r-- | cddl/contrib/opensolaris/lib/libdtrace/common/dt_link.c | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_link.c b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_link.c index eaf0961..af57e39 100644 --- a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_link.c +++ b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_link.c @@ -1785,17 +1785,11 @@ dtrace_program_link(dtrace_hdl_t *dtp, dtrace_prog_t *pgp, uint_t dflags, "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, dtrace_prog_t *pgp, uint_t dflags, } #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); } |