From 7fc8d0884c86eb76efecbc6e96a5ba4287dbc0e8 Mon Sep 17 00:00:00 2001 From: Derek Dai Date: Mon, 15 Aug 2016 11:15:12 +0800 Subject: [PATCH 1/2] add debian support to miracle-utils.sh and normal-wifi.sh --- README.md | 2 +- res/miracle-utils.sh | 10 ++++++++-- res/normal-wifi.sh | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 0e03657..06678d7 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,7 @@ If you feel confidence enough (since systemd is the entrypoint for an OS) extrac Steps to use it as sink: - 1. shutdown wpa_supplicant + 1. shutdown wpa_supplicant and NetworkManager $ sudo kill -9 $(ps -ef | grep wpa_supplican[t] | awk '{print $2}') # now you can use `res/kill-wpa.sh` diff --git a/res/miracle-utils.sh b/res/miracle-utils.sh index 577fe41..e938055 100755 --- a/res/miracle-utils.sh +++ b/res/miracle-utils.sh @@ -113,12 +113,18 @@ function check_archlinux_distro { function check_ubuntu_distro { cat /proc/version | grep -i ubuntu } +# +# checking if distro is debian +# +function check_debian_distro { + cat /proc/version | grep -i debian +} # # ubuntu manager restarts automatically wpa_supplicant # function kill_ubuntu_network_manager { - if check_ubuntu_distro + if check_ubuntu_distro || check_debian_distro then echo stopping NetworkManager sudo service NetworkManager stop @@ -140,7 +146,7 @@ function kill_archlinux_network_manager { # start ubuntu manager # function start_ubuntu_network_manager { - if check_ubuntu_distro + if check_ubuntu_distro || check_debian_distro then echo starting NetworkManager sudo service NetworkManager start diff --git a/res/normal-wifi.sh b/res/normal-wifi.sh index 230f4db..1e03201 100755 --- a/res/normal-wifi.sh +++ b/res/normal-wifi.sh @@ -47,7 +47,7 @@ CONFIG_FILE=${1:-/run/network/wpa_supplicant_${ETHERNAME}.conf} echo starting wpa_supplicant for normal connection -if check_ubuntu_distro +if check_ubuntu_distro || check_debian_distro then start_ubuntu_network_manager sudo wpa_supplicant -B -u -s -O /var/run/wpa_supplicant From 4601514799e4b1e017d5c723e69a4fbbefd693e7 Mon Sep 17 00:00:00 2001 From: Derek Dai Date: Mon, 15 Aug 2016 17:35:38 +0800 Subject: [PATCH 2/2] find wpa_supplicant through PATH instead of option --wpa-bindir --- src/wifi/wifid-supplicant.c | 56 ++++++++++++++++++++++++++++++++----- src/wifi/wifid.c | 7 ----- src/wifi/wifid.h | 1 - 3 files changed, 49 insertions(+), 15 deletions(-) diff --git a/src/wifi/wifid-supplicant.c b/src/wifi/wifid-supplicant.c index e05a0cc..305b4bd 100644 --- a/src/wifi/wifid-supplicant.c +++ b/src/wifi/wifid-supplicant.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -2401,6 +2402,49 @@ static void supplicant_run(struct supplicant *s, const char *binary) execve(argv[0], argv, environ); } +static int supplicant_find(char **binary) +{ + _shl_free_ char *path = getenv("PATH"); + if(!path) { + return -EINVAL; + } + + path = strdup(path); + if(!path) { + return log_ENOMEM(); + } + + struct stat bin_stat; + char *curr = path, *next; + while(1) { + curr = strtok_r(curr, ":", &next); + if(!curr) { + break; + } + + _shl_free_ char *bin = shl_strcat(curr, "/wpa_supplicant"); + if (!bin) + return log_ENOMEM(); + + if(stat(bin, &bin_stat) < 0) { + if(ENOENT == errno) { + goto end; + } + return log_ERRNO(); + } + + if (!access(bin, X_OK)) { + *binary = strdup(bin); + return 0; + } + +end: + curr = NULL; + } + + return -EINVAL; +} + static int supplicant_spawn(struct supplicant *s) { _shl_free_ char *binary = NULL; @@ -2414,14 +2458,12 @@ static int supplicant_spawn(struct supplicant *s) log_debug("spawn supplicant of %s", s->l->ifname); - binary = shl_strcat(arg_wpa_bindir, "/wpa_supplicant"); - if (!binary) - return log_ENOMEM(); + if (supplicant_find(&binary) < 0) { + log_error("execution of wpas (%s) not possible: %m", binary); + return -EINVAL; + } - if (access(binary, X_OK) < 0) { - log_error("execution of wpas (%s) not possible: %m", binary); - return -EINVAL; - } + log_info("wpa_supplicant found: %s", binary); pid = fork(); if (pid < 0) { diff --git a/src/wifi/wifid.c b/src/wifi/wifid.c index 9bfd2a8..9533206 100644 --- a/src/wifi/wifid.c +++ b/src/wifi/wifid.c @@ -40,7 +40,6 @@ #include "wifid.h" #include "config.h" -const char *arg_wpa_bindir = "/usr/bin"; const char *interface_name = NULL; unsigned int arg_wpa_loglevel = LOG_NOTICE; @@ -457,7 +456,6 @@ static int help(void) "\n" " -i --interface Choose the interface to use\n" "\n" - " --wpa-bindir wpa_supplicant binary dir [/usr/bin]\n" " --wpa-loglevel