1
0
mirror of https://github.com/systemd/systemd.git synced 2025-03-31 14:50:15 +03:00

path-util: also check for existence of binary when given absolute path

In contrast to a filename-only argument, find_binary() did not
actually check if an path exists, allowing the code to fail later on.
This was OK, but it seems nicer to treat both paths identically.

Also take advantage of path_make_absolute_cwd doing strdup() by itself
if necessary to simplify.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2014-04-12 17:17:49 -04:00
parent eb66db55fc
commit b972115c97
2 changed files with 7 additions and 4 deletions

View File

@ -427,15 +427,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;
}

View File

@ -104,6 +104,8 @@ static void test_find_binary(void) {
free(p);
assert(find_binary("xxxx-xxxx", &p) == -ENOENT);
assert(find_binary("/some/dir/xxxx-xxxx", &p) == -ENOENT);
}
static void test_prefixes(void) {