mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-04-18 15:30:44 +02:00
core: consolidate helper progam searching (bgo #734131)
Instead of having basically the same code in a bunch of different place to find helper programs, just have one place do it. Yes, this does mean that the same sequence of paths is searched for all helpers (so for example, dnsmasq will no longer be found first in /usr/local) but I think consistency is the better option here. https://bugzilla.gnome.org/show_bug.cgi?id=734131
This commit is contained in:
parent
053c8fa5df
commit
544fc82aa7
15 changed files with 140 additions and 240 deletions
|
|
@ -643,10 +643,16 @@ if test "$with_dhclient" = "no" -a "$with_dhcpcd" = "no"; then
|
|||
fi
|
||||
# Add substitutions
|
||||
if test "$with_dhclient" != "no"; then
|
||||
AC_DEFINE(WITH_DHCLIENT, TRUE, [Define if you have dhclient])
|
||||
AC_SUBST(DHCLIENT_PATH, $with_dhclient)
|
||||
else
|
||||
AC_DEFINE(WITH_DHCLIENT, FALSE, [Define if you have dhclient])
|
||||
fi
|
||||
if test "$with_dhcpcd" != "no"; then
|
||||
AC_DEFINE(WITH_DHCPCD, TRUE, [Define if you have dhcpcd])
|
||||
AC_SUBST(DHCPCD_PATH, $with_dhcpcd)
|
||||
else
|
||||
AC_DEFINE(WITH_DHCPCD, FALSE, [Define if you have dhcpcd])
|
||||
fi
|
||||
|
||||
# resolvconf and netconfig support
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ AM_CPPFLAGS = \
|
|||
-I$(top_srcdir)/libnm-core \
|
||||
-I$(top_builddir)/libnm-core \
|
||||
-I$(top_srcdir)/callouts \
|
||||
-DPREFIX=\"$(prefix)\" \
|
||||
-DG_LOG_DOMAIN=\""NetworkManager"\" \
|
||||
-DNETWORKMANAGER_COMPILATION \
|
||||
-DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE
|
||||
|
|
|
|||
|
|
@ -589,6 +589,56 @@ out:
|
|||
#undef LOG_NAME_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);
|
||||
|
||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, "Could not find %s binary", progname);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/******************************************************************************************/
|
||||
|
||||
gboolean
|
||||
|
|
|
|||
|
|
@ -62,6 +62,10 @@ gboolean nm_utils_kill_child_sync (pid_t pid, int sig, guint64 log_domain, const
|
|||
int *child_status, guint32 wait_before_kill_msec,
|
||||
guint32 sleep_duration_msec);
|
||||
|
||||
const char *nm_utils_find_helper (const char *progname,
|
||||
const char *try_first,
|
||||
GError **error);
|
||||
|
||||
gboolean nm_match_spec_string (const GSList *specs, const char *string);
|
||||
gboolean nm_match_spec_hwaddr (const GSList *specs, const char *hwaddr);
|
||||
gboolean nm_match_spec_s390_subchannels (const GSList *specs, const char *subchannels);
|
||||
|
|
|
|||
|
|
@ -2508,27 +2508,17 @@ static NMActStageReturn
|
|||
aipd_start (NMDevice *self, NMDeviceStateReason *reason)
|
||||
{
|
||||
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
|
||||
char *argv[6], *cmdline;
|
||||
const char **aipd_binary = NULL;
|
||||
static const char *aipd_paths[] = {
|
||||
"/usr/sbin/avahi-autoipd",
|
||||
"/usr/local/sbin/avahi-autoipd",
|
||||
NULL
|
||||
};
|
||||
const char *argv[6];
|
||||
char *cmdline;
|
||||
const char *aipd_binary;
|
||||
int i = 0;
|
||||
GError *error = NULL;
|
||||
|
||||
aipd_cleanup (self);
|
||||
|
||||
/* Find avahi-autoipd */
|
||||
aipd_binary = aipd_paths;
|
||||
while (*aipd_binary != NULL) {
|
||||
if (g_file_test (*aipd_binary, G_FILE_TEST_EXISTS))
|
||||
break;
|
||||
aipd_binary++;
|
||||
}
|
||||
|
||||
if (!*aipd_binary) {
|
||||
aipd_binary = nm_utils_find_helper ("avahi-autoipd", NULL, NULL);
|
||||
if (!aipd_binary) {
|
||||
_LOGW (LOGD_DEVICE | LOGD_AUTOIP4,
|
||||
"Activation: Stage 3 of 5 (IP Configure Start) failed"
|
||||
" to start avahi-autoipd: not found");
|
||||
|
|
@ -2536,20 +2526,20 @@ aipd_start (NMDevice *self, NMDeviceStateReason *reason)
|
|||
return NM_ACT_STAGE_RETURN_FAILURE;
|
||||
}
|
||||
|
||||
argv[i++] = (char *) (*aipd_binary);
|
||||
argv[i++] = aipd_binary;
|
||||
argv[i++] = "--script";
|
||||
argv[i++] = (char *) nm_device_autoipd_helper_path;
|
||||
argv[i++] = nm_device_autoipd_helper_path;
|
||||
|
||||
if (nm_logging_enabled (LOGL_DEBUG, LOGD_AUTOIP4))
|
||||
argv[i++] = "--debug";
|
||||
argv[i++] = (char *) nm_device_get_ip_iface (self);
|
||||
argv[i++] = nm_device_get_ip_iface (self);
|
||||
argv[i++] = NULL;
|
||||
|
||||
cmdline = g_strjoinv (" ", argv);
|
||||
cmdline = g_strjoinv (" ", (char **) argv);
|
||||
_LOGD (LOGD_AUTOIP4, "running: %s", cmdline);
|
||||
g_free (cmdline);
|
||||
|
||||
if (!g_spawn_async ("/", argv, NULL, G_SPAWN_DO_NOT_REAP_CHILD,
|
||||
if (!g_spawn_async ("/", (char **) argv, NULL, G_SPAWN_DO_NOT_REAP_CHILD,
|
||||
&aipd_child_setup, NULL, &(priv->aipd_pid), &error)) {
|
||||
_LOGW (LOGD_DEVICE | LOGD_AUTOIP4,
|
||||
"Activation: Stage 3 of 5 (IP Configure Start) failed"
|
||||
|
|
|
|||
|
|
@ -422,12 +422,7 @@ teamd_start (NMDevice *device, NMSettingTeam *s_team)
|
|||
const char *iface = nm_device_get_ip_iface (device);
|
||||
char *tmp_str = NULL;
|
||||
const char *config;
|
||||
const char **teamd_binary = NULL;
|
||||
static const char *teamd_paths[] = {
|
||||
"/usr/bin/teamd",
|
||||
"/usr/local/bin/teamd",
|
||||
NULL
|
||||
};
|
||||
const char *teamd_binary;
|
||||
GPtrArray *argv;
|
||||
GError *error = NULL;
|
||||
gboolean ret;
|
||||
|
|
@ -443,21 +438,15 @@ teamd_start (NMDevice *device, NMSettingTeam *s_team)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
teamd_binary = teamd_paths;
|
||||
while (*teamd_binary != NULL) {
|
||||
if (g_file_test (*teamd_binary, G_FILE_TEST_EXISTS))
|
||||
break;
|
||||
teamd_binary++;
|
||||
}
|
||||
|
||||
if (!*teamd_binary) {
|
||||
teamd_binary = nm_utils_find_helper ("teamd", NULL, NULL);
|
||||
if (!teamd_binary) {
|
||||
_LOGW (LOGD_TEAM, "Activation: (team) failed to start teamd: teamd binary not found");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Kill teamd for same named device first if it is there */
|
||||
argv = g_ptr_array_new ();
|
||||
g_ptr_array_add (argv, (gpointer) *teamd_binary);
|
||||
g_ptr_array_add (argv, (gpointer) teamd_binary);
|
||||
g_ptr_array_add (argv, (gpointer) "-k");
|
||||
g_ptr_array_add (argv, (gpointer) "-t");
|
||||
g_ptr_array_add (argv, (gpointer) iface);
|
||||
|
|
@ -472,7 +461,7 @@ teamd_start (NMDevice *device, NMSettingTeam *s_team)
|
|||
|
||||
/* Start teamd now */
|
||||
argv = g_ptr_array_new ();
|
||||
g_ptr_array_add (argv, (gpointer) *teamd_binary);
|
||||
g_ptr_array_add (argv, (gpointer) teamd_binary);
|
||||
g_ptr_array_add (argv, (gpointer) "-o");
|
||||
g_ptr_array_add (argv, (gpointer) "-n");
|
||||
g_ptr_array_add (argv, (gpointer) "-U");
|
||||
|
|
|
|||
|
|
@ -42,13 +42,13 @@
|
|||
#include "nm-dhcp-dhclient-utils.h"
|
||||
#include "nm-dhcp-manager.h"
|
||||
#include "nm-posix-signals.h"
|
||||
#include "NetworkManagerUtils.h"
|
||||
|
||||
G_DEFINE_TYPE (NMDhcpDhclient, nm_dhcp_dhclient, NM_TYPE_DHCP_CLIENT)
|
||||
|
||||
#define NM_DHCP_DHCLIENT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DHCP_DHCLIENT, NMDhcpDhclientPrivate))
|
||||
|
||||
typedef struct {
|
||||
const char *path;
|
||||
char *conf_file;
|
||||
const char *def_leasefile;
|
||||
char *lease_file;
|
||||
|
|
@ -56,27 +56,13 @@ typedef struct {
|
|||
} NMDhcpDhclientPrivate;
|
||||
|
||||
const char *
|
||||
nm_dhcp_dhclient_get_path (const char *try_first)
|
||||
nm_dhcp_dhclient_get_path (void)
|
||||
{
|
||||
static const char *dhclient_paths[] = {
|
||||
"/sbin/dhclient",
|
||||
"/usr/sbin/dhclient",
|
||||
"/usr/pkg/sbin/dhclient",
|
||||
"/usr/local/sbin/dhclient",
|
||||
NULL
|
||||
};
|
||||
const char **path = dhclient_paths;
|
||||
const char *path = NULL;
|
||||
|
||||
if (strlen (try_first) && g_file_test (try_first, G_FILE_TEST_EXISTS))
|
||||
return try_first;
|
||||
|
||||
while (*path != NULL) {
|
||||
if (g_file_test (*path, G_FILE_TEST_EXISTS))
|
||||
break;
|
||||
path++;
|
||||
}
|
||||
|
||||
return *path;
|
||||
if (WITH_DHCLIENT)
|
||||
path = nm_utils_find_helper ("dhclient", DHCLIENT_PATH, NULL);
|
||||
return path;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -335,7 +321,7 @@ dhclient_start (NMDhcpClient *client,
|
|||
GPtrArray *argv = NULL;
|
||||
pid_t pid;
|
||||
GError *error = NULL;
|
||||
const char *iface, *uuid, *system_bus_address;
|
||||
const char *iface, *uuid, *system_bus_address, *dhclient_path = NULL;
|
||||
char *binary_name, *cmd_str, *pid_file = NULL, *system_bus_address_env = NULL;
|
||||
gboolean ipv6, success;
|
||||
guint log_domain;
|
||||
|
|
@ -349,8 +335,9 @@ dhclient_start (NMDhcpClient *client,
|
|||
|
||||
log_domain = ipv6 ? LOGD_DHCP6 : LOGD_DHCP4;
|
||||
|
||||
if (!g_file_test (priv->path, G_FILE_TEST_EXISTS)) {
|
||||
nm_log_warn (log_domain, "%s does not exist.", priv->path);
|
||||
dhclient_path = nm_dhcp_dhclient_get_path ();
|
||||
if (!dhclient_path) {
|
||||
nm_log_warn (log_domain, "dhclient could not be found");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
|
@ -359,7 +346,7 @@ dhclient_start (NMDhcpClient *client,
|
|||
iface);
|
||||
|
||||
/* Kill any existing dhclient from the pidfile */
|
||||
binary_name = g_path_get_basename (priv->path);
|
||||
binary_name = g_path_get_basename (dhclient_path);
|
||||
nm_dhcp_client_stop_existing (pid_file, binary_name);
|
||||
g_free (binary_name);
|
||||
|
||||
|
|
@ -411,7 +398,7 @@ dhclient_start (NMDhcpClient *client,
|
|||
}
|
||||
|
||||
argv = g_ptr_array_new ();
|
||||
g_ptr_array_add (argv, (gpointer) priv->path);
|
||||
g_ptr_array_add (argv, (gpointer) dhclient_path);
|
||||
|
||||
g_ptr_array_add (argv, (gpointer) "-d");
|
||||
|
||||
|
|
@ -608,8 +595,6 @@ nm_dhcp_dhclient_init (NMDhcpDhclient *self)
|
|||
NMDhcpDhclientPrivate *priv = NM_DHCP_DHCLIENT_GET_PRIVATE (self);
|
||||
const char **iter = &def_leasefiles[0];
|
||||
|
||||
priv->path = nm_dhcp_dhclient_get_path (DHCLIENT_PATH);
|
||||
|
||||
while (iter && *iter) {
|
||||
if (g_file_test (*iter, G_FILE_TEST_EXISTS)) {
|
||||
priv->def_leasefile = *iter;
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ GSList *nm_dhcp_dhclient_get_lease_ip_configs (const char *iface,
|
|||
const char *uuid,
|
||||
gboolean ipv6);
|
||||
|
||||
const char *nm_dhcp_dhclient_get_path (const char *try_first);
|
||||
const char *nm_dhcp_dhclient_get_path (void);
|
||||
|
||||
#endif /* __NETWORKMANAGER_DHCP_DHCLIENT_H__ */
|
||||
|
||||
|
|
|
|||
|
|
@ -37,38 +37,24 @@
|
|||
#include "nm-utils.h"
|
||||
#include "nm-logging.h"
|
||||
#include "nm-posix-signals.h"
|
||||
#include "NetworkManagerUtils.h"
|
||||
|
||||
G_DEFINE_TYPE (NMDhcpDhcpcd, nm_dhcp_dhcpcd, NM_TYPE_DHCP_CLIENT)
|
||||
|
||||
#define NM_DHCP_DHCPCD_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DHCP_DHCPCD, NMDhcpDhcpcdPrivate))
|
||||
|
||||
typedef struct {
|
||||
const char *path;
|
||||
char *pid_file;
|
||||
} NMDhcpDhcpcdPrivate;
|
||||
|
||||
const char *
|
||||
nm_dhcp_dhcpcd_get_path (const char *try_first)
|
||||
nm_dhcp_dhcpcd_get_path (void)
|
||||
{
|
||||
static const char *dhcpcd_paths[] = {
|
||||
"/sbin/dhcpcd",
|
||||
"/usr/sbin/dhcpcd",
|
||||
"/usr/pkg/sbin/dhcpcd",
|
||||
"/usr/local/sbin/dhcpcd",
|
||||
NULL
|
||||
};
|
||||
const char **path = dhcpcd_paths;
|
||||
const char *path = NULL;
|
||||
|
||||
if (strlen (try_first) && g_file_test (try_first, G_FILE_TEST_EXISTS))
|
||||
return try_first;
|
||||
|
||||
while (*path != NULL) {
|
||||
if (g_file_test (*path, G_FILE_TEST_EXISTS))
|
||||
break;
|
||||
path++;
|
||||
}
|
||||
|
||||
return *path;
|
||||
if (WITH_DHCPCD)
|
||||
path = nm_utils_find_helper ("dhcpcd", DHCPCD_PATH, NULL);
|
||||
return path;
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -96,7 +82,7 @@ ip4_start (NMDhcpClient *client,
|
|||
pid_t pid = -1;
|
||||
GError *error = NULL;
|
||||
char *pid_contents = NULL, *binary_name, *cmd_str;
|
||||
const char *iface;
|
||||
const char *iface, *dhcpcd_path = NULL;
|
||||
|
||||
g_return_val_if_fail (priv->pid_file == NULL, FALSE);
|
||||
|
||||
|
|
@ -107,18 +93,19 @@ ip4_start (NMDhcpClient *client,
|
|||
*/
|
||||
priv->pid_file = g_strdup_printf (RUNDIR "/dhcpcd-%s.pid", iface);
|
||||
|
||||
if (!g_file_test (priv->path, G_FILE_TEST_EXISTS)) {
|
||||
nm_log_warn (LOGD_DHCP4, "%s does not exist.", priv->path);
|
||||
dhcpcd_path = nm_dhcp_dhcpcd_get_path ();
|
||||
if (!dhcpcd_path) {
|
||||
nm_log_warn (LOGD_DHCP4, "dhcpcd could not be found");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Kill any existing dhcpcd from the pidfile */
|
||||
binary_name = g_path_get_basename (priv->path);
|
||||
binary_name = g_path_get_basename (dhcpcd_path);
|
||||
nm_dhcp_client_stop_existing (priv->pid_file, binary_name);
|
||||
g_free (binary_name);
|
||||
|
||||
argv = g_ptr_array_new ();
|
||||
g_ptr_array_add (argv, (gpointer) priv->path);
|
||||
g_ptr_array_add (argv, (gpointer) dhcpcd_path);
|
||||
|
||||
g_ptr_array_add (argv, (gpointer) "-B"); /* Don't background on lease (disable fork()) */
|
||||
|
||||
|
|
@ -202,9 +189,6 @@ stop (NMDhcpClient *client, gboolean release, const GByteArray *duid)
|
|||
static void
|
||||
nm_dhcp_dhcpcd_init (NMDhcpDhcpcd *self)
|
||||
{
|
||||
NMDhcpDhcpcdPrivate *priv = NM_DHCP_DHCPCD_GET_PRIVATE (self);
|
||||
|
||||
priv->path = nm_dhcp_dhcpcd_get_path (DHCPCD_PATH);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ typedef struct {
|
|||
|
||||
GType nm_dhcp_dhcpcd_get_type (void);
|
||||
|
||||
const char *nm_dhcp_dhcpcd_get_path (const char *try_first);
|
||||
const char *nm_dhcp_dhcpcd_get_path (void);
|
||||
|
||||
#endif /* __NETWORKMANAGER_DHCP_DHCPCD_H__ */
|
||||
|
||||
|
|
|
|||
|
|
@ -285,23 +285,16 @@ dis_connection_cb (NMDBusManager *mgr,
|
|||
static GType
|
||||
get_client_type (const char *client, GError **error)
|
||||
{
|
||||
const char *dhclient_path = NULL;
|
||||
const char *dhcpcd_path = NULL;
|
||||
gboolean use_dhclient, use_dhcpcd;
|
||||
|
||||
/* If a client was disabled at build-time, its *_PATH define will be
|
||||
* an empty string.
|
||||
*/
|
||||
/* coverity[array_null] */
|
||||
if (DHCLIENT_PATH && strlen (DHCLIENT_PATH))
|
||||
dhclient_path = nm_dhcp_dhclient_get_path (DHCLIENT_PATH);
|
||||
/* coverity[array_null] */
|
||||
if (DHCPCD_PATH && strlen (DHCPCD_PATH))
|
||||
dhcpcd_path = nm_dhcp_dhcpcd_get_path (DHCPCD_PATH);
|
||||
/* If a client was disabled at build-time, these will return FALSE */
|
||||
use_dhclient = !!nm_dhcp_dhclient_get_path ();
|
||||
use_dhcpcd = !!nm_dhcp_dhcpcd_get_path ();
|
||||
|
||||
if (!client) {
|
||||
if (dhclient_path)
|
||||
if (use_dhclient)
|
||||
return NM_TYPE_DHCP_DHCLIENT;
|
||||
else if (dhcpcd_path)
|
||||
else if (use_dhcpcd)
|
||||
return NM_TYPE_DHCP_DHCPCD;
|
||||
else {
|
||||
g_set_error_literal (error,
|
||||
|
|
@ -312,20 +305,20 @@ get_client_type (const char *client, GError **error)
|
|||
}
|
||||
|
||||
if (!strcmp (client, "dhclient")) {
|
||||
if (!dhclient_path) {
|
||||
if (!use_dhclient) {
|
||||
g_set_error_literal (error,
|
||||
NM_DHCP_MANAGER_ERROR, NM_DHCP_MANAGER_ERROR_BAD_CLIENT,
|
||||
_("'dhclient' could be found."));
|
||||
_("'dhclient' could not be found or was disabled."));
|
||||
return G_TYPE_INVALID;
|
||||
}
|
||||
return NM_TYPE_DHCP_DHCLIENT;
|
||||
}
|
||||
|
||||
if (!strcmp (client, "dhcpcd")) {
|
||||
if (!dhcpcd_path) {
|
||||
if (!use_dhcpcd) {
|
||||
g_set_error_literal (error,
|
||||
NM_DHCP_MANAGER_ERROR, NM_DHCP_MANAGER_ERROR_BAD_CLIENT,
|
||||
_("'dhcpcd' could be found."));
|
||||
_("'dhcpcd' could not be found or was disabled."));
|
||||
return G_TYPE_INVALID;
|
||||
}
|
||||
return NM_TYPE_DHCP_DHCPCD;
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@
|
|||
#include "nm-ip4-config.h"
|
||||
#include "nm-ip6-config.h"
|
||||
#include "nm-dns-utils.h"
|
||||
#include "NetworkManagerUtils.h"
|
||||
|
||||
G_DEFINE_TYPE (NMDnsDnsmasq, nm_dns_dnsmasq, NM_TYPE_DNS_PLUGIN)
|
||||
|
||||
|
|
@ -50,26 +51,6 @@ typedef struct {
|
|||
|
||||
/*******************************************/
|
||||
|
||||
static inline const char *
|
||||
find_dnsmasq (void)
|
||||
{
|
||||
static const char *paths[] = {
|
||||
DNSMASQ_PATH,
|
||||
"/usr/local/sbin/dnsmasq",
|
||||
"/usr/sbin/dnsmasq",
|
||||
"/sbin/dnsmasq",
|
||||
NULL
|
||||
};
|
||||
const char **binary = paths;
|
||||
|
||||
while (*binary != NULL) {
|
||||
if (**binary && g_file_test (*binary, G_FILE_TEST_EXISTS))
|
||||
return *binary;
|
||||
binary++;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
add_ip4_config (GString *str, NMIP4Config *ip4, gboolean split)
|
||||
{
|
||||
|
|
@ -225,6 +206,7 @@ update (NMDnsPlugin *plugin,
|
|||
const char *hostname)
|
||||
{
|
||||
NMDnsDnsmasq *self = NM_DNS_DNSMASQ (plugin);
|
||||
const char *dm_binary;
|
||||
GString *conf;
|
||||
GSList *iter;
|
||||
const char *argv[15];
|
||||
|
|
@ -240,6 +222,12 @@ update (NMDnsPlugin *plugin,
|
|||
*/
|
||||
nm_dns_plugin_child_kill (plugin);
|
||||
|
||||
dm_binary = nm_utils_find_helper ("dnsmasq", DNSMASQ_PATH, NULL);
|
||||
if (!dm_binary) {
|
||||
nm_log_warn (LOGD_DNS, "Could not find dnsmasq binary");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Build up the new dnsmasq config file */
|
||||
conf = g_string_sized_new (150);
|
||||
|
||||
|
|
@ -281,7 +269,7 @@ update (NMDnsPlugin *plugin,
|
|||
nm_log_dbg (LOGD_DNS, "dnsmasq local caching DNS configuration:");
|
||||
nm_log_dbg (LOGD_DNS, "%s", conf->str);
|
||||
|
||||
argv[idx++] = find_dnsmasq ();
|
||||
argv[idx++] = dm_binary;
|
||||
argv[idx++] = "--no-resolv"; /* Use only commandline */
|
||||
argv[idx++] = "--keep-in-foreground";
|
||||
argv[idx++] = "--no-hosts"; /* don't use /etc/hosts to resolve */
|
||||
|
|
|
|||
|
|
@ -169,27 +169,6 @@ nm_cmd_line_add_string (NMCmdLine *cmd, const char *str)
|
|||
|
||||
/*******************************************/
|
||||
|
||||
static inline const char *
|
||||
nm_find_dnsmasq (void)
|
||||
{
|
||||
static const char *dnsmasq_binary_paths[] = {
|
||||
DNSMASQ_PATH,
|
||||
"/usr/local/sbin/dnsmasq",
|
||||
"/usr/sbin/dnsmasq",
|
||||
"/sbin/dnsmasq",
|
||||
NULL
|
||||
};
|
||||
const char **dnsmasq_binary = dnsmasq_binary_paths;
|
||||
|
||||
while (*dnsmasq_binary != NULL) {
|
||||
if (**dnsmasq_binary && g_file_test (*dnsmasq_binary, G_FILE_TEST_EXISTS))
|
||||
break;
|
||||
dnsmasq_binary++;
|
||||
}
|
||||
|
||||
return *dnsmasq_binary;
|
||||
}
|
||||
|
||||
static void
|
||||
dm_exit_code (guint dm_exit_status)
|
||||
{
|
||||
|
|
@ -250,7 +229,6 @@ create_dm_cmd_line (const char *iface,
|
|||
const char *pidfile,
|
||||
GError **error)
|
||||
{
|
||||
const char *dm_binary;
|
||||
NMCmdLine *cmd;
|
||||
GString *s;
|
||||
const NMPlatformIP4Address *tmp;
|
||||
|
|
@ -258,16 +236,11 @@ create_dm_cmd_line (const char *iface,
|
|||
char last[INET_ADDRSTRLEN];
|
||||
char localaddr[INET_ADDRSTRLEN];
|
||||
char *error_desc = NULL;
|
||||
const char *dm_binary;
|
||||
|
||||
dm_binary = nm_find_dnsmasq ();
|
||||
if (!dm_binary) {
|
||||
g_set_error_literal (error, NM_DNSMASQ_MANAGER_ERROR, NM_DNSMASQ_MANAGER_ERROR_NOT_FOUND,
|
||||
"Could not find dnsmasq binary.");
|
||||
dm_binary = nm_utils_find_helper ("dnsmasq", DNSMASQ_PATH, error);
|
||||
if (!dm_binary)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Find the IP4 address to use */
|
||||
tmp = nm_ip4_config_get_address (ip4_config, 0);
|
||||
|
||||
/* Create dnsmasq command line */
|
||||
cmd = nm_cmd_line_new ();
|
||||
|
|
@ -298,6 +271,9 @@ create_dm_cmd_line (const char *iface,
|
|||
*/
|
||||
nm_cmd_line_add_string (cmd, "--strict-order");
|
||||
|
||||
/* Find the IP4 address to use */
|
||||
tmp = nm_ip4_config_get_address (ip4_config, 0);
|
||||
|
||||
s = g_string_new ("--listen-address=");
|
||||
nm_utils_inet4_ntop (tmp->address, localaddr);
|
||||
g_string_append (s, localaddr);
|
||||
|
|
@ -311,7 +287,8 @@ create_dm_cmd_line (const char *iface,
|
|||
error_desc);
|
||||
nm_log_warn (LOGD_SHARING, "Failed to find DHCP address ranges: %s", error_desc);
|
||||
g_free (error_desc);
|
||||
goto error;
|
||||
nm_cmd_line_destroy (cmd);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
s = g_string_new ("--dhcp-range=");
|
||||
|
|
@ -332,10 +309,6 @@ create_dm_cmd_line (const char *iface,
|
|||
g_string_free (s, TRUE);
|
||||
|
||||
return cmd;
|
||||
|
||||
error:
|
||||
nm_cmd_line_destroy (cmd);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
|||
39
src/nm-dcb.c
39
src/nm-dcb.c
|
|
@ -296,47 +296,20 @@ _fcoe_cleanup (const char *iface,
|
|||
return do_helper (NULL, FCOEADM, run_func, user_data, error, "-d %s", iface);
|
||||
}
|
||||
|
||||
|
||||
static const char *dcbpaths[] = {
|
||||
"/sbin/dcbtool",
|
||||
"/usr/sbin/dcbtool",
|
||||
"/usr/local/sbin/dcbtool",
|
||||
NULL
|
||||
};
|
||||
static const char *fcoepaths[] = {
|
||||
"/sbin/fcoeadm",
|
||||
"/usr/sbin/fcoeadm",
|
||||
"/usr/local/sbin/fcoeadm",
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
static gboolean
|
||||
run_helper (char **argv, guint which, gpointer user_data, GError **error)
|
||||
{
|
||||
static const char *helper_path[2] = { NULL, NULL };
|
||||
const char *helper_path;
|
||||
int exit_status = 0;
|
||||
gboolean success;
|
||||
char *errmsg = NULL, *outmsg = NULL;
|
||||
const char **iter;
|
||||
char *cmdline;
|
||||
|
||||
if (G_UNLIKELY (helper_path[which] == NULL)) {
|
||||
iter = (which == DCBTOOL) ? dcbpaths : fcoepaths;
|
||||
while (*iter) {
|
||||
if (g_file_test (*iter, G_FILE_TEST_EXISTS))
|
||||
helper_path[which] = *iter;
|
||||
iter++;
|
||||
}
|
||||
if (!helper_path[which]) {
|
||||
g_set_error (error, NM_DCB_ERROR, NM_DCB_ERROR_HELPER_NOT_FOUND,
|
||||
"%s not found",
|
||||
which == DCBTOOL ? "dcbtool" : "fcoadm");
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
helper_path = nm_utils_find_helper ((which == DCBTOOL) ? "dcbtool" : "fcoeadm", NULL, error);
|
||||
if (!helper_path)
|
||||
return FALSE;
|
||||
|
||||
argv[0] = (char *) helper_path[which];
|
||||
argv[0] = (char *) helper_path;
|
||||
cmdline = g_strjoinv (" ", argv);
|
||||
nm_log_dbg (LOGD_DCB, "%s", cmdline);
|
||||
|
||||
|
|
@ -359,9 +332,9 @@ run_helper (char **argv, guint which, gpointer user_data, GError **error)
|
|||
success = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
g_free (outmsg);
|
||||
g_free (errmsg);
|
||||
|
||||
g_free (cmdline);
|
||||
return success;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -751,36 +751,6 @@ nm_cmd_line_add_int (NMCmdLine *cmd, int i)
|
|||
|
||||
/*******************************************/
|
||||
|
||||
static const char *pppd_binary_paths[] = {
|
||||
PPPD_PATH,
|
||||
"/usr/local/sbin/pppd",
|
||||
"/usr/sbin/pppd",
|
||||
"/sbin/pppd",
|
||||
NULL
|
||||
};
|
||||
|
||||
static const char *pppoe_binary_paths[] = {
|
||||
PPPOE_PATH,
|
||||
"/usr/local/sbin/pppoe",
|
||||
"/usr/sbin/pppoe",
|
||||
"/sbin/pppoe",
|
||||
NULL
|
||||
};
|
||||
|
||||
static inline const char *
|
||||
nm_find_binary (const char *paths[])
|
||||
{
|
||||
const char **binary = paths;
|
||||
|
||||
while (*binary != NULL) {
|
||||
if (**binary && g_file_test (*binary, G_FILE_TEST_EXISTS))
|
||||
break;
|
||||
binary++;
|
||||
}
|
||||
|
||||
return *binary;
|
||||
}
|
||||
|
||||
static void
|
||||
ppp_exit_code (guint pppd_exit_status, GPid pid)
|
||||
{
|
||||
|
|
@ -900,27 +870,21 @@ create_pppd_cmd_line (NMPPPManager *self,
|
|||
GError **err)
|
||||
{
|
||||
NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (self);
|
||||
const char *pppd_binary, *pppoe_binary = NULL;
|
||||
const char *pppd_binary = NULL, *pppoe_binary = NULL;
|
||||
NMCmdLine *cmd;
|
||||
gboolean ppp_debug;
|
||||
|
||||
g_return_val_if_fail (setting != NULL, NULL);
|
||||
|
||||
pppd_binary = nm_find_binary (pppd_binary_paths);
|
||||
if (!pppd_binary) {
|
||||
g_set_error (err, NM_PPP_MANAGER_ERROR, NM_PPP_MANAGER_ERROR,
|
||||
"Could not find pppd binary.");
|
||||
pppd_binary = nm_utils_find_helper ("pppd", NULL, err);
|
||||
if (!pppd_binary)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ( pppoe
|
||||
|| (adsl && strcmp (nm_setting_adsl_get_protocol (adsl), NM_SETTING_ADSL_PROTOCOL_PPPOE))) {
|
||||
pppoe_binary = nm_find_binary (pppoe_binary_paths);
|
||||
if (!pppoe_binary) {
|
||||
g_set_error (err, NM_PPP_MANAGER_ERROR, NM_PPP_MANAGER_ERROR,
|
||||
"Could not find pppoe binary.");
|
||||
pppoe_binary = nm_utils_find_helper ("pppoe", NULL, err);
|
||||
if (!pppoe_binary)
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* Create pppd command line */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue