summaryrefslogtreecommitdiff
path: root/src/tmpfiles
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2019-10-24 10:33:20 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2019-10-24 22:44:24 +0900
commita5648b809457d120500b2acb18b31e2168a4817a (patch)
tree59846b7791dce151e858a889f1281bad28c55ffe /src/tmpfiles
parent58ce85f6a17b6db03265e6a974120b18d1c0855a (diff)
downloadsystemd-a5648b809457d120500b2acb18b31e2168a4817a.tar.gz
systemd-a5648b809457d120500b2acb18b31e2168a4817a.tar.bz2
systemd-a5648b809457d120500b2acb18b31e2168a4817a.zip
basic/fs-util: change CHASE_OPEN flag into a separate output parameter
chase_symlinks() would return negative on error, and either a non-negative status or a non-negative fd when CHASE_OPEN was given. This made the interface quite complicated, because dependning on the flags used, we would get two different "types" of return object. Coverity was always confused by this, and flagged every use of chase_symlinks() without CHASE_OPEN as a resource leak (because it would this that an fd is returned). This patch uses a saparate output parameter, so there is no confusion. (I think it is OK to have functions which return either an error or an fd. It's only returning *either* an fd or a non-fd that is confusing.)
Diffstat (limited to 'src/tmpfiles')
-rw-r--r--src/tmpfiles/tmpfiles.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c
index 19a2aa6f21..fae949863a 100644
--- a/src/tmpfiles/tmpfiles.c
+++ b/src/tmpfiles/tmpfiles.c
@@ -859,7 +859,7 @@ shortcut:
static int path_open_parent_safe(const char *path) {
_cleanup_free_ char *dn = NULL;
- int fd;
+ int r, fd;
if (path_equal(path, "/") || !path_is_normalized(path))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
@@ -870,15 +870,15 @@ static int path_open_parent_safe(const char *path) {
if (!dn)
return log_oom();
- fd = chase_symlinks(dn, arg_root, CHASE_OPEN|CHASE_SAFE|CHASE_WARN, NULL);
- if (fd < 0 && fd != -ENOLINK)
- return log_error_errno(fd, "Failed to validate path %s: %m", path);
+ r = chase_symlinks(dn, arg_root, CHASE_SAFE|CHASE_WARN, NULL, &fd);
+ if (r < 0 && r != -ENOLINK)
+ return log_error_errno(r, "Failed to validate path %s: %m", path);
- return fd;
+ return r < 0 ? r : fd;
}
static int path_open_safe(const char *path) {
- int fd;
+ int r, fd;
/* path_open_safe() returns a file descriptor opened with O_PATH after
* verifying that the path doesn't contain unsafe transitions, except
@@ -891,11 +891,11 @@ static int path_open_safe(const char *path) {
"Failed to open invalid path '%s'.",
path);
- fd = chase_symlinks(path, arg_root, CHASE_OPEN|CHASE_SAFE|CHASE_WARN|CHASE_NOFOLLOW, NULL);
- if (fd < 0 && fd != -ENOLINK)
- return log_error_errno(fd, "Failed to validate path %s: %m", path);
+ r = chase_symlinks(path, arg_root, CHASE_SAFE|CHASE_WARN|CHASE_NOFOLLOW, NULL, &fd);
+ if (r < 0 && r != -ENOLINK)
+ return log_error_errno(r, "Failed to validate path %s: %m", path);
- return fd;
+ return r < 0 ? r : fd;
}
static int path_set_perms(Item *i, const char *path) {
@@ -2257,7 +2257,7 @@ static int process_item(Item *i, OperationMask operation) {
i->done |= operation;
- r = chase_symlinks(i->path, arg_root, CHASE_NO_AUTOFS|CHASE_WARN, NULL);
+ r = chase_symlinks(i->path, arg_root, CHASE_NO_AUTOFS|CHASE_WARN, NULL, NULL);
if (r == -EREMOTE) {
log_notice_errno(r, "Skipping %s", i->path);
return 0;