checkPidFile(device);
main(int argc, char **argv) {    int status, waited;    char *device, *physicalDevice = NULL;    char *theBoot = NULL;    shvarFile *ifcfg;    sigset_t sigs;    int pppdPid;    int timeout = 30;    char *temp;    struct timeval tv;    int dieing = 0;    int sendsig;    int connectedOnce = 0;    if (argc < 2) {	fprintf (stderr, "usage: ppp-watch [ifcfg-]<logical-name> [boot]");	exit(30);    }    if (!strncmp(argv[1], "ifcfg-", 6)) {	device = argv[1] + 6;    } else {	device = argv[1];    }    checkPidFile(device);    detach(0, 0, device); /* prepare */    if (argc > 2 && !strcmp("boot", argv[2])) {	theBoot = argv[2];    }    doPidFile(device);    signal(SIGTERM, signal_handler);    signal(SIGINT, signal_handler);    signal(SIGHUP, signal_handler);    signal(SIGIO, signal_handler);    signal(SIGCHLD, signal_handler);    if (theBoot) {	signal(SIGALRM, signal_handler);	alarm(30);    }    fork_exec(1, "/sbin/netreport", NULL, NULL, NULL);    theSigchld = 0;    /* don't set up the procmask until after we have received the netreport     * signal     */    sigemptyset(&sigs);    sigaddset(&sigs, SIGTERM);    sigaddset(&sigs, SIGINT);    sigaddset(&sigs, SIGHUP);    sigaddset(&sigs, SIGIO);    sigaddset(&sigs, SIGCHLD);    if (theBoot) sigaddset(&sigs, SIGALRM);    sigprocmask(SIG_BLOCK, &sigs, NULL);    /* prepare for sigsuspend later */    sigfillset(&sigs);    sigdelset(&sigs, SIGTERM);    sigdelset(&sigs, SIGINT);    sigdelset(&sigs, SIGHUP);    sigdelset(&sigs, SIGIO);    sigdelset(&sigs, SIGCHLD);    if (theBoot) sigdelset(&sigs, SIGALRM);    ifcfg = shvarfilesGet(device);    if (!ifcfg) cleanExit(28);    fork_exec(0, "/etc/sysconfig/network-scripts/ifup-ppp", "daemon", device, theBoot);    temp = svGetValue(ifcfg, "RETRYTIMEOUT");    if (temp) {	timeout = atoi(temp);	free(temp);    } else {	timeout = 30;    }    while (1) {	sigsuspend(&sigs);	if (theSigterm || theSigint) {	    theSigterm = theSigint = 0;	    if (dieing) sendsig = SIGKILL;	    else sendsig = SIGTERM;	    dieing = 1;	    if (physicalDevice) { free(physicalDevice); physicalDevice = NULL; }	    physicalDevice = pppLogicalToPhysical(&pppdPid, device);	    if (physicalDevice) { free(physicalDevice); physicalDevice = NULL; }	    if (!pppdPid) cleanExit(35);	    kill(pppdPid, sendsig);	    if (sendsig == SIGKILL) {		kill(-pppdPid, SIGTERM); /* give it a chance to die nicely */		usleep(2500000);		kill(-pppdPid, sendsig);		hangup(ifcfg);		cleanExit(32);	    }	}	if (theSighup) {	    theSighup = 0;	    if (ifcfg->parent) svCloseFile(ifcfg->parent);	    svCloseFile(ifcfg);	    ifcfg = shvarfilesGet(device);	    physicalDevice = pppLogicalToPhysical(&pppdPid, device);	    if (physicalDevice) { free(physicalDevice); physicalDevice = NULL; }	    kill(pppdPid, SIGTERM);	    /* redial when SIGCHLD arrives, even if !PERSIST */	    connectedOnce = 0;	    timeout = 0; /* redial immediately */	}	if (theSigio) {	    theSigio = 0;	    if (connectedOnce) {		if (physicalDevice) { free(physicalDevice); physicalDevice = NULL; }		temp = svGetValue(ifcfg, "DISCONNECTTIMEOUT");		if (temp) {		    timeout = atoi(temp);		    free(temp);		} else {		    timeout = 2;		}	    }	    physicalDevice = pppLogicalToPhysical(NULL, device);	    if (physicalDevice) {		if (interfaceStatus(physicalDevice)) {		    /* device is up */		    detach(1, 0, NULL);		    connectedOnce = 1;		}	    }	}	if (theSigchld) {	    theSigchld = 0;	    waited = wait3(&status, 0, NULL);	    if (waited < 0) continue;	    /* now, we need to kill any children of pppd still in pppd's	     * process group, in case they are hanging around.	     * pppd is dead (we just waited for it) but there is no	     * guarantee that its children are dead, and they will	     * hold the modem if we do not get rid of them.	     * We have kept the old pid/pgrp around in pppdPid.	     */	    if (pppdPid) {		kill(-pppdPid, SIGTERM); /* give it a chance to die nicely */		usleep(2500000);		kill(-pppdPid, SIGKILL);		hangup(ifcfg);	    }	    pppdPid = 0;	    if (!WIFEXITED(status)) cleanExit(29);	    if (dieing) cleanExit(WEXITSTATUS(status));	    if (!connectedOnce || svTrueValue(ifcfg, "PERSIST", 0)) {		temp = svGetValue(ifcfg, "RETRYTIMEOUT");		if (temp) {		    timeout = atoi(temp);		    free(temp);		} else {		    timeout = 30;		}		if (connectedOnce) {		    memset(&tv, 0, sizeof(tv));		    tv.tv_sec = timeout;		    select(0, NULL, NULL, NULL, &tv);		}		fork_exec(0, "/etc/sysconfig/network-scripts/ifup-ppp", "daemon", device, theBoot);	    } else {		cleanExit(WEXITSTATUS(status));	    }	}	if (theSigalrm) {	    detach(1, 34, NULL);	}    }}