]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
util-lib: Don't propagate EACCES from find_binary PATH lookup to caller 13651/head
authorChris Down <chris@chrisdown.name>
Wed, 25 Sep 2019 16:09:38 +0000 (17:09 +0100)
committerChris Down <chris@chrisdown.name>
Thu, 26 Sep 2019 08:19:20 +0000 (09:19 +0100)
On one of my test machines, test-path-util was failing because the
find_binary("xxxx-xxxx") was returning -EACCES instead of -ENOENT. This
happens because the PATH entry on that host contains a directory which
the user in question doesn't have access to. Typically applications
ignore permission errors when searching through PATH, for example in
bash:

    $ whoami
    cdown
    $ PATH=/root:/bin type sh
    sh is /bin/sh

This behaviour is present on zsh and other shells as well, though. This
patch brings our PATH search behaviour closer to other major Unix tools.

src/basic/path-util.c

index 18c7dabbae0bf7f741a7c580311d7eadf6a69af8..b9544b4bacce90cb906b29a743864ff98660a8d7 100644 (file)
@@ -651,7 +651,9 @@ int find_binary(const char *name, char **ret) {
                         return 0;
                 }
 
-                last_error = -errno;
+                /* PATH entries which we don't have access to are ignored, as per tradition. */
+                if (errno != EACCES)
+                        last_error = -errno;
         }
 
         return last_error;