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-05 11:07:42 +0100
commitcb8af29f0b180bfc4a5558334881285539a8dcdb (patch)
tree4fc86373fa1e1f8e4f8c8a5c19cb8df5a8315d21
parent6399170ff36986b7e973f77598390b37612106cb (diff)
downloadNetworkManager-cb8af29f0b180bfc4a5558334881285539a8dcdb.tar.gz
core: implement nm_utils_find_helper() based on nm_utils_file_search_in_paths()
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 2ce6e1a396..e78f2a0f89 100644
--- a/src/NetworkManagerUtils.c
+++ b/src/NetworkManagerUtils.c
@@ -808,54 +808,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);
}
/******************************************************************************************/