Commit a387f1de authored by Dan Williams's avatar Dan Williams

merge: don't use system() for loading modules (bgo #740651)

parents 1970f59b 32625f60
......@@ -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
......
......@@ -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) \
......
......@@ -4934,7 +4934,6 @@ nm_device_activate_schedule_ip6_config_timeout (NMDevice *self)
static gboolean
share_init (void)
{
int status;
char *modules[] = { "ip_tables", "iptable_nat", "nf_nat_ftp", "nf_nat_irc",
"nf_nat_sip", "nf_nat_tftp", "nf_nat_pptp", "nf_nat_h323",
NULL };
......@@ -4954,20 +4953,8 @@ share_init (void)
errsv, strerror (errsv));
}
for (iter = modules; *iter; iter++) {
char *argv[3] = { "/sbin/modprobe", *iter, NULL };
char *envp[1] = { NULL };
GError *error = NULL;
if (!g_spawn_sync ("/", argv, envp, G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL,
NULL, NULL, NULL, NULL, &status, &error)) {
nm_log_err (LOGD_SHARING, "share: error loading NAT module %s: (%d) %s",
*iter, error ? error->code : 0,
(error && error->message) ? error->message : "unknown");
if (error)
g_error_free (error);
}
}
for (iter = modules; *iter; iter++)
nm_utils_modprobe (NULL, *iter, NULL);
return TRUE;
}
......
......@@ -2267,7 +2267,6 @@ build_rtnl_link (int ifindex, const char *name, NMLinkType type)
static gboolean
link_add (NMPlatform *platform, const char *name, NMLinkType type, const void *address, size_t address_len)
{
int r;
struct nl_object *l;
if (type == NM_LINK_TYPE_BOND) {
......@@ -2279,8 +2278,7 @@ link_add (NMPlatform *platform, const char *name, NMLinkType type, const void *a
* bond0 automatically.
*/
if (!g_file_test ("/sys/class/net/bonding_masters", G_FILE_TEST_EXISTS))
/* Ignore return value to shut up the compiler */
r = system ("modprobe bonding max_bonds=0");
nm_utils_modprobe (NULL, "bonding", "max_bonds=0", NULL);
}
debug ("link: add link '%s' of type '%s' (%d)",
......
......@@ -1068,7 +1068,6 @@ nm_ppp_manager_start (NMPPPManager *manager,
NMCmdLine *ppp_cmd;
char *cmd_str;
struct stat st;
int ignored;
g_return_val_if_fail (NM_IS_PPP_MANAGER (manager), FALSE);
g_return_val_if_fail (NM_IS_ACT_REQUEST (req), FALSE);
......@@ -1088,7 +1087,7 @@ nm_ppp_manager_start (NMPPPManager *manager,
/* Make sure /dev/ppp exists (bgo #533064) */
if (stat ("/dev/ppp", &st) || !S_ISCHR (st.st_mode))
ignored = system ("/sbin/modprobe ppp_generic");
nm_utils_modprobe (NULL, "ppp_generic", NULL);
connection = nm_act_request_get_connection (req);
g_assert (connection);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment