diff options
| author | Lennart Poettering <lennart@poettering.net> | 2004-01-26 15:23:01 +0000 |
|---|---|---|
| committer | Lennart Poettering <lennart@poettering.net> | 2004-01-26 15:23:01 +0000 |
| commit | bc1fef7e4144a437293345c1dbd7f174b32dcbbd (patch) | |
| tree | 84e91626aa1326e53fbc9df1c76146d8a47f66bc /src/waproamd.c | |
| parent | a084f62ea25f533b43233cdbb000fd0353585bcb (diff) | |
multiple fixes
git-svn-id: file:///home/lennart/svn/public/waproamd/trunk@58 022f378f-78c4-0310-b860-d162c87e6274
Diffstat (limited to 'src/waproamd.c')
| -rw-r--r-- | src/waproamd.c | 59 |
1 files changed, 35 insertions, 24 deletions
diff --git a/src/waproamd.c b/src/waproamd.c index 8e2d5ad..aa3381f 100644 --- a/src/waproamd.c +++ b/src/waproamd.c @@ -32,6 +32,7 @@ #include <signal.h> #include <stdlib.h> #include <getopt.h> +#include <sys/stat.h> #include <libdaemon/dpid.h> #include <libdaemon/dlog.h> @@ -68,12 +69,13 @@ int use_assocwatch = 1, use_userspace_roaming = 1; int poll_interval = 5, - scan_interval = 10; + scan_interval = 30; char log_ident[32], pid_ident[32]; int get_script_path(char *path, int l, struct ap_info *ai) { assert(path && l); + struct stat st; if (!ai) { snprintf(path, l, "%s/default", SCRIPTDIR); @@ -85,30 +87,30 @@ int get_script_path(char *path, int l, struct ap_info *ai) { ai->ap.addr[0], ai->ap.addr[1], ai->ap.addr[2], ai->ap.addr[3], ai->ap.addr[4], ai->ap.addr[5]); - if (!access(path, X_OK)) - return 0; + if (!stat(path, &st)) + return st.st_mode & S_IXUSR ? 0 : 1; snprintf(path, l, "%s/%02X:%02X:%02X:%02X:%02X:%02X", SCRIPTDIR, ai->ap.addr[0], ai->ap.addr[1], ai->ap.addr[2], ai->ap.addr[3], ai->ap.addr[4], ai->ap.addr[5]); - if (!access(path, X_OK)) - return 0; + if (!stat(path, &st)) + return st.st_mode & S_IXUSR ? 0 : 1; if (ai->essid[0]) { snprintf(path, l, "%s/essid:%s", SCRIPTDIR, escape_essid(ai->essid)); - if (!access(path, X_OK)) - return 0; + if (!stat(path, &st)) + return st.st_mode & S_IXUSR ? 0 : 1; } return -1; } -int aps_found_n; +int total_aps_found_n, aps_found_n; struct ap_info scan_ap; int scan_ap_has_script; @@ -119,19 +121,23 @@ static int scan_result_cb(struct ap_info*ai) { assert(ai); - aps_found_n++; - - if (aps_found_n == 1) + if (total_aps_found_n == 0) daemon_log(LOG_INFO, "Scan results:"); + total_aps_found_n++; + snprint_hw_addr(t, sizeof(t), &ai->ap); f = get_script_path(path, sizeof(path), ai); - daemon_log(LOG_INFO, "%i. Found AP %s, ESSID '%s', script: %s", aps_found_n, t, escape_essid(ai->essid), !f ? "yes" : "no"); + daemon_log(LOG_INFO, "%i. Found AP %s, ESSID '%s', script: %s", total_aps_found_n, t, escape_essid(ai->essid), f == 0 ? "yes" : (f < 0 ? "no" : "off")); - /* Select this AP, if no better was found before */ - if (aps_found_n <= 1 || (!scan_ap_has_script && f == 0)) { - memcpy(&scan_ap, ai, sizeof(struct ap_info)); - scan_ap_has_script = f == 0; + if (f <= 0) { + aps_found_n++; + + /* Select this AP, if no better was found before */ + if ((aps_found_n <= 1 || (!scan_ap_has_script && f == 0))) { + memcpy(&scan_ap, ai, sizeof(struct ap_info)); + scan_ap_has_script = f == 0; + } } return 0; @@ -139,7 +145,7 @@ static int scan_result_cb(struct ap_info*ai) { int read_scan(struct interface *i, struct ap_info **ap) { int r; - aps_found_n = 0; + aps_found_n = total_aps_found_n = 0; scan_ap_has_script = 0; memset(&scan_ap, 0, sizeof(scan_ap)); @@ -149,8 +155,7 @@ int read_scan(struct interface *i, struct ap_info **ap) { if (r == 1) return 1; - if (aps_found_n >= 1) - daemon_log(LOG_INFO, "Scan finished."); + daemon_log(LOG_INFO, "Scan completed with %u suitable networks. (total: %u)", aps_found_n, total_aps_found_n); *ap = aps_found_n > 0 ? &scan_ap : NULL; @@ -254,6 +259,8 @@ int go(struct interface *i) { if (nlapi_open(RTMGRP_LINK) < 0) goto finish; + interface_up(i); + /* Check whether interface is available */ if (use_ifmonitor) { int b; @@ -363,7 +370,7 @@ int go(struct interface *i) { if (nlapi_work(0) < 0) goto finish; - if (!disabled && !paused) { + if (!disabled && !paused && !scanning) { if ((associated = iw_assoc(i, &associated_ap)) < 0) { if (!use_ifmonitor) @@ -385,7 +392,7 @@ int go(struct interface *i) { /* Changed: enabled -> disabled */ if (!d && disabled) { - daemon_log(LOG_INFO, "Interface disabled"); + daemon_log(LOG_INFO, "Interface disabled."); if (associated) if (set_current_ap(i, NULL) < 0) @@ -396,11 +403,15 @@ int go(struct interface *i) { /* Changed: disabled -> enabled */ if (d && !disabled) { - daemon_log(LOG_INFO, "Interface enabled"); + daemon_log(LOG_INFO, "Interface enabled."); associated = scanning = 0; - if (iw_set_hostroam(i, 2) < 0) - daemon_log(LOG_WARNING, "Enabling user space roaming failed, doing without."); + interface_up(i); + + if (use_userspace_roaming) { + if (iw_set_hostroam(i, 2) < 0) + daemon_log(LOG_WARNING, "Enabling user space roaming failed, doing without."); + } } if (!disabled) { |
