summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2014-11-25 23:02:33 +0100
committerThomas Haller <thaller@redhat.com>2014-12-04 13:29:40 +0100
commit96fb8f84147b40ceaf3e6118a259b14f4d17f2be (patch)
treeaadc2a0c8d43f3c30c5cb28b37e01bd583aed434
parent1f4c67e3930a72960b533bad614817a16172f400 (diff)
downloadNetworkManager-96fb8f84147b40ceaf3e6118a259b14f4d17f2be.tar.gz
core: implement nm_utils_find_helper() based on nm_utils_file_search_in_paths()th/file_search_in_path_bgo740783
This also changes behavior in that we now only find files that are executable. https://bugzilla.gnome.org/show_bug.cgi?id=740783
-rw-r--r--src/NetworkManagerUtils.c61
1 files changed, 14 insertions, 47 deletions
diff --git a/src/NetworkManagerUtils.c b/src/NetworkManagerUtils.c
index 0dcd643bf3..15d6261641 100644
--- a/src/NetworkManagerUtils.c
+++ b/src/NetworkManagerUtils.c
@@ -797,54 +797,21 @@ nm_utils_kill_process_sync (pid_t pid, guint64 start_time, int sig, guint64 log_
#undef LOG_NAME_PROCESS_FMT
#undef LOG_NAME_ARGS
-/**
- * nm_utils_find_helper:
- * @progname: the helper program name, like "iptables"
- * @try_first: a custom path to try first before searching
- * @error: on failure, a "not found" error using @error_domain and @error_code
- *
- * Searches for the @progname in common system paths.
- *
- * Returns: the full path to the helper, if found, or %NULL if not found.
- */
-const char *
-nm_utils_find_helper (const char *progname,
- const char *try_first,
- GError **error)
-{
- static const char *paths[] = {
- PREFIX "/sbin/",
- PREFIX "/bin/",
- "/sbin/",
- "/usr/sbin/",
- "/usr/local/sbin/",
- "/usr/bin/",
- "/usr/local/bin/",
- };
- guint i;
- GString *tmp;
- const char *ret;
-
- if (error)
- g_return_val_if_fail (*error == NULL, NULL);
-
- if (try_first && try_first[0] && g_file_test (try_first, G_FILE_TEST_EXISTS))
- return g_intern_string (try_first);
-
- tmp = g_string_sized_new (50);
- for (i = 0; i < G_N_ELEMENTS (paths); i++) {
- g_string_append_printf (tmp, "%s%s", paths[i], progname);
- if (g_file_test (tmp->str, G_FILE_TEST_EXISTS)) {
- ret = g_intern_string (tmp->str);
- g_string_free (tmp, TRUE);
- return ret;
- }
- g_string_set_size (tmp, 0);
- }
- g_string_free (tmp, TRUE);
+const char *const NM_PATHS_DEFAULT[] = {
+ PREFIX "/sbin/",
+ PREFIX "/bin/",
+ "/sbin/",
+ "/usr/sbin/",
+ "/usr/local/sbin/",
+ "/usr/bin/",
+ "/usr/local/bin/",
+ NULL,
+};
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, "Could not find %s binary", progname);
- return NULL;
+const char *
+nm_utils_find_helper(const char *progname, const char *try_first, GError **error)
+{
+ return nm_utils_file_search_in_paths (progname, try_first, NM_PATHS_DEFAULT, G_FILE_TEST_IS_EXECUTABLE, NULL, NULL, error);
}
/******************************************************************************************/