From f3f63715dc41288b4bd6bcf346d7429c650ed5d2 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 5 Nov 2003 22:04:26 +0000 Subject: exec fixes git-svn-id: file:///home/lennart/svn/public/waproamd/trunk@31 022f378f-78c4-0310-b860-d162c87e6274 --- configure.ac | 3 ++- src/exec.c | 19 ++++++++++++------- src/waproamd.c | 40 +++++++++++++++++++++++----------------- 3 files changed, 37 insertions(+), 25 deletions(-) diff --git a/configure.ac b/configure.ac index c3540d4..bbbcc66 100644 --- a/configure.ac +++ b/configure.ac @@ -20,7 +20,7 @@ # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. AC_PREREQ(2.57) -AC_INIT([waproamd], [0.3b], [mzjncebnzq (at) 0pointer (dot) de]) +AC_INIT([waproamd], [0.4], [mzjncebnzq (at) 0pointer (dot) de]) AC_CONFIG_SRCDIR([src/waproamd.c]) AC_CONFIG_HEADERS([config.h]) AM_INIT_AUTOMAKE([foreign -Wall]) @@ -48,6 +48,7 @@ AC_HEADER_SYS_WAIT AC_CHECK_HEADERS([fcntl.h limits.h stdint.h stdlib.h string.h sys/ioctl.h sys/socket.h unistd.h]) AC_CHECK_LIB([daemon], [daemon_fork],, [AC_MSG_ERROR([*** Sorry, you have to install libdaemon ***])]) +AC_CHECK_LIB([daemon], [daemon_pid_file_kill_wait],, [AC_MSG_WARN([*** libdaemon too old, --wait-on-kill is not going to be supported. Consider updating to libdaemon 0.3. ***])]) AC_C_CONST AC_TYPE_MODE_T diff --git a/src/exec.c b/src/exec.c index f2a37ef..80b60ec 100644 --- a/src/exec.c +++ b/src/exec.c @@ -55,8 +55,12 @@ int log_exec(const char *dir, const char *prog, const char *arg) { return -1; } else if (pid == 0) { - dup2(p[1], 1); - dup2(p[1], 2); + + if (p[1] != 1) + dup2(p[1], 1); + + if (p[1] != 2) + dup2(p[1], 2); if (p[0] > 2) close(p[0]); @@ -65,16 +69,19 @@ int log_exec(const char *dir, const char *prog, const char *arg) { close(p[1]); close(0); - open("/dev/null", O_RDONLY); + if (open("/dev/null", O_RDONLY) != 0) { + daemon_log(LOG_ERR, "Unable to open /dev/null as STDIN"); + _exit(EXIT_FAILURE); + } - umask(0022); // Set up a sane umask + umask(0022); /* Set up a sane umask */ if (dir && chdir(dir) < 0) { daemon_log(LOG_WARNING, "Failed to change to directory '%s'", dir); chdir("/"); } - execl(prog, prog, arg, 0); + execl(prog, prog, arg, (char*) 0); daemon_log(LOG_ERR, "execl(%s) failed: %s\n", prog, strerror(errno)); @@ -134,8 +141,6 @@ int log_exec(const char *dir, const char *prog, const char *arg) { daemon_log(LOG_WARNING, "Killing child."); kill(pid, SIGTERM); } - - break; } } diff --git a/src/waproamd.c b/src/waproamd.c index 33df905..96bc0bd 100644 --- a/src/waproamd.c +++ b/src/waproamd.c @@ -64,16 +64,12 @@ char log_ident[32], pid_ident[32]; int issue_scan(struct interface *i) { - //daemon_log(LOG_ERR, "Scanning...\n"); - - if (iw_set_mode(i, IW_MODE_INFRA) < 0) - return -1; + /* daemon_log(LOG_ERR, "Scanning...\n"); */ -/* if (iw_set_ap(i, &null_ap) < 0) */ -/* return -1; */ - - if (iw_set_essid(i, NULL) < 0) - return -1; + /* Due to driver issues, the return codes of these function calls are no longer evaluated */ + iw_set_mode(i, IW_MODE_INFRA); + iw_set_ap(i, &null_ap); + iw_set_essid(i, NULL); if (iw_scan(i) < 0) return -1; @@ -81,7 +77,7 @@ int issue_scan(struct interface *i) { return 0; } -void get_script_path(char *path, int l, struct hw_addr *ap) { +void get_script_path(char *path, int l, struct hw_addr *ap, int uc) { assert(path && l); if (!ap) { @@ -89,7 +85,7 @@ void get_script_path(char *path, int l, struct hw_addr *ap) { return; } - snprintf(path, l, "%s/%02x:%02x:%02x:%02x:%02x:%02x", + snprintf(path, l, uc ? "%s/%02X:%02X:%02X:%02X:%02X:%02X": "%s/%02x:%02x:%02x:%02x:%02x:%02x", SCRIPTDIR, ap->addr[0], ap->addr[1], ap->addr[2], ap->addr[3], ap->addr[4], ap->addr[5]); @@ -104,8 +100,11 @@ static int scan_result_cb(struct ap_info*ap) { char path[PATH_MAX]; assert(ap); - get_script_path(path, sizeof(path), &ap->ap); - b = access(path, X_OK) == 0; + get_script_path(path, sizeof(path), &ap->ap, 0); + if (!(b = !access(path, X_OK))) { + get_script_path(path, sizeof(path), &ap->ap, 1); + b = !access(path, X_OK); + } if (selected_ap_valid) { @@ -138,10 +137,14 @@ int read_scan(struct interface *i, struct ap_info **ap) { int run_script(struct hw_addr *ap, const char *arg) { char path[PATH_MAX]; - get_script_path(path, sizeof(path), ap); + get_script_path(path, sizeof(path), ap, 0); - if (access(path, X_OK) < 0) - get_script_path(path, sizeof(path), NULL); + if (access(path, X_OK) < 0) { + get_script_path(path, sizeof(path), ap, 1); + + if (access(path, X_OK) < 0) + get_script_path(path, sizeof(path), NULL, 0); + } return log_exec(SCRIPTDIR, path, arg); }; @@ -218,7 +221,7 @@ int go(struct interface *i) { goto finish; } - if (daemon_signal_init(SIGINT, SIGTERM, SIGQUIT, SIGHUP, -1) < 0) { + if (daemon_signal_init(SIGINT, SIGTERM, SIGQUIT, SIGHUP, SIGCHLD, -1) < 0) { daemon_log(LOG_ERR, "Could not register signal handler: %s", strerror(errno)); goto finish; } @@ -411,6 +414,9 @@ int go(struct interface *i) { next_scan = 0; break; + case SIGCHLD: + break; + default: daemon_log(LOG_INFO, "Ignoring unknown signal %s", strsignal(sig)); break; -- cgit