diff options
author | markj <markj@FreeBSD.org> | 2013-12-03 03:40:47 +0000 |
---|---|---|
committer | markj <markj@FreeBSD.org> | 2013-12-03 03:40:47 +0000 |
commit | 80b61d514a5ff7363b88aabeb8df5ae6661ab146 (patch) | |
tree | 74f3d814576a6a48a4b7b537f47e1926e11f9d73 /cddl | |
parent | d3a0e92020a765c11f02f51a0bccdd2796fe6c6f (diff) | |
download | FreeBSD-src-80b61d514a5ff7363b88aabeb8df5ae6661ab146.zip FreeBSD-src-80b61d514a5ff7363b88aabeb8df5ae6661ab146.tar.gz |
Use mkstemp(3) to create the temporary file used in the FreeBSD-specific
portions of dtrace_program_link().
Diffstat (limited to 'cddl')
-rw-r--r-- | cddl/contrib/opensolaris/lib/libdtrace/common/dt_link.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_link.c b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_link.c index 5d72e98..6561c93 100644 --- a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_link.c +++ b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_link.c @@ -1709,8 +1709,6 @@ dtrace_program_link(dtrace_hdl_t *dtp, dtrace_prog_t *pgp, uint_t dflags, */ return (0); } - /* XXX Should get a temp file name here. */ - snprintf(tfile, sizeof(tfile), "%s.tmp", file); #endif /* @@ -1785,9 +1783,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 ((fd = open(tfile, O_RDWR | O_CREAT | O_TRUNC, 0666)) == -1) + snprintf(tfile, sizeof(tfile), "%s.XXXXXX", file); + if ((fd = mkstemp(tfile)) == -1) return (dt_link_error(dtp, NULL, -1, NULL, - "failed to open %s: %s", tfile, strerror(errno))); + "failed to create temporary file %s: %s", + tfile, strerror(errno))); #endif /* @@ -1830,13 +1830,15 @@ dtrace_program_link(dtrace_hdl_t *dtp, dtrace_prog_t *pgp, uint_t dflags, status = dump_elf32(dtp, dof, fd); if (status != 0 || lseek(fd, 0, SEEK_SET) != 0) { -#else - /* We don't write the ELF header, just the DOF section */ - if (dt_write(dtp, fd, dof, dof->dofh_filesz) < dof->dofh_filesz) { -#endif return (dt_link_error(dtp, NULL, -1, NULL, "failed to write %s: %s", file, strerror(errno))); } +#else + /* We don't write the ELF header, just the DOF section */ + if (dt_write(dtp, fd, dof, dof->dofh_filesz) < dof->dofh_filesz) + return (dt_link_error(dtp, NULL, -1, NULL, + "failed to write %s: %s", tfile, strerror(errno))); +#endif if (!dtp->dt_lazyload) { #if defined(sun) |