ifplugd: code shrink

function                                             old     new   delta
ifplugd_main                                        1161    1144     -17

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2014-02-10 09:44:25 +01:00
parent 3e78f6f955
commit 50e4cc29f5

View File

@ -289,8 +289,6 @@ static const struct {
{ "IFF_RUNNING" , &detect_link_iff }, { "IFF_RUNNING" , &detect_link_iff },
}; };
static const char *strstatus(int status) static const char *strstatus(int status)
{ {
if (status == IFSTATUS_ERR) if (status == IFSTATUS_ERR)
@ -652,7 +650,6 @@ int ifplugd_main(int argc UNUSED_PARAM, char **argv)
delay_time = 0; delay_time = 0;
while (1) { while (1) {
int iface_status_old; int iface_status_old;
int iface_exists_old;
switch (bb_got_signal) { switch (bb_got_signal) {
case SIGINT: case SIGINT:
@ -678,12 +675,12 @@ int ifplugd_main(int argc UNUSED_PARAM, char **argv)
goto exiting; goto exiting;
} }
iface_status_old = iface_status;
iface_exists_old = G.iface_exists;
if ((opts & FLAG_MONITOR) if ((opts & FLAG_MONITOR)
&& (netlink_pollfd[0].revents & POLLIN) && (netlink_pollfd[0].revents & POLLIN)
) { ) {
int iface_exists_old;
iface_exists_old = G.iface_exists;
G.iface_exists = check_existence_through_netlink(); G.iface_exists = check_existence_through_netlink();
if (G.iface_exists < 0) /* error */ if (G.iface_exists < 0) /* error */
goto exiting; goto exiting;
@ -696,6 +693,7 @@ int ifplugd_main(int argc UNUSED_PARAM, char **argv)
} }
/* note: if !G.iface_exists, returns DOWN */ /* note: if !G.iface_exists, returns DOWN */
iface_status_old = iface_status;
iface_status = detect_link(); iface_status = detect_link();
if (iface_status == IFSTATUS_ERR) { if (iface_status == IFSTATUS_ERR) {
if (!(opts & FLAG_MONITOR)) if (!(opts & FLAG_MONITOR))
@ -709,7 +707,7 @@ int ifplugd_main(int argc UNUSED_PARAM, char **argv)
if (delay_time) { if (delay_time) {
/* link restored its old status before /* link restored its old status before
* we run script. don't run the script: */ * we ran script. don't run the script: */
delay_time = 0; delay_time = 0;
} else { } else {
delay_time = monotonic_sec(); delay_time = monotonic_sec();
@ -717,15 +715,19 @@ int ifplugd_main(int argc UNUSED_PARAM, char **argv)
delay_time += G.delay_up; delay_time += G.delay_up;
if (iface_status == IFSTATUS_DOWN) if (iface_status == IFSTATUS_DOWN)
delay_time += G.delay_down; delay_time += G.delay_down;
if (delay_time == 0) #if 0 /* if you are back in 1970... */
delay_time++; if (delay_time == 0) {
sleep(1);
delay_time = 1;
}
#endif
} }
} }
if (delay_time && (int)(monotonic_sec() - delay_time) >= 0) { if (delay_time && (int)(monotonic_sec() - delay_time) >= 0) {
delay_time = 0;
if (run_script(iface_status_str) != 0) if (run_script(iface_status_str) != 0)
goto exiting; goto exiting;
delay_time = 0;
} }
} /* while (1) */ } /* while (1) */