mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-07-11 05:52:36 +02:00
lbutils/file: tidy up mkhtemp_tmpfile_linux
make failure more obvious. no behavioural change. Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
@@ -694,26 +694,27 @@ mkhtemp_tmpfile_linux(int dirfd,
|
|||||||
st_dir_first) < 0)
|
st_dir_first) < 0)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
if (linkat(tmpfd, "", dirfd, fname_copy, AT_EMPTY_PATH) == 0) {
|
if (linkat(tmpfd, "", dirfd,
|
||||||
|
fname_copy, AT_EMPTY_PATH) == -1) {
|
||||||
|
|
||||||
linked = 1; /* file created */
|
if (errno == EEXIST)
|
||||||
|
continue; /* retry on collision */
|
||||||
/* TODO: potential fd leak here.
|
else
|
||||||
* probably should only set *fd on successful
|
|
||||||
* return from this function (see below)
|
|
||||||
*/
|
|
||||||
if (fd_verify_dir_identity(dirfd, st_dir_first) < 0 ||
|
|
||||||
fstat(*fd = tmpfd, st) < 0 ||
|
|
||||||
secure_file(fd, st, st, O_APPEND, 1, 1, 0600) < 0)
|
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
goto out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (errno != EEXIST)
|
linked = 1; /* file created */
|
||||||
|
|
||||||
|
/* TODO: potential fd leak here.
|
||||||
|
* probably should only set *fd on successful
|
||||||
|
* return from this function (see below)
|
||||||
|
*/
|
||||||
|
if (fd_verify_dir_identity(dirfd, st_dir_first) < 0 ||
|
||||||
|
fstat(*fd = tmpfd, st) < 0 ||
|
||||||
|
secure_file(fd, st, st, O_APPEND, 1, 1, 0600) < 0)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
/* retry on collision */
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
errno = EEXIST;
|
errno = EEXIST;
|
||||||
|
|||||||
Reference in New Issue
Block a user