--- usr.sbin/arp/arp.c +++ usr.sbin/arp/arp.c @@ -56,6 +56,8 @@ #include #include #include +#include +#include #include #include @@ -79,6 +81,7 @@ #include #include #include +#include typedef void (action_fn)(struct sockaddr_dl *sdl, struct sockaddr_inarp *s_in, struct rt_msghdr *rtm); @@ -110,6 +113,9 @@ #define F_REPLACE 4 #define F_DELETE 5 +/* timeout for arp */ +#define TIMEOUT 20 + #define SETFUNC(f) { if (func) usage(); func = (f); } int @@ -118,6 +124,17 @@ int ch, func = 0; int rtn = 0; int aflag = 0; /* do it for all entries */ + int pidfork; + int arpdone = 0; + int tout = TIMEOUT; + int status; + + openlog("arp", LOG_CONS, LOG_USER); + while (arpdone == 0) { + pidfork = fork(); + if (pidfork == 0) { + alarm(tout); + /* Beginning of ARP */ while ((ch = getopt(argc, argv, "andfsSi:")) != -1) switch((char)ch) { @@ -201,6 +218,22 @@ usage(); rtn = file(argv[0]); break; + } + arpdone = 1; + alarm(0); + } else if (pidfork > 0) { + wait(&status); + if (WIFSIGNALED(status)) { + arpdone = 0; + syslog(LOG_WARNING, "config failed, restarting"); + } else { + arpdone = 1; + rtn = WEXITSTATUS(status); + } + } else { + syslog (LOG_ERR, "forking failed"); + arpdone = 0; + } } return (rtn);