mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-09 01:50:21 +01:00
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
This commit is contained in:
parent
6399170ff3
commit
cb8af29f0b
1 changed files with 13 additions and 46 deletions
|
|
@ -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 *const NM_PATHS_DEFAULT[] = {
|
||||
PREFIX "/sbin/",
|
||||
PREFIX "/bin/",
|
||||
"/sbin/",
|
||||
"/usr/sbin/",
|
||||
"/usr/local/sbin/",
|
||||
"/usr/bin/",
|
||||
"/usr/local/bin/",
|
||||
NULL,
|
||||
};
|
||||
|
||||
const char *
|
||||
nm_utils_find_helper (const char *progname,
|
||||
const char *try_first,
|
||||
GError **error)
|
||||
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);
|
||||
|
||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, "Could not find %s binary", progname);
|
||||
return NULL;
|
||||
return nm_utils_file_search_in_paths (progname, try_first, NM_PATHS_DEFAULT, G_FILE_TEST_IS_EXECUTABLE, NULL, NULL, error);
|
||||
}
|
||||
|
||||
/******************************************************************************************/
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue