mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-10-03 04:45:46 +00:00
Use g_mkstemp_full instead of mkostemp(s)
With g_mkstemp_full, there is no need to distinguish between mkostemp and mkostemps (no suffix vs. a suffix of a fixed length), because the GLib function looks for the XXXXXX pattern everywhere in the string. Use S_IRUSR | S_IWUSR for the permissions and do not pass O_RDWR in flags since it's implied. Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
parent
c4ae19d1ec
commit
4ac4773040
@ -4024,8 +4024,8 @@ qemuDomainScreenshot(virDomainPtr dom,
|
|||||||
if (!(tmp = g_strdup_printf("%s/qemu.screendump.XXXXXX", cfg->cacheDir)))
|
if (!(tmp = g_strdup_printf("%s/qemu.screendump.XXXXXX", cfg->cacheDir)))
|
||||||
goto endjob;
|
goto endjob;
|
||||||
|
|
||||||
if ((tmp_fd = mkostemp(tmp, O_CLOEXEC)) == -1) {
|
if ((tmp_fd = g_mkstemp_full(tmp, O_CLOEXEC, S_IRUSR | S_IWUSR)) == -1) {
|
||||||
virReportSystemError(errno, _("mkostemp(\"%s\") failed"), tmp);
|
virReportSystemError(errno, _("g_mkstemp(\"%s\") failed"), tmp);
|
||||||
goto endjob;
|
goto endjob;
|
||||||
}
|
}
|
||||||
unlink_tmp = true;
|
unlink_tmp = true;
|
||||||
@ -11970,9 +11970,9 @@ qemuDomainMemoryPeek(virDomainPtr dom,
|
|||||||
goto endjob;
|
goto endjob;
|
||||||
|
|
||||||
/* Create a temporary filename. */
|
/* Create a temporary filename. */
|
||||||
if ((fd = mkostemp(tmp, O_CLOEXEC)) == -1) {
|
if ((fd = g_mkstemp_full(tmp, O_CLOEXEC, S_IRUSR | S_IWUSR)) == -1) {
|
||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
_("mkostemp(\"%s\") failed"), tmp);
|
_("g_mkstemp(\"%s\") failed"), tmp);
|
||||||
goto endjob;
|
goto endjob;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2825,7 +2825,7 @@ virStoragePoolObjFindPoolByUUID(const unsigned char *uuid)
|
|||||||
*
|
*
|
||||||
* Generate a name for a temporary file using the driver stateDir
|
* Generate a name for a temporary file using the driver stateDir
|
||||||
* as a path, the pool name, and the volume name to be used as input
|
* as a path, the pool name, and the volume name to be used as input
|
||||||
* for a mkostemp
|
* for mkstemp
|
||||||
*
|
*
|
||||||
* Returns a string pointer on success, NULL on failure
|
* Returns a string pointer on success, NULL on failure
|
||||||
*/
|
*/
|
||||||
|
@ -1215,7 +1215,7 @@ storageBackendCreateQemuImgSecretPath(virStoragePoolObjPtr pool,
|
|||||||
if (!(secretPath = virStoragePoolObjBuildTempFilePath(pool, vol)))
|
if (!(secretPath = virStoragePoolObjBuildTempFilePath(pool, vol)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if ((fd = mkostemp(secretPath, O_CLOEXEC)) < 0) {
|
if ((fd = g_mkstemp_full(secretPath, O_CLOEXEC, S_IRUSR | S_IWUSR)) < 0) {
|
||||||
virReportSystemError(errno, "%s",
|
virReportSystemError(errno, "%s",
|
||||||
_("failed to open secret file for write"));
|
_("failed to open secret file for write"));
|
||||||
goto error;
|
goto error;
|
||||||
|
@ -992,13 +992,7 @@ virLogOutputToJournald(virLogSourcePtr source,
|
|||||||
* and pass an FD to the journal
|
* and pass an FD to the journal
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* NB: mkostemp is not declared async signal safe by
|
if ((buffd = g_mkstemp_full(path, O_CLOEXEC, S_IRUSR | S_IWUSR)) < 0)
|
||||||
* POSIX, but this is Linux only code and the GLibc
|
|
||||||
* impl is safe enough, only using open() and inline
|
|
||||||
* asm to read a timestamp (falling back to gettimeofday
|
|
||||||
* on some arches
|
|
||||||
*/
|
|
||||||
if ((buffd = mkostemp(path, O_CLOEXEC|O_RDWR)) < 0)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (unlink(path) < 0)
|
if (unlink(path) < 0)
|
||||||
|
@ -7385,8 +7385,8 @@ vboxDomainScreenshot(virDomainPtr dom,
|
|||||||
|
|
||||||
tmp = g_strdup_printf("%s/vbox.screendump.XXXXXX", cacheDir);
|
tmp = g_strdup_printf("%s/vbox.screendump.XXXXXX", cacheDir);
|
||||||
|
|
||||||
if ((tmp_fd = mkostemp(tmp, O_CLOEXEC)) == -1) {
|
if ((tmp_fd = g_mkstemp_full(tmp, O_CLOEXEC, S_IRUSR | S_IWUSR)) == -1) {
|
||||||
virReportSystemError(errno, _("mkostemp(\"%s\") failed"), tmp);
|
virReportSystemError(errno, _("g_mkstemp(\"%s\") failed"), tmp);
|
||||||
VIR_FREE(tmp);
|
VIR_FREE(tmp);
|
||||||
VBOX_RELEASE(machine);
|
VBOX_RELEASE(machine);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -133,7 +133,7 @@ makeSparseFile(const off_t offsets[],
|
|||||||
off_t len = 0;
|
off_t len = 0;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
if ((fd = mkostemp(path, O_CLOEXEC|O_RDWR)) < 0)
|
if ((fd = g_mkstemp_full(path, O_CLOEXEC, S_IRUSR | S_IWUSR)) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (unlink(path) < 0)
|
if (unlink(path) < 0)
|
||||||
|
@ -2400,9 +2400,9 @@ vshEditWriteToTempFile(vshControl *ctl, const char *doc)
|
|||||||
tmpdir = getenv("TMPDIR");
|
tmpdir = getenv("TMPDIR");
|
||||||
if (!tmpdir) tmpdir = "/tmp";
|
if (!tmpdir) tmpdir = "/tmp";
|
||||||
ret = g_strdup_printf("%s/virshXXXXXX.xml", tmpdir);
|
ret = g_strdup_printf("%s/virshXXXXXX.xml", tmpdir);
|
||||||
fd = mkostemps(ret, 4, O_CLOEXEC);
|
fd = g_mkstemp_full(ret, O_CLOEXEC, S_IRUSR | S_IWUSR);
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
vshError(ctl, _("mkostemps: failed to create temporary file: %s"),
|
vshError(ctl, _("g_mkstemp_full: failed to create temporary file: %s"),
|
||||||
virStrerror(errno, ebuf, sizeof(ebuf)));
|
virStrerror(errno, ebuf, sizeof(ebuf)));
|
||||||
VIR_FREE(ret);
|
VIR_FREE(ret);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
Loading…
Reference in New Issue
Block a user