diff options
author | Thomas Haller <thaller@redhat.com> | 2015-01-09 11:25:06 +0100 |
---|---|---|
committer | Dan Williams <dcbw@redhat.com> | 2015-01-19 12:07:27 -0600 |
commit | 4ad6099b016317563c14648ca6f04fb9e320d032 (patch) | |
tree | 9490438d97de64e38a8da31ef50f6d72e7d1b34d /src | |
parent | 1970f59b6f463be559c47fe944efd560a4629c88 (diff) |
utils: add nm_utils_modprobe()
https://bugzilla.gnome.org/show_bug.cgi?id=740651
Diffstat (limited to 'src')
-rw-r--r-- | src/NetworkManagerUtils.c | 37 | ||||
-rw-r--r-- | src/NetworkManagerUtils.h | 2 |
2 files changed, 39 insertions, 0 deletions
diff --git a/src/NetworkManagerUtils.c b/src/NetworkManagerUtils.c index 268abb84a..0ac432f0d 100644 --- a/src/NetworkManagerUtils.c +++ b/src/NetworkManagerUtils.c @@ -48,6 +48,7 @@ #include "nm-setting-wireless-security.h" #include "nm-auth-utils.h" #include "nm-dbus-glib-types.h" +#include "gsystem-local-alloc.h" /* * Some toolchains (E.G. uClibc 0.9.33 and earlier) don't export @@ -175,6 +176,42 @@ nm_spawn_process (const char *args) return status; } +int +nm_utils_modprobe (GError **error, const char *arg1, ...) +{ + gs_unref_ptrarray GPtrArray *argv = NULL; + int exit_status; + gs_free char *_log_str = NULL; +#define ARGV_TO_STR(argv) (_log_str ? _log_str : (_log_str = g_strjoinv (" ", (char **) argv->pdata))) + GError *local = NULL; + va_list ap; + + g_return_val_if_fail (!error || !*error, -1); + g_return_val_if_fail (arg1, -1); + + /* construct the argument list */ + argv = g_ptr_array_sized_new (4); + g_ptr_array_add (argv, "/sbin/modprobe"); + g_ptr_array_add (argv, (char *) arg1); + + va_start (ap, arg1); + while ((arg1 = va_arg (ap, const char *))) + g_ptr_array_add (argv, (char *) arg1); + va_end (ap); + + g_ptr_array_add (argv, NULL); + + nm_log_dbg (LOGD_CORE, "modprobe: '%s'", ARGV_TO_STR (argv)); + if (!g_spawn_sync (NULL, (char **) argv->pdata, NULL, 0, NULL, NULL, NULL, NULL, &exit_status, &local)) { + nm_log_err (LOGD_CORE, "modprobe: '%s' failed: %s", ARGV_TO_STR (argv), local->message); + g_propagate_error (error, local); + return -1; + } else if (exit_status != 0) + nm_log_err (LOGD_CORE, "modprobe: '%s' exited with error %d", ARGV_TO_STR (argv), exit_status); + + return exit_status; +} + /** * nm_utils_get_start_time_for_pid: * @pid: the process identifier diff --git a/src/NetworkManagerUtils.h b/src/NetworkManagerUtils.h index 99543df31..191c19ce9 100644 --- a/src/NetworkManagerUtils.h +++ b/src/NetworkManagerUtils.h @@ -51,6 +51,8 @@ nm_utils_ip6_route_metric_normalize (guint32 metric) int nm_spawn_process (const char *args); +int nm_utils_modprobe (GError **error, const char *arg1, ...) G_GNUC_NULL_TERMINATED; + /* check if @flags has exactly one flag (@check) set. You should call this * only with @check being a compile time constant and a power of two. */ #define NM_FLAGS_HAS(flags, check) \ |