Rename find_binary to find_executable
"executable" is more correct than "binary", since scripts are OK too.
This commit is contained in:
parent
0706c01259
commit
f7bc0c324a
|
@ -593,7 +593,7 @@ char* path_join_internal(const char *first, ...) {
|
|||
return joined;
|
||||
}
|
||||
|
||||
int find_binary(const char *name, char **ret) {
|
||||
int find_executable(const char *name, char **ret) {
|
||||
int last_error, r;
|
||||
const char *p;
|
||||
|
||||
|
@ -612,10 +612,7 @@ int find_binary(const char *name, char **ret) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Plain getenv, not secure_getenv, because we want
|
||||
* to actually allow the user to pick the binary.
|
||||
*/
|
||||
/* Plain getenv, not secure_getenv, because we want to actually allow the user to pick the binary. */
|
||||
p = getenv("PATH");
|
||||
if (!p)
|
||||
p = DEFAULT_PATH;
|
||||
|
@ -649,9 +646,7 @@ int find_binary(const char *name, char **ret) {
|
|||
if (access(with_dash, X_OK) >= 0)
|
||||
continue;
|
||||
|
||||
/**
|
||||
* We can't just `continue` inverting this case, since we need to update last_error.
|
||||
*/
|
||||
/* We can't just `continue` inverting this case, since we need to update last_error. */
|
||||
if (errno == ENOTDIR) {
|
||||
/* Found it! */
|
||||
if (ret)
|
||||
|
@ -704,18 +699,17 @@ bool paths_check_timestamp(const char* const* paths, usec_t *timestamp, bool upd
|
|||
return changed;
|
||||
}
|
||||
|
||||
static int binary_is_good(const char *binary) {
|
||||
static int executable_is_good(const char *executable) {
|
||||
_cleanup_free_ char *p = NULL, *d = NULL;
|
||||
int r;
|
||||
|
||||
r = find_binary(binary, &p);
|
||||
r = find_executable(executable, &p);
|
||||
if (r == -ENOENT)
|
||||
return 0;
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
/* An fsck that is linked to /bin/true is a non-existent
|
||||
* fsck */
|
||||
/* An fsck that is linked to /bin/true is a non-existent fsck */
|
||||
|
||||
r = readlink_malloc(p, &d);
|
||||
if (r == -EINVAL) /* not a symlink */
|
||||
|
@ -738,7 +732,7 @@ int fsck_exists(const char *fstype) {
|
|||
return -EINVAL;
|
||||
|
||||
checker = strjoina("fsck.", fstype);
|
||||
return binary_is_good(checker);
|
||||
return executable_is_good(checker);
|
||||
}
|
||||
|
||||
int parse_path_argument_and_warn(const char *path, bool suppress_root, char **arg) {
|
||||
|
|
|
@ -80,7 +80,7 @@ int path_strv_make_absolute_cwd(char **l);
|
|||
char** path_strv_resolve(char **l, const char *root);
|
||||
char** path_strv_resolve_uniq(char **l, const char *root);
|
||||
|
||||
int find_binary(const char *name, char **filename);
|
||||
int find_executable(const char *name, char **filename);
|
||||
|
||||
bool paths_check_timestamp(const char* const* paths, usec_t *paths_ts_usec, bool update);
|
||||
|
||||
|
|
|
@ -176,7 +176,7 @@ _unused_ static void test_compress_stream(const char *compression,
|
|||
_cleanup_free_ char *cmd = NULL, *cmd2 = NULL;
|
||||
struct stat st = {};
|
||||
|
||||
r = find_binary(cat, NULL);
|
||||
r = find_executable(cat, NULL);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Skipping %s, could not find %s binary: %m", __func__, cat);
|
||||
return;
|
||||
|
|
|
@ -1725,7 +1725,7 @@ static int run(int argc, char* argv[]) {
|
|||
|
||||
/* Patch in an absolute path */
|
||||
|
||||
r = find_binary(arg_cmdline[0], &command);
|
||||
r = find_executable(arg_cmdline[0], &command);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to find executable %s: %m", arg_cmdline[0]);
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ int mkfs_exists(const char *fstype) {
|
|||
if (!filename_is_valid(mkfs)) /* refuse file system types with slashes and similar */
|
||||
return -EINVAL;
|
||||
|
||||
r = find_binary(mkfs, NULL);
|
||||
r = find_executable(mkfs, NULL);
|
||||
if (r == -ENOENT)
|
||||
return false;
|
||||
if (r < 0)
|
||||
|
@ -44,7 +44,7 @@ int make_filesystem(
|
|||
assert(label);
|
||||
|
||||
if (streq(fstype, "swap")) {
|
||||
r = find_binary("mkswap", &mkfs);
|
||||
r = find_executable("mkswap", &mkfs);
|
||||
if (r == -ENOENT)
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EPROTONOSUPPORT), "mkswap binary not available.");
|
||||
if (r < 0)
|
||||
|
|
|
@ -328,7 +328,7 @@ static void test_exec_privatedevices(Manager *m) {
|
|||
|
||||
/* We use capsh to test if the capabilities are
|
||||
* properly set, so be sure that it exists */
|
||||
r = find_binary("capsh", NULL);
|
||||
r = find_executable("capsh", NULL);
|
||||
if (r < 0) {
|
||||
log_notice_errno(r, "Could not find capsh binary, skipping remaining tests in %s: %m", __func__);
|
||||
return;
|
||||
|
@ -361,7 +361,7 @@ static void test_exec_protectkernelmodules(Manager *m) {
|
|||
return;
|
||||
}
|
||||
|
||||
r = find_binary("capsh", NULL);
|
||||
r = find_executable("capsh", NULL);
|
||||
if (r < 0) {
|
||||
log_notice_errno(r, "Skipping %s, could not find capsh binary: %m", __func__);
|
||||
return;
|
||||
|
@ -435,7 +435,7 @@ static void test_exec_systemcallfilter(Manager *m) {
|
|||
test(m, "exec-systemcallfilter-failing.service", SIGSYS, CLD_KILLED);
|
||||
test(m, "exec-systemcallfilter-failing2.service", SIGSYS, CLD_KILLED);
|
||||
|
||||
r = find_binary("python3", NULL);
|
||||
r = find_executable("python3", NULL);
|
||||
if (r < 0) {
|
||||
log_notice_errno(r, "Skipping remaining tests in %s, could not find python3 binary: %m", __func__);
|
||||
return;
|
||||
|
@ -458,7 +458,7 @@ static void test_exec_systemcallerrornumber(Manager *m) {
|
|||
return;
|
||||
}
|
||||
|
||||
r = find_binary("python3", NULL);
|
||||
r = find_executable("python3", NULL);
|
||||
if (r < 0) {
|
||||
log_notice_errno(r, "Skipping %s, could not find python3 binary: %m", __func__);
|
||||
return;
|
||||
|
@ -694,7 +694,7 @@ static void test_exec_runtimedirectory(Manager *m) {
|
|||
static void test_exec_capabilityboundingset(Manager *m) {
|
||||
int r;
|
||||
|
||||
r = find_binary("capsh", NULL);
|
||||
r = find_executable("capsh", NULL);
|
||||
if (r < 0) {
|
||||
log_notice_errno(r, "Skipping %s, could not find capsh binary: %m", __func__);
|
||||
return;
|
||||
|
@ -756,7 +756,7 @@ static void test_exec_ambientcapabilities(Manager *m) {
|
|||
static void test_exec_privatenetwork(Manager *m) {
|
||||
int r;
|
||||
|
||||
r = find_binary("ip", NULL);
|
||||
r = find_executable("ip", NULL);
|
||||
if (r < 0) {
|
||||
log_notice_errno(r, "Skipping %s, could not find ip binary: %m", __func__);
|
||||
return;
|
||||
|
|
|
@ -164,31 +164,31 @@ static void test_path_equal_root(void) {
|
|||
assert_se(!path_equal_or_files_same("/", "/.../", AT_SYMLINK_NOFOLLOW));
|
||||
}
|
||||
|
||||
static void test_find_binary(const char *self) {
|
||||
static void test_find_executable(const char *self) {
|
||||
char *p;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(find_binary("/bin/sh", &p) == 0);
|
||||
assert_se(find_executable("/bin/sh", &p) == 0);
|
||||
puts(p);
|
||||
assert_se(path_equal(p, "/bin/sh"));
|
||||
free(p);
|
||||
|
||||
assert_se(find_binary(self, &p) == 0);
|
||||
assert_se(find_executable(self, &p) == 0);
|
||||
puts(p);
|
||||
/* libtool might prefix the binary name with "lt-" */
|
||||
assert_se(endswith(p, "/lt-test-path-util") || endswith(p, "/test-path-util"));
|
||||
assert_se(path_is_absolute(p));
|
||||
free(p);
|
||||
|
||||
assert_se(find_binary("sh", &p) == 0);
|
||||
assert_se(find_executable("sh", &p) == 0);
|
||||
puts(p);
|
||||
assert_se(endswith(p, "/sh"));
|
||||
assert_se(path_is_absolute(p));
|
||||
free(p);
|
||||
|
||||
assert_se(find_binary("xxxx-xxxx", &p) == -ENOENT);
|
||||
assert_se(find_binary("/some/dir/xxxx-xxxx", &p) == -ENOENT);
|
||||
assert_se(find_executable("xxxx-xxxx", &p) == -ENOENT);
|
||||
assert_se(find_executable("/some/dir/xxxx-xxxx", &p) == -ENOENT);
|
||||
}
|
||||
|
||||
static void test_prefixes(void) {
|
||||
|
@ -670,7 +670,7 @@ int main(int argc, char **argv) {
|
|||
test_print_paths();
|
||||
test_path();
|
||||
test_path_equal_root();
|
||||
test_find_binary(argv[0]);
|
||||
test_find_executable(argv[0]);
|
||||
test_prefixes();
|
||||
test_path_join();
|
||||
test_fsck_exists();
|
||||
|
|
|
@ -405,7 +405,7 @@ int xdg_autostart_format_exec_start(
|
|||
|
||||
/* This is the executable, find it in $PATH */
|
||||
first_arg = false;
|
||||
r = find_binary(c, &executable);
|
||||
r = find_executable(c, &executable);
|
||||
if (r < 0)
|
||||
return log_info_errno(r, "Exec binary '%s' does not exist: %m", c);
|
||||
|
||||
|
@ -481,7 +481,7 @@ static int xdg_autostart_generate_desktop_condition(
|
|||
if (!isempty(condition)) {
|
||||
_cleanup_free_ char *gnome_autostart_condition_path = NULL, *e_autostart_condition = NULL;
|
||||
|
||||
r = find_binary(test_binary, &gnome_autostart_condition_path);
|
||||
r = find_executable(test_binary, &gnome_autostart_condition_path);
|
||||
if (r < 0) {
|
||||
log_full_errno(r == -ENOENT ? LOG_INFO : LOG_WARNING, r,
|
||||
"%s not found: %m", test_binary);
|
||||
|
@ -536,10 +536,10 @@ int xdg_autostart_service_generate_unit(
|
|||
|
||||
/*
|
||||
* The TryExec key cannot be checked properly from the systemd unit,
|
||||
* it is trivial to check using find_binary though.
|
||||
* it is trivial to check using find_executable though.
|
||||
*/
|
||||
if (service->try_exec) {
|
||||
r = find_binary(service->try_exec, NULL);
|
||||
r = find_executable(service->try_exec, NULL);
|
||||
if (r < 0) {
|
||||
log_full_errno(r == -ENOENT ? LOG_INFO : LOG_WARNING, r,
|
||||
"Not generating service for XDG autostart %s, could not find TryExec= binary %s: %m",
|
||||
|
|
Loading…
Reference in New Issue