arp: fix -H/-t handling.
[oweals/busybox.git] / networking / udhcp / dhcpd.c
index 6fb48a19a9e8509a38edbf199f7c04420f706b05..9ad95954dd0ec5c0b6a56d7d86049949ce4de1d2 100644 (file)
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
+
+//usage:#define udhcpd_trivial_usage
+//usage:       "[-fS]" IF_FEATURE_UDHCP_PORT(" [-P N]") " [CONFFILE]"
+//usage:#define udhcpd_full_usage "\n\n"
+//usage:       "DHCP server\n"
+//usage:     "\n       -f      Run in foreground"
+//usage:     "\n       -S      Log to syslog too"
+//usage:       IF_FEATURE_UDHCP_PORT(
+//usage:     "\n       -P N    Use port N (default 67)"
+//usage:       )
+
 #include <syslog.h>
 #include "common.h"
 #include "dhcpc.h"
@@ -303,9 +314,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
 #endif
        opt = getopt32(argv, "fSv"
                IF_FEATURE_UDHCP_PORT("P:", &str_P)
-#if defined CONFIG_UDHCP_DEBUG && CONFIG_UDHCP_DEBUG >= 1
-               , &dhcp_verbose
-#endif
+               IF_UDHCP_VERBOSE(, &dhcp_verbose)
                );
        if (!(opt & 1)) { /* no -f */
                bb_daemonize_or_rexec(0, argv);
@@ -368,6 +377,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
        /* Setup the signal pipe */
        udhcp_sp_setup();
 
+ continue_with_autotime:
        timeout_end = monotonic_sec() + server_config.auto_time;
        while (1) { /* loop until universe collapses */
                fd_set rfds;
@@ -397,8 +407,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
                }
                if (retval == 0) {
                        write_leases();
-                       timeout_end = monotonic_sec() + server_config.auto_time;
-                       continue;
+                       goto continue_with_autotime;
                }
                if (retval < 0 && errno != EINTR) {
                        log1("Error on select");
@@ -410,10 +419,10 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
                        bb_info_msg("Received SIGUSR1");
                        write_leases();
                        /* why not just reset the timeout, eh */
-                       timeout_end = monotonic_sec() + server_config.auto_time;
-                       continue;
+                       goto continue_with_autotime;
                case SIGTERM:
                        bb_info_msg("Received SIGTERM");
+                       write_leases();
                        goto ret0;
                case 0: /* no signal: read a packet */
                        break;