X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fshared%2Fpath-util.c;h=69fcb1660a134531830047795a3edd77d7ef6eb2;hp=1ad1084b2d5f0653bb56b1e8dee818b39199fe88;hb=21749924e12201d8f5210c5dc9695e18fd16bb93;hpb=eb66db55fc4b342e4253065886e0cc0419c45a07 diff --git a/src/shared/path-util.c b/src/shared/path-util.c index 1ad1084b2..69fcb1660 100644 --- a/src/shared/path-util.c +++ b/src/shared/path-util.c @@ -324,11 +324,15 @@ bool path_equal(const char *a, const char *b) { } int path_is_mount_point(const char *t, bool allow_symlink) { - char *parent; - int r; - struct file_handle *h; + + union file_handle_union h = { + .handle.handle_bytes = MAX_HANDLE_SZ + }; + int mount_id, mount_id_parent; + char *parent; struct stat a, b; + int r; /* We are not actually interested in the file handles, but * name_to_handle_at() also passes us the mount ID, hence use @@ -337,12 +341,9 @@ int path_is_mount_point(const char *t, bool allow_symlink) { if (path_equal(t, "/")) return 1; - h = alloca(MAX_HANDLE_SZ); - h->handle_bytes = MAX_HANDLE_SZ; - - r = name_to_handle_at(AT_FDCWD, t, h, &mount_id, allow_symlink ? AT_SYMLINK_FOLLOW : 0); + r = name_to_handle_at(AT_FDCWD, t, &h.handle, &mount_id, allow_symlink ? AT_SYMLINK_FOLLOW : 0); if (r < 0) { - if (errno == ENOSYS || errno == ENOTSUP) + if (IN_SET(errno, ENOSYS, EOPNOTSUPP)) /* This kernel or file system does not support * name_to_handle_at(), hence fallback to the * traditional stat() logic */ @@ -358,15 +359,14 @@ int path_is_mount_point(const char *t, bool allow_symlink) { if (r < 0) return r; - h->handle_bytes = MAX_HANDLE_SZ; - r = name_to_handle_at(AT_FDCWD, parent, h, &mount_id_parent, 0); + h.handle.handle_bytes = MAX_HANDLE_SZ; + r = name_to_handle_at(AT_FDCWD, parent, &h.handle, &mount_id_parent, 0); free(parent); - if (r < 0) { /* The parent can't do name_to_handle_at() but the * directory we are interested in can? If so, it must * be a mount point */ - if (errno == ENOTSUP) + if (errno == EOPNOTSUPP) return 1; return -errno; @@ -393,7 +393,6 @@ fallback: r = lstat(parent, &b); free(parent); - if (r < 0) return -errno; @@ -427,15 +426,16 @@ int find_binary(const char *name, char **filename) { assert(name); if (strchr(name, '/')) { + if (access(name, X_OK) < 0) + return -errno; + if (filename) { char *p; - if (path_is_absolute(name)) - p = strdup(name); - else - p = path_make_absolute_cwd(name); + p = path_make_absolute_cwd(name); if (!p) return -ENOMEM; + *filename = p; } @@ -463,8 +463,7 @@ int find_binary(const char *name, char **filename) { continue; if (filename) { - path_kill_slashes(p); - *filename = p; + *filename = path_kill_slashes(p); p = NULL; }