--- usr.sbin/arp/arp.c +++ usr.sbin/arp/arp.c @@ -60,6 +60,8 @@ #include #include #include +#include +#include #include #include @@ -82,6 +84,7 @@ #include #include #include +#include void search(u_long addr, void (*action)(struct sockaddr_dl *sdl, struct sockaddr_inarp *sin, struct rt_msghdr *rtm)); @@ -121,6 +124,8 @@ #define F_REPLACE 4 #define F_DELETE 5 +/* timeout for arp */ +#define TIMEOUT 20 #define ROUNDUP(a) \ ((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long)) #define SETFUNC(f) { if (func) usage(); func = (f); } @@ -130,7 +135,17 @@ { int ch, func = 0; int rtn = 0; - + 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 */ pid = getpid(); while ((ch = getopt(argc, argv, "andfsSi:")) != -1) switch((char)ch) { @@ -222,6 +237,25 @@ 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); }