summaryrefslogtreecommitdiff
path: root/src/ifplugd.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ifplugd.c')
-rw-r--r--src/ifplugd.c66
1 files changed, 57 insertions, 9 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;