main: preserve errno for create_directory

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
Giuseppe Scrivano 2020-03-03 15:42:14 +01:00
parent 47218d09ab
commit 9660aaed2f
No known key found for this signature in database
GPG Key ID: E4730F97F60286ED

3
main.c
View File

@ -2418,6 +2418,7 @@ create_directory (struct ovl_data *lo, int dirfd, const char *name, const struct
struct ovl_node *parent, int xattr_sfd, uid_t uid, gid_t gid, mode_t mode, bool set_opaque, struct stat *st_out) struct ovl_node *parent, int xattr_sfd, uid_t uid, gid_t gid, mode_t mode, bool set_opaque, struct stat *st_out)
{ {
int ret; int ret;
int saved_errno;
cleanup_close int dfd = -1; cleanup_close int dfd = -1;
cleanup_free char *buf = NULL; cleanup_free char *buf = NULL;
char wd_tmp_file_name[32]; char wd_tmp_file_name[32];
@ -2511,8 +2512,10 @@ create_directory (struct ovl_data *lo, int dirfd, const char *name, const struct
ret = renameat (lo->workdir_fd, wd_tmp_file_name, dirfd, name); ret = renameat (lo->workdir_fd, wd_tmp_file_name, dirfd, name);
} }
out: out:
saved_errno = errno;
if (ret < 0) if (ret < 0)
unlinkat (lo->workdir_fd, wd_tmp_file_name, AT_REMOVEDIR); unlinkat (lo->workdir_fd, wd_tmp_file_name, AT_REMOVEDIR);
errno = saved_errno;
return ret; return ret;
} }