mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-09 17:00:40 +01:00
platform: move nm_utils_modprobe() to libnm-platform
This commit is contained in:
parent
7b18e15481
commit
9113a672cf
9 changed files with 97 additions and 93 deletions
|
|
@ -11634,7 +11634,7 @@ share_init(NMDevice *self, GError **error)
|
|||
}
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS(modules); i++)
|
||||
nm_utils_modprobe(NULL, FALSE, modules[i], NULL);
|
||||
nmp_utils_modprobe(NULL, FALSE, modules[i], NULL);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
#include <linux/if_ether.h>
|
||||
|
||||
#include "libnm-core-intern/nm-core-internal.h"
|
||||
#include "libnm-platform/nm-platform-utils.h"
|
||||
#include "NetworkManagerUtils.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
@ -92,7 +93,7 @@ nmi_ibft_read(const char *sysfs_dir)
|
|||
(GDestroyNotify) g_hash_table_unref);
|
||||
|
||||
if (!g_file_test(ibft_path, G_FILE_TEST_IS_DIR))
|
||||
nm_utils_modprobe(NULL, FALSE, "iscsi_ibft", NULL);
|
||||
nmp_utils_modprobe(NULL, FALSE, "iscsi_ibft", NULL);
|
||||
if (!g_file_test(ibft_path, G_FILE_TEST_IS_DIR))
|
||||
return ibft;
|
||||
|
||||
|
|
|
|||
|
|
@ -274,85 +274,6 @@ nm_utils_array_remove_at_indexes(GArray *array, const guint *indexes_to_delete,
|
|||
g_array_set_size(array, res_length);
|
||||
}
|
||||
|
||||
static const char *
|
||||
_trunk_first_line(char *str)
|
||||
{
|
||||
char *s;
|
||||
|
||||
s = strchr(str, '\n');
|
||||
if (s)
|
||||
s[0] = '\0';
|
||||
return str;
|
||||
}
|
||||
|
||||
int
|
||||
nm_utils_modprobe(GError **error, gboolean suppress_error_logging, 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;
|
||||
NMLogLevel llevel = suppress_error_logging ? LOGL_DEBUG : LOGL_ERR;
|
||||
gs_free char *std_out = NULL, *std_err = NULL;
|
||||
|
||||
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, "--use-blacklist");
|
||||
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,
|
||||
&std_out,
|
||||
&std_err,
|
||||
&exit_status,
|
||||
&local)) {
|
||||
nm_log(llevel,
|
||||
LOGD_CORE,
|
||||
NULL,
|
||||
NULL,
|
||||
"modprobe: '%s' failed: %s",
|
||||
ARGV_TO_STR(argv),
|
||||
local->message);
|
||||
g_propagate_error(error, local);
|
||||
return -1;
|
||||
} else if (exit_status != 0) {
|
||||
nm_log(llevel,
|
||||
LOGD_CORE,
|
||||
NULL,
|
||||
NULL,
|
||||
"modprobe: '%s' exited with error %d%s%s%s%s%s%s",
|
||||
ARGV_TO_STR(argv),
|
||||
exit_status,
|
||||
std_out && *std_out ? " (" : "",
|
||||
std_out && *std_out ? _trunk_first_line(std_out) : "",
|
||||
std_out && *std_out ? ")" : "",
|
||||
std_err && *std_err ? " (" : "",
|
||||
std_err && *std_err ? _trunk_first_line(std_err) : "",
|
||||
std_err && *std_err ? ")" : "");
|
||||
}
|
||||
|
||||
return exit_status;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
typedef struct {
|
||||
|
|
|
|||
|
|
@ -150,9 +150,6 @@ nm_utils_ip_route_metric_penalize(guint32 metric, guint32 penalty)
|
|||
return G_MAXUINT32;
|
||||
}
|
||||
|
||||
int nm_utils_modprobe(GError **error, gboolean suppress_error_loggin, const char *arg1, ...)
|
||||
G_GNUC_NULL_TERMINATED;
|
||||
|
||||
void nm_utils_kill_process_sync(pid_t pid,
|
||||
guint64 start_time,
|
||||
int sig,
|
||||
|
|
|
|||
|
|
@ -7359,7 +7359,7 @@ link_add(NMPlatform * platform,
|
|||
* bond0 automatically.
|
||||
*/
|
||||
if (!g_file_test("/sys/class/net/bonding_masters", G_FILE_TEST_EXISTS))
|
||||
(void) nm_utils_modprobe(NULL, TRUE, "bonding", "max_bonds=0", NULL);
|
||||
(void) nmp_utils_modprobe(NULL, TRUE, "bonding", "max_bonds=0", NULL);
|
||||
}
|
||||
|
||||
nlmsg = _nl_msg_new_link(RTM_NEWLINK, NLM_F_CREATE | NLM_F_EXCL, 0, name);
|
||||
|
|
|
|||
|
|
@ -1303,7 +1303,7 @@ test_software_detect(gconstpointer user_data)
|
|||
|
||||
if (!nm_platform_link_get_by_ifname(NM_PLATFORM_GET, "gre0")) {
|
||||
/* Seems that the ip_gre module is not loaded... try to load it. */
|
||||
gracefully_skip = nm_utils_modprobe(NULL, TRUE, "ip_gre", NULL) != 0;
|
||||
gracefully_skip = nmp_utils_modprobe(NULL, TRUE, "ip_gre", NULL) != 0;
|
||||
}
|
||||
|
||||
if (!nmtstp_link_gre_add(NULL, ext, DEVICE_NAME, &lnk_gre)) {
|
||||
|
|
@ -1330,7 +1330,7 @@ test_software_detect(gconstpointer user_data)
|
|||
|
||||
if (!nm_platform_link_get_by_ifname(NM_PLATFORM_GET, "gretap0")) {
|
||||
/* Seems that the ip_gre module is not loaded... try to load it. */
|
||||
gracefully_skip = nm_utils_modprobe(NULL, TRUE, "ip_gre", NULL) != 0;
|
||||
gracefully_skip = nmp_utils_modprobe(NULL, TRUE, "ip_gre", NULL) != 0;
|
||||
}
|
||||
|
||||
if (!nmtstp_link_gre_add(NULL, ext, DEVICE_NAME, &lnk_gre)) {
|
||||
|
|
@ -1350,7 +1350,7 @@ test_software_detect(gconstpointer user_data)
|
|||
|
||||
if (!nm_platform_link_get_by_ifname(NM_PLATFORM_GET, "tunl0")) {
|
||||
/* Seems that the ipip module is not loaded... try to load it. */
|
||||
gracefully_skip = nm_utils_modprobe(NULL, TRUE, "ipip", NULL) != 0;
|
||||
gracefully_skip = nmp_utils_modprobe(NULL, TRUE, "ipip", NULL) != 0;
|
||||
}
|
||||
|
||||
lnk_ipip.local = nmtst_inet4_from_string("1.2.3.4");
|
||||
|
|
@ -1376,7 +1376,7 @@ test_software_detect(gconstpointer user_data)
|
|||
|
||||
if (!nm_platform_link_get_by_ifname(NM_PLATFORM_GET, "ip6tnl0")) {
|
||||
/* Seems that the ip6_tunnel module is not loaded... try to load it. */
|
||||
gracefully_skip = nm_utils_modprobe(NULL, TRUE, "ip6_tunnel", NULL) != 0;
|
||||
gracefully_skip = nmp_utils_modprobe(NULL, TRUE, "ip6_tunnel", NULL) != 0;
|
||||
}
|
||||
|
||||
switch (test_data->test_mode) {
|
||||
|
|
@ -1418,7 +1418,7 @@ test_software_detect(gconstpointer user_data)
|
|||
|
||||
if (!nm_platform_link_get_by_ifname(NM_PLATFORM_GET, "ip6gre0")) {
|
||||
/* Seems that the ip6_tunnel module is not loaded... try to load it. */
|
||||
gracefully_skip = nm_utils_modprobe(NULL, TRUE, "ip6_gre", NULL) != 0;
|
||||
gracefully_skip = nmp_utils_modprobe(NULL, TRUE, "ip6_gre", NULL) != 0;
|
||||
}
|
||||
|
||||
lnk_ip6tnl.local = *nmtst_inet6_from_string("fd01::42");
|
||||
|
|
@ -1445,7 +1445,7 @@ test_software_detect(gconstpointer user_data)
|
|||
|
||||
if (!nm_platform_link_get_by_ifname(NM_PLATFORM_GET, "ip6gre0")) {
|
||||
/* Seems that the ip6_tunnel module is not loaded... try to load it. */
|
||||
gracefully_skip = nm_utils_modprobe(NULL, TRUE, "ip6_gre", NULL) != 0;
|
||||
gracefully_skip = nmp_utils_modprobe(NULL, TRUE, "ip6_gre", NULL) != 0;
|
||||
}
|
||||
|
||||
lnk_ip6tnl.local = *nmtst_inet6_from_string("fe80::abcd");
|
||||
|
|
@ -1526,7 +1526,7 @@ test_software_detect(gconstpointer user_data)
|
|||
|
||||
if (!nm_platform_link_get_by_ifname(NM_PLATFORM_GET, "sit0")) {
|
||||
/* Seems that the sit module is not loaded... try to load it. */
|
||||
gracefully_skip = nm_utils_modprobe(NULL, TRUE, "sit", NULL) != 0;
|
||||
gracefully_skip = nmp_utils_modprobe(NULL, TRUE, "sit", NULL) != 0;
|
||||
}
|
||||
|
||||
if (!nmtstp_link_sit_add(NULL, ext, DEVICE_NAME, &lnk_sit)) {
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@
|
|||
|
||||
#include "NetworkManagerUtils.h"
|
||||
#include "platform/nm-platform.h"
|
||||
#include "libnm-platform/nm-platform-utils.h"
|
||||
#include "libnm-core-intern/nm-core-internal.h"
|
||||
#include "nm-act-request.h"
|
||||
#include "nm-ip4-config.h"
|
||||
|
|
@ -998,7 +999,7 @@ _ppp_manager_start(NMPPPManager *self,
|
|||
|
||||
/* Make sure /dev/ppp exists (bgo #533064) */
|
||||
if (stat("/dev/ppp", &st) || !S_ISCHR(st.st_mode))
|
||||
nm_utils_modprobe(NULL, FALSE, "ppp_generic", NULL);
|
||||
nmp_utils_modprobe(NULL, FALSE, "ppp_generic", NULL);
|
||||
|
||||
connection = nm_act_request_get_applied_connection(req);
|
||||
g_return_val_if_fail(connection, FALSE);
|
||||
|
|
|
|||
|
|
@ -1952,3 +1952,84 @@ nmp_utils_lifetime_get(guint32 timestamp,
|
|||
|
||||
return t_lifetime;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static const char *
|
||||
_trunk_first_line(char *str)
|
||||
{
|
||||
char *s;
|
||||
|
||||
s = strchr(str, '\n');
|
||||
if (s)
|
||||
s[0] = '\0';
|
||||
return str;
|
||||
}
|
||||
|
||||
int
|
||||
nmp_utils_modprobe(GError **error, gboolean suppress_error_logging, 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;
|
||||
NMLogLevel llevel = suppress_error_logging ? LOGL_DEBUG : LOGL_ERR;
|
||||
gs_free char *std_out = NULL, *std_err = NULL;
|
||||
|
||||
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, "--use-blacklist");
|
||||
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,
|
||||
&std_out,
|
||||
&std_err,
|
||||
&exit_status,
|
||||
&local)) {
|
||||
nm_log(llevel,
|
||||
LOGD_CORE,
|
||||
NULL,
|
||||
NULL,
|
||||
"modprobe: '%s' failed: %s",
|
||||
ARGV_TO_STR(argv),
|
||||
local->message);
|
||||
g_propagate_error(error, local);
|
||||
return -1;
|
||||
} else if (exit_status != 0) {
|
||||
nm_log(llevel,
|
||||
LOGD_CORE,
|
||||
NULL,
|
||||
NULL,
|
||||
"modprobe: '%s' exited with error %d%s%s%s%s%s%s",
|
||||
ARGV_TO_STR(argv),
|
||||
exit_status,
|
||||
std_out && *std_out ? " (" : "",
|
||||
std_out && *std_out ? _trunk_first_line(std_out) : "",
|
||||
std_out && *std_out ? ")" : "",
|
||||
std_err && *std_err ? " (" : "",
|
||||
std_err && *std_err ? _trunk_first_line(std_err) : "",
|
||||
std_err && *std_err ? ")" : "");
|
||||
}
|
||||
|
||||
return exit_status;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -82,4 +82,7 @@ guint32 nmp_utils_lifetime_get(guint32 timestamp,
|
|||
gint32 now,
|
||||
guint32 *out_preferred);
|
||||
|
||||
int nmp_utils_modprobe(GError **error, gboolean suppress_error_logging, const char *arg1, ...)
|
||||
G_GNUC_NULL_TERMINATED;
|
||||
|
||||
#endif /* __NM_PLATFORM_UTILS_H__ */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue