eiwd

no dbus iwd with iwctl functionality
git clone https://git.daat.foo/repos/eiwd.git
Log | Files | Refs | Submodules | README | LICENSE

commit f6bb911d2cba1e232f3406078b8577dfec1bf57c
parent a6e8622677ff861bbc154c04a6faa26fc499d3c9
Author: Denis Kenzior <denkenz@gmail.com>
Date:   Wed,  7 Aug 2019 10:46:30 -0500

resolve: Search more places for resolvconf exe

Some distros put resolvconf in /usr/sbin instead of /sbin.  Do not try
to hard-code the path and instead search for it in more places.

Diffstat:
Msrc/resolve.c | 36++++++++++++++++++++----------------
1 file changed, 20 insertions(+), 16 deletions(-)

diff --git a/src/resolve.c b/src/resolve.c @@ -28,6 +28,7 @@ #include <arpa/inet.h> #include <sys/stat.h> #include <stdio.h> +#include <unistd.h> #include <ell/ell.h> @@ -49,6 +50,7 @@ struct resolve_method { }; static struct resolve_method method; +static char *RESOLVCONF_PATH; #define SYSTEMD_RESOLVED_SERVICE "org.freedesktop.resolve1" #define SYSTEMD_RESOLVED_MANAGER_PATH "/org/freedesktop/resolve1" @@ -242,8 +244,6 @@ static const struct resolve_method_ops resolve_method_systemd = { .remove = resolve_systemd_remove, }; -#define RESOLVCONF_PATH "/sbin/resolvconf" - static void resolve_resolvconf_add_dns(uint32_t ifindex, uint8_t type, char **dns_list, void *data) { @@ -257,7 +257,7 @@ static void resolve_resolvconf_add_dns(uint32_t ifindex, uint8_t type, if (!*ready) return; - cmd = l_strdup_printf(RESOLVCONF_PATH " -a %u", ifindex); + cmd = l_strdup_printf("%s -a %u", RESOLVCONF_PATH, ifindex); if (!(resolvconf = popen(cmd, "w"))) { l_error("resolve: Failed to start %s (%s).", RESOLVCONF_PATH, @@ -295,7 +295,7 @@ static void resolve_resolvconf_remove(uint32_t ifindex, void *data) if (!*ready) return; - cmd = l_strdup_printf(RESOLVCONF_PATH " -d %u", ifindex); + cmd = l_strdup_printf("%s -d %u", RESOLVCONF_PATH, ifindex); if (!(resolvconf = popen(cmd, "r"))) { l_error("resolve: Failed to start %s (%s).", RESOLVCONF_PATH, @@ -314,34 +314,38 @@ static void resolve_resolvconf_remove(uint32_t ifindex, void *data) static void *resolve_resolvconf_init(void) { - struct stat st; + static const char *default_path = "/sbin:/usr/sbin"; bool *ready; + const char *path; ready = l_new(bool, 1); + *ready = false; - if (stat(RESOLVCONF_PATH, &st)) { - l_error("resolve: Could not stat %s (%s).", RESOLVCONF_PATH, - strerror(errno)); - goto error; + l_debug("Trying to find resolvconf in $PATH"); + path = getenv("PATH"); + if (path) + RESOLVCONF_PATH = l_path_find("resolvconf", path, X_OK); + + if (!RESOLVCONF_PATH) { + l_debug("Trying to find resolvconf in default paths"); + RESOLVCONF_PATH = l_path_find("resolvconf", default_path, X_OK); } - if (!(st.st_mode & S_IXUSR)) { - l_error("resolve: %s is not executable.", RESOLVCONF_PATH); - goto error; + if (!RESOLVCONF_PATH) { + l_error("No usable resolvconf found on system"); + return ready; } + l_debug("resolvconf found as: %s", RESOLVCONF_PATH); *ready = true; return ready; - -error: - *ready = false; - return ready; } static void resolve_resolvconf_exit(void *data) { bool *ready = data; + RESOLVCONF_PATH = NULL; l_free(ready); }