X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=pppd%2Fmain.c;h=7441219fa97e3be6e6193438ec36225ec98339bd;hb=1ab9ab93491c12576fa771db9388bf6ab76c788c;hp=eec19c760398d598ca9eb8e7650f295db0d9101a;hpb=8d95b4cae82fe429d2988b3d95d37325e65ea5ad;p=ppp.git diff --git a/pppd/main.c b/pppd/main.c index eec19c7..7441219 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.48 1998/04/28 23:37:30 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; + } } /* @@ -1282,10 +1287,9 @@ pr_log __V((void *arg, char *fmt, ...)) fmt = va_arg(pvar, char *); #endif - vsprintf(buf, fmt, pvar); + n = vfmtmsg(buf, sizeof(buf), fmt, pvar); va_end(pvar); - n = strlen(buf); if (linep + n + 1 > line + sizeof(line)) { syslog(LOG_DEBUG, "%s", line); linep = line;