--- embedtools/src/wdog.c 2010/10/18 10:47:06 1.1.2.4 +++ embedtools/src/wdog.c 2010/10/18 11:20:37 1.1.2.6 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ - * $Id: wdog.c,v 1.1.2.4 2010/10/18 10:47:06 misho Exp $ + * $Id: wdog.c,v 1.1.2.6 2010/10/18 11:20:37 misho Exp $ * *************************************************************************/ #include "global.h" @@ -23,6 +23,7 @@ Usage() "\t-v\t\tVerbose ...\n" "\t-c \tBefore execute chroot to dir [default=/]\n" "\t-u \tBefore execute change user\n" + "\t-P\t\tInfinit loop, bypass penalty timeout\n" "\n", compiled, compiledby, compilehost); } @@ -45,17 +46,21 @@ sigHand(int sig) int main(int argc, char **argv) { - char ch, szChroot[MAXPATHLEN] = "/"; + char ch, bypass = 0, szChroot[MAXPATHLEN] = "/"; int status = 0, ret = 1; struct sigaction sa; struct passwd *pass = NULL; uid_t uid = getuid(); + u_int penalty = 1; - while ((ch = getopt(argc, argv, "vhc:u:")) != -1) + while ((ch = getopt(argc, argv, "vhPc:u:")) != -1) switch (ch) { case 'v': Verbose++; break; + case 'P': + bypass = 1; + break; case 'c': if (uid) { printf("Error:: can`t chroot, please run as root!\n"); @@ -125,7 +130,7 @@ main(int argc, char **argv) VERB(1) printf("Info:: setuid to %u\n", uid); status ^= status; - while (!Kill) + while (!Kill && penalty) { switch ((ret = fork())) { case -1: printf("Error:: error in fork #%d - %s\n", errno, strerror(errno)); @@ -139,13 +144,22 @@ main(int argc, char **argv) ret = 6; goto end; } - /* never reached */ + /* never reached !!! */ break; default: wait(&status); kill(ret, SIGTERM); ret = status; } + /* penalty timeout retry */ + usleep(penalty); + if (!bypass) { + penalty <<= 1; + VERB(2) printf("Info:: penalty timeout %u microseconds\n", penalty); + } + } + if (!penalty) + ret = 9; end: return ret; }