X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=pppd%2Fmain.c;h=cad0fa3b44a0668ebaadcec1a7d640561eabcfd4;hb=5018cc2da57e555b620750f33dce6b1c964e612a;hp=0e256229c7f8064e3f03ada8bae8913d3934ae90;hpb=7bf6751db96fd7d4ca96ff4fe89cae5935a05287;p=ppp.git diff --git a/pppd/main.c b/pppd/main.c index 0e25622..cad0fa3 100644 --- a/pppd/main.c +++ b/pppd/main.c @@ -18,7 +18,7 @@ */ #ifndef lint -static char rcsid[] = "$Id: main.c,v 1.68 1999/03/30 04:22:57 paulus Exp $"; +static char rcsid[] = "$Id: main.c,v 1.73 1999/04/01 07:19:59 paulus Exp $"; #endif #include @@ -153,8 +153,8 @@ static void record_child __P((int, char *, void (*) (void *), void *)); static int start_charshunt __P((int, int)); static void charshunt_done __P((void *)); static void charshunt __P((int, int, char *)); -static int record_write(FILE *, int code, u_char *buf, int nb, - struct timeval *); +static int record_write __P((FILE *, int code, u_char *buf, int nb, + struct timeval *)); extern char *ttyname __P((int)); extern char *getlogin __P((void)); @@ -214,12 +214,7 @@ main(argc, argv) script_env = NULL; /* Initialize syslog facilities */ -#ifdef ULTRIX - openlog("pppd", LOG_PID); -#else - openlog("pppd", LOG_PID | LOG_NDELAY, LOG_PPP); - setlogmask(LOG_UPTO(LOG_INFO)); -#endif + reopen_log(); if (gethostname(hostname, MAXNAMELEN) < 0 ) { option_error("Couldn't get hostname: %m"); @@ -323,8 +318,6 @@ main(argc, argv) log_to_fd = 1; /* default to stdout */ script_setenv("DEVICE", devnam); - slprintf(numbuf, sizeof(numbuf), "%d", baud_rate); - script_setenv("SPEED", numbuf); /* * Initialize system-dependent stuff and magic number package. @@ -622,6 +615,8 @@ main(argc, argv) error("Connect script failed"); goto fail; } + if (kill_link) + goto disconnect; info("Serial connection established."); @@ -644,6 +639,9 @@ main(argc, argv) close(i); } + slprintf(numbuf, sizeof(numbuf), "%d", baud_rate); + script_setenv("SPEED", numbuf); + /* run welcome script, if any */ if (welcomer && welcomer[0]) { if (device_script(welcomer, ttyfd, ttyfd, 0) < 0) @@ -653,7 +651,7 @@ main(argc, argv) /* set up the serial device as a ppp interface */ fd_ppp = establish_ppp(ttyfd); if (fd_ppp < 0) - goto fail; + goto disconnect; if (!demand) { @@ -740,11 +738,14 @@ main(argc, argv) restore_loop(); disestablish_ppp(ttyfd); fd_ppp = -1; + if (!hungup) + lcp_lowerdown(0); /* * Run disconnector script, if requested. * XXX we may not be able to do this if the line has hung up! */ + disconnect: if (disconnector && !hungup) { if (real_ttyfd >= 0) set_up_tty(real_ttyfd, 1); @@ -754,8 +755,6 @@ main(argc, argv) info("Serial link disconnected."); } } - if (!hungup) - lcp_lowerdown(0); fail: if (pty_master >= 0) @@ -838,6 +837,20 @@ detach() create_pidfile(); } +/* + * reopen_log - (re)open our connection to syslog. + */ +void +reopen_log() +{ +#ifdef ULTRIX + openlog("pppd", LOG_PID); +#else + openlog("pppd", LOG_PID | LOG_NDELAY, LOG_PPP); + setlogmask(LOG_UPTO(LOG_INFO)); +#endif +} + /* * Create a file containing our process ID. */ @@ -1280,7 +1293,7 @@ device_script(program, in, out, dont_wait) int dont_wait; { int pid; - int status = 0; + int status = -1; int errfd; ++conn_running; @@ -1319,13 +1332,9 @@ device_script(program, in, out, dont_wait) if (out == 0) out = dup(out); dup2(in, 0); - if (in > 2) - close(in); } if (out != 1) { dup2(out, 1); - if (out > 2) - close(out); } if (real_ttyfd > 2) close(real_ttyfd); @@ -1347,6 +1356,7 @@ device_script(program, in, out, dont_wait) if (dont_wait) { record_child(pid, program, NULL, NULL); + status = 0; } else { while (waitpid(pid, &status, 0) < 0) { if (errno == EINTR) @@ -1458,12 +1468,7 @@ run_program(prog, args, must_exist, done, arg) if (must_exist || errno != ENOENT) { /* have to reopen the log, there's nowhere else for the message to go. */ -#ifdef ULTRIX - openlog("pppd", LOG_PID); -#else - openlog("pppd", LOG_PID | LOG_NDELAY, LOG_PPP); - setlogmask(LOG_UPTO(LOG_INFO)); -#endif + reopen_log(); syslog(LOG_ERR, "Can't execute %s: %m", prog); closelog(); } @@ -1531,8 +1536,8 @@ reap_kids(waitfor) warn("Child process %s (pid %d) terminated with signal %d", (chp? chp->prog: "??"), pid, WTERMSIG(status)); } else if (debug) - dbglog("process %d (%s) finished, status = 0x%x", - pid, (chp? chp->prog: "??"), status); + dbglog("Script %s finished (pid %d), status = 0x%x", + (chp? chp->prog: "??"), pid, status); if (chp && chp->done) (*chp->done)(chp->arg); }