}
fprintf(f, "%d\n", getpid()); fclose(f);
doPidFile(char *device) {    static char *pidFileName = NULL;    char *pidFilePath;    int fd; FILE *f;    int pid = 0;    if (pidFileName) {	/* remove it */	pidFilePath = alloca(strlen(pidFileName) + 25);	sprintf(pidFilePath, "/var/run/pppwatch-%s.pid", pidFileName);	unlink(pidFilePath); /* not much we can do in case of error... */    }    if (device) {	/* create it */	pidFileName = device;	pidFilePath = alloca(strlen(pidFileName) + 25);	sprintf(pidFilePath, "/var/run/pppwatch-%s.pid", pidFileName);	fd = open(pidFilePath, O_WRONLY|O_TRUNC|O_CREAT|O_EXCL,		  S_IRUSR|S_IWUSR | S_IRGRP | S_IROTH);	if (fd == -1) {	    /* file already existed, or terrible things have happened... */	    fd = open(pidFilePath, O_RDONLY);	    if (fd == -1)		cleanExit(36); /* terrible things have happened */	    /* already running, send a SIGHUP (we presume that they	     * are calling ifup for a reason, so they probably want	     * to redial) and then exit cleanly and let things go	     * on in the background	     */	    f = fdopen(fd, "r");	    if (!f) cleanExit(37);	    if (fscanf(f, "%d", &pid) && pid)		kill(pid, SIGHUP);	    fclose(f);	    cleanExit(0);	}	f = fdopen(fd, "w");	if (f) {	    fprintf(f, "%d\n", getpid());	    fclose(f);	} else {	    cleanExit(31);	}    }}