mirror of
https://github.com/albfan/miraclecast.git
synced 2025-03-09 23:38:56 +00:00
find wpa_supplicant through PATH instead of option --wpa-bindir
This commit is contained in:
parent
7fc8d0884c
commit
4601514799
3 changed files with 49 additions and 15 deletions
|
@ -24,6 +24,7 @@
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <systemd/sd-event.h>
|
#include <systemd/sd-event.h>
|
||||||
#include <systemd/sd-journal.h>
|
#include <systemd/sd-journal.h>
|
||||||
|
@ -2401,6 +2402,49 @@ static void supplicant_run(struct supplicant *s, const char *binary)
|
||||||
execve(argv[0], argv, environ);
|
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)
|
static int supplicant_spawn(struct supplicant *s)
|
||||||
{
|
{
|
||||||
_shl_free_ char *binary = NULL;
|
_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);
|
log_debug("spawn supplicant of %s", s->l->ifname);
|
||||||
|
|
||||||
binary = shl_strcat(arg_wpa_bindir, "/wpa_supplicant");
|
if (supplicant_find(&binary) < 0) {
|
||||||
if (!binary)
|
log_error("execution of wpas (%s) not possible: %m", binary);
|
||||||
return log_ENOMEM();
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
if (access(binary, X_OK) < 0) {
|
log_info("wpa_supplicant found: %s", binary);
|
||||||
log_error("execution of wpas (%s) not possible: %m", binary);
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
pid = fork();
|
pid = fork();
|
||||||
if (pid < 0) {
|
if (pid < 0) {
|
||||||
|
|
|
@ -40,7 +40,6 @@
|
||||||
#include "wifid.h"
|
#include "wifid.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
const char *arg_wpa_bindir = "/usr/bin";
|
|
||||||
const char *interface_name = NULL;
|
const char *interface_name = NULL;
|
||||||
unsigned int arg_wpa_loglevel = LOG_NOTICE;
|
unsigned int arg_wpa_loglevel = LOG_NOTICE;
|
||||||
|
|
||||||
|
@ -457,7 +456,6 @@ static int help(void)
|
||||||
"\n"
|
"\n"
|
||||||
" -i --interface Choose the interface to use\n"
|
" -i --interface Choose the interface to use\n"
|
||||||
"\n"
|
"\n"
|
||||||
" --wpa-bindir <dir> wpa_supplicant binary dir [/usr/bin]\n"
|
|
||||||
" --wpa-loglevel <lvl wpa_supplicant log-level\n"
|
" --wpa-loglevel <lvl wpa_supplicant log-level\n"
|
||||||
, program_invocation_short_name);
|
, program_invocation_short_name);
|
||||||
/*
|
/*
|
||||||
|
@ -475,7 +473,6 @@ static int parse_argv(int argc, char *argv[])
|
||||||
ARG_LOG_LEVEL,
|
ARG_LOG_LEVEL,
|
||||||
ARG_LOG_TIME,
|
ARG_LOG_TIME,
|
||||||
|
|
||||||
ARG_WPA_BINDIR,
|
|
||||||
ARG_WPA_LOGLEVEL,
|
ARG_WPA_LOGLEVEL,
|
||||||
};
|
};
|
||||||
static const struct option options[] = {
|
static const struct option options[] = {
|
||||||
|
@ -484,7 +481,6 @@ static int parse_argv(int argc, char *argv[])
|
||||||
{ "log-level", required_argument, NULL, ARG_LOG_LEVEL },
|
{ "log-level", required_argument, NULL, ARG_LOG_LEVEL },
|
||||||
{ "log-time", no_argument, NULL, ARG_LOG_TIME },
|
{ "log-time", no_argument, NULL, ARG_LOG_TIME },
|
||||||
|
|
||||||
{ "wpa-bindir", required_argument, NULL, ARG_WPA_BINDIR },
|
|
||||||
{ "wpa-loglevel", required_argument, NULL, ARG_WPA_LOGLEVEL },
|
{ "wpa-loglevel", required_argument, NULL, ARG_WPA_LOGLEVEL },
|
||||||
{ "interface", required_argument, NULL, 'i' },
|
{ "interface", required_argument, NULL, 'i' },
|
||||||
{}
|
{}
|
||||||
|
@ -508,9 +504,6 @@ static int parse_argv(int argc, char *argv[])
|
||||||
log_init_time();
|
log_init_time();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ARG_WPA_BINDIR:
|
|
||||||
arg_wpa_bindir = optarg;
|
|
||||||
break;
|
|
||||||
case ARG_WPA_LOGLEVEL:
|
case ARG_WPA_LOGLEVEL:
|
||||||
arg_wpa_loglevel = log_parse_arg(optarg);
|
arg_wpa_loglevel = log_parse_arg(optarg);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -203,7 +203,6 @@ void manager_dbus_disconnect(struct manager *m);
|
||||||
|
|
||||||
/* cli arguments */
|
/* cli arguments */
|
||||||
|
|
||||||
extern const char *arg_wpa_bindir;
|
|
||||||
extern unsigned int arg_wpa_loglevel;
|
extern unsigned int arg_wpa_loglevel;
|
||||||
|
|
||||||
#endif /* WIFID_H */
|
#endif /* WIFID_H */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue