From 7097785dc774ed0ff166a0434a90ffc342814ae9 Mon Sep 17 00:00:00 2001 From: Paul Mackerras Date: Mon, 30 Mar 1998 06:25:34 +0000 Subject: [PATCH] rewrite the pid file when using updetach --- pppd/main.c | 47 ++++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/pppd/main.c b/pppd/main.c index eec19c7..8bb5caa 100644 --- a/pppd/main.c +++ b/pppd/main.c @@ -18,7 +18,7 @@ */ #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 @@ -105,6 +105,7 @@ char *no_ppp_msg = "Sorry - this system lacks PPP kernel support\n"; /* 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)); @@ -165,7 +166,6 @@ main(argc, argv) { int i, fdflags; struct sigaction sa; - FILE *pidfile; char *p; struct passwd *pw; struct timeval timo; @@ -373,15 +373,7 @@ main(argc, argv) (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. @@ -522,16 +514,7 @@ main(argc, argv) (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 */ } /* @@ -636,6 +619,28 @@ detach() 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; + } } /* -- 2.39.2