When in lazyload mode, write the DOF to a temporary file and rename it
rather than writing directly to the output file. CID: 1147172
This commit is contained in:
parent
caa3817d4f
commit
ed09cc1b53
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=283024
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user