fs-util,tmpfiles: fix error handling of fchmod_opath()
When4dfaa528d4was first commited its callers relied on `errno` instead of the return value for error reporting. Which worked fine, since internally under all conditions base were set — even if ugly and not inline with our coding style. Things then got broken inf8606626edwhere suddenly additional syscalls might end up being done in the function, thus corrupting `errno`.
This commit is contained in:
@@ -836,6 +836,7 @@ static int fd_set_perms(Item *i, int fd, const char *path, const struct stat *st
|
||||
struct stat stbuf;
|
||||
mode_t new_mode;
|
||||
bool do_chown;
|
||||
int r;
|
||||
|
||||
assert(i);
|
||||
assert(fd);
|
||||
@@ -881,8 +882,9 @@ static int fd_set_perms(Item *i, int fd, const char *path, const struct stat *st
|
||||
log_debug("\"%s\" matches temporary mode %o already.", path, m);
|
||||
else {
|
||||
log_debug("Temporarily changing \"%s\" to mode %o.", path, m);
|
||||
if (fchmod_opath(fd, m) < 0)
|
||||
return log_error_errno(errno, "fchmod() of %s failed: %m", path);
|
||||
r = fchmod_opath(fd, m);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "fchmod() of %s failed: %m", path);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -913,8 +915,9 @@ static int fd_set_perms(Item *i, int fd, const char *path, const struct stat *st
|
||||
log_debug("\"%s\" matches mode %o already.", path, new_mode);
|
||||
else {
|
||||
log_debug("Changing \"%s\" to mode %o.", path, new_mode);
|
||||
if (fchmod_opath(fd, new_mode) < 0)
|
||||
return log_error_errno(errno, "fchmod() of %s failed: %m", path);
|
||||
r = fchmod_opath(fd, new_mode);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "fchmod() of %s failed: %m", path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user