diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ifplugd.c | 66 | ||||
-rw-r--r-- | src/interface.c | 1 | ||||
-rw-r--r-- | src/interface.h | 3 |
3 files changed, 60 insertions, 10 deletions
diff --git a/src/ifplugd.c b/src/ifplugd.c index 76d4d1a..f04afaf 100644 --- a/src/ifplugd.c +++ b/src/ifplugd.c @@ -68,11 +68,14 @@ char *run = SYSCONFDIR"/ifplugd/ifplugd.action"; char *extra_arg = NULL; int polltime = 1, + pollutime = 0, delay_up = 0, delay_down = 5; int daemonize = 1, use_beep = 1, + beep_on_up = 1, + beep_on_down = 1, no_startup_script = 0, no_shutdown_script = 0, wait_on_fork = 0, @@ -126,6 +129,18 @@ finish: return; } +static void beep_up(int b) { + if(!beep_on_up) + return; + beep(b); +} + +static void beep_down(int b) { + if(!beep_on_down) + return; + beep(b); +} + const char *pid_file_proc() { static char fn[PATH_MAX]; snprintf(fn, sizeof(fn), "%s/ifplugd.%s.pid", VARRUN, interface); @@ -237,13 +252,13 @@ int action(interface_status_t status) { if (!WIFEXITED(r) || WEXITSTATUS(r) != 0) { if (status == IFSTATUS_UP) - beep(2); + beep_up(2); daemon_log(LOG_ERR, "Program execution failed, return value is %i.", WEXITSTATUS(r)); return ignore_retval ? 0 : -1; } else { if (status == IFSTATUS_UP) - beep(0); + beep_up(0); daemon_log(LOG_INFO, "Program executed successfully."); return 0; @@ -409,7 +424,7 @@ void work(void) { break; } - if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { + if ((fd = socket(AF_LOCAL, SOCK_DGRAM, 0)) < 0) { daemon_log(LOG_ERR, "socket(): %s", strerror(errno)); goto finish; } @@ -440,7 +455,10 @@ void work(void) { goto finish; daemon_log(LOG_INFO, "Initialization complete, link beat %sdetected%s.", status == IFSTATUS_UP ? "" : "not ", use_ifmonitor ? (disabled ? ", interface disabled" : ", interface enabled") : ""); - beep(status == IFSTATUS_UP ? 0 : 1); + if(status == IFSTATUS_UP) + beep_up(0); + else + beep_down(1); if ((!no_startup_script && status == IFSTATUS_UP) || initial_down) if (action(status) < 0) @@ -466,8 +484,16 @@ void work(void) { struct timeval tv; tv.tv_sec = polltime; - tv.tv_usec = 0; + tv.tv_usec = pollutime; + if (t) { + int delay = t - time(NULL); + if (delay < 0) + tv.tv_sec = 0; + else if (delay < tv.tv_sec) + tv.tv_sec = delay; + } + if (select(FD_SETSIZE, &qfds, NULL, NULL, &tv) < 0) { if (errno == EINTR) continue; @@ -513,7 +539,10 @@ void work(void) { if (status != s) { daemon_log(LOG_INFO, "Link beat %s.", status == IFSTATUS_DOWN ? "lost" : "detected"); - beep(status == IFSTATUS_UP ? 0 : 1); + if(status == IFSTATUS_UP) + beep_up(0); + else + beep_down(1); if (t) t = 0; @@ -573,7 +602,7 @@ void work(void) { } } - if (t && t < time(NULL)) { + if (t && t <= time(NULL)) { t = 0; if (action(status) < 0) @@ -586,7 +615,7 @@ cleanup: setenv(IFPLUGD_ENV_PREVIOUS, strstatus(status), 1); setenv(IFPLUGD_ENV_CURRENT, strstatus(-1), 1); action(IFSTATUS_DOWN); - beep(1); + beep_down(1); } finish: @@ -628,12 +657,15 @@ void usage(char *p) { " -n --no-daemon Do not daemonize (for debugging) (%s)\n" " -s --no-syslog Do not use syslog, use stderr instead (for debugging) (%s)\n" " -b --no-beep Do not beep (%s)\n" + " -U --no-beep-up Do not beep on interface up (%s)\n" + " -D --no-beep-down Do not beep on interface down (%s)\n" " -f --ignore-fail Ignore detection failure, retry instead (failure is treated as DOWN) (%s)\n" " -F --ignore-fail-positive Ignore detection failure, retry instead (failure is treated as UP) (%s)\n" " -i --iface=IFACE Specify ethernet interface (%s)\n" " -r --run=EXEC Specify program to execute (%s)\n" " -I --ignore-retval Don't exit on nonzero return value of program executed (%s)\n" " -t --poll-time=SECS Specify poll time in seconds (%i)\n" + " -T --poll-utime=USECS Specify poll time in microseconds, add to -t (%i)\n" " -u --delay-up=SECS Specify delay for configuring interface (%i)\n" " -d --delay-down=SECS Specify delay for deconfiguring interface (%i)\n" " -m --api-mode=MODE Force API mode (mii, priv, ethtool, wlan, auto) (%s)\n" @@ -656,12 +688,15 @@ void usage(char *p) { !daemonize ? "on" : "off", !use_syslog ? "on" : "off", !use_beep ? "on" : "off", + !beep_on_up ? "on" : "off", + !beep_on_down ? "on" : "off", failure_status == IFSTATUS_DOWN ? "on" : "off", failure_status == IFSTATUS_UP ? "on" : "off", interface, run, ignore_retval ? "on" : "off", polltime, + pollutime, delay_up, delay_down, m, @@ -679,12 +714,15 @@ void parse_args(int argc, char *argv[]) { {"no-daemon", no_argument, 0, 'n'}, {"no-syslog", no_argument, 0, 's'}, {"no-beep", no_argument, 0, 'b'}, + {"no-beep-up", no_argument, 0, 'U'}, + {"no-beep-down", no_argument, 0, 'D'}, {"ignore-fail", no_argument, 0, 'f'}, {"ignore-fail-positive", no_argument, 0, 'F'}, {"ignore-retval", no_argument, 0, 'I'}, {"iface", required_argument, 0, 'i'}, {"run", required_argument, 0, 'r'}, {"poll-time", required_argument, 0, 't'}, + {"poll-utime", required_argument, 0, 'T'}, {"delay-up", required_argument, 0, 'u'}, {"delay-down", required_argument, 0, 'd'}, {"api-mode", required_argument, 0, 'm'}, @@ -710,7 +748,7 @@ void parse_args(int argc, char *argv[]) { for (;;) { int c; - if ((c = getopt_long(argc, argv, "asni:r:t:u:d:hkbfFvm:pqwx:cISRzlMW", long_options, &option_index)) < 0) + if ((c = getopt_long(argc, argv, "asni:r:t:T:u:d:hkbUDfFvm:pqwx:cISRzlMW", long_options, &option_index)) < 0) break; switch (c) { @@ -738,6 +776,10 @@ void parse_args(int argc, char *argv[]) { polltime = atoi(optarg); if (polltime < 0) polltime = 0; break; + case 'T': + pollutime = atoi(optarg); + if (pollutime < 0) pollutime = 0; + break; case 'u': delay_up = atoi(optarg); break; @@ -759,6 +801,12 @@ void parse_args(int argc, char *argv[]) { case 'b': use_beep = !use_beep; break; + case 'U': + beep_on_up = !beep_on_up; + break; + case 'D': + beep_on_down = !beep_on_down; + break; case 'f': failure_status = IFSTATUS_DOWN; break; diff --git a/src/interface.c b/src/interface.c index e5038f4..98bcf0e 100644 --- a/src/interface.c +++ b/src/interface.c @@ -23,7 +23,6 @@ #endif #include <linux/sockios.h> -#include <linux/if_ether.h> #include <sys/types.h> #include <sys/socket.h> #include <sys/ioctl.h> diff --git a/src/interface.h b/src/interface.h index d223b1f..8d6ea78 100644 --- a/src/interface.h +++ b/src/interface.h @@ -21,6 +21,9 @@ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ +/* From <linux/if_ether.h> */ +#define ETH_ALEN 6 + int interface_auto_up; int interface_do_message; |