*/
#ifndef lint
-static char rcsid[] = "$Id: main.c,v 1.46 1998/03/26 04:46:04 paulus Exp $";
+static char rcsid[] = "$Id: main.c,v 1.47 1998/03/30 06:25:34 paulus Exp $";
#endif
#include <stdio.h>
/* Prototypes for procedures local to this file. */
+static void create_pidfile __P((void));
static void cleanup __P((void));
static void close_tty __P((void));
static void get_input __P((void));
{
int i, fdflags;
struct sigaction sa;
- FILE *pidfile;
char *p;
struct passwd *pw;
struct timeval timo;
(void) sprintf(ifname, "ppp%d", ifunit);
script_setenv("IFNAME", ifname);
- /* write pid to file */
- (void) sprintf(pidfilename, "%s%s.pid", _PATH_VARRUN, ifname);
- if ((pidfile = fopen(pidfilename, "w")) != NULL) {
- fprintf(pidfile, "%d\n", pid);
- (void) fclose(pidfile);
- } else {
- syslog(LOG_ERR, "Failed to create pid file %s: %m", pidfilename);
- pidfilename[0] = 0;
- }
+ create_pidfile(); /* write pid to file */
/*
* Configure the interface and mark it up, etc.
(void) sprintf(ifname, "ppp%d", ifunit);
script_setenv("IFNAME", ifname);
- /* write pid to file */
- (void) sprintf(pidfilename, "%s%s.pid", _PATH_VARRUN, ifname);
- if ((pidfile = fopen(pidfilename, "w")) != NULL) {
- fprintf(pidfile, "%d\n", pid);
- (void) fclose(pidfile);
- } else {
- syslog(LOG_ERR, "Failed to create pid file %s: %m",
- pidfilename);
- pidfilename[0] = 0;
- }
+ create_pidfile(); /* write pid to file */
}
/*
die(1);
}
detached = 1;
+ pid = getpid();
+ /* update pid file if it has been written already */
+ if (pidfilename[0])
+ create_pidfile();
+}
+
+/*
+ * Create a file containing our process ID.
+ */
+static void
+create_pidfile()
+{
+ FILE *pidfile;
+
+ (void) sprintf(pidfilename, "%s%s.pid", _PATH_VARRUN, ifname);
+ if ((pidfile = fopen(pidfilename, "w")) != NULL) {
+ fprintf(pidfile, "%d\n", pid);
+ (void) fclose(pidfile);
+ } else {
+ syslog(LOG_ERR, "Failed to create pid file %s: %m", pidfilename);
+ pidfilename[0] = 0;
+ }
}
/*