X-Git-Url: http://git.ozlabs.org/?p=ppp.git;a=blobdiff_plain;f=pppd%2Fmain.c;h=6541a3be3c472d208f43059ba8f74e3f88431425;hp=498f856430ce8244b1bc45a084d645a8225f2958;hb=215baf28fc53e909b987a4b31d7d25ecd4ee7a71;hpb=ffa027207fff95bd19cb529105bd549fb6ae1709 diff --git a/pppd/main.c b/pppd/main.c index 498f856..6541a3b 100644 --- a/pppd/main.c +++ b/pppd/main.c @@ -17,7 +17,7 @@ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ -#define RCSID "$Id: main.c,v 1.106 2001/04/27 23:16:13 paulus Exp $" +#define RCSID "$Id: main.c,v 1.109 2002/01/11 18:10:16 etbe Exp $" #include #include @@ -175,6 +175,7 @@ static void add_db_key __P((const char *)); static void delete_db_key __P((const char *)); static void cleanup_db __P((void)); static void handle_events __P((void)); +static void print_link_stats __P((void)); extern char *ttyname __P((int)); extern char *getlogin __P((void)); @@ -233,6 +234,7 @@ main(argc, argv) struct protent *protp; char numbuf[16]; + link_stats_valid = 0; new_phase(PHASE_INITIALIZE); /* @@ -468,9 +470,11 @@ main(argc, argv) * Start opening the connection and wait for * incoming events (reply, timeout, etc.). */ - notice("Connect: %s <--> %s", ifname, ppp_devnam); + if (ifunit >= 0) + notice("Connect: %s <--> %s", ifname, ppp_devnam); + else + notice("Starting negotiation on %s", ppp_devnam); gettimeofday(&start_time, NULL); - link_stats_valid = 0; script_unsetenv("CONNECT_TIME"); script_unsetenv("BYTES_SENT"); script_unsetenv("BYTES_RCVD"); @@ -493,15 +497,7 @@ main(argc, argv) } } - /* - * Print connect time and statistics. - */ - if (link_stats_valid) { - int t = (link_connect_time + 5) / 6; /* 1/10ths of minutes */ - info("Connect time %d.%d minutes.", t/10, t%10); - info("Sent %u bytes, received %u bytes.", - link_stats.bytes_out, link_stats.bytes_in); - } + print_link_stats(); /* * Delete pid file before disestablishing ppp. Otherwise it @@ -510,7 +506,7 @@ main(argc, argv) */ if (!demand) { if (pidfilename[0] != 0 - && unlink(pidfilename) < 0 && errno != ENOENT) + && unlink(pidfilename) < 0 && errno != ENOENT) warn("unable to delete pid file %s: %m", pidfilename); pidfilename[0] = 0; } @@ -543,7 +539,7 @@ main(argc, argv) if (!demand) { if (pidfilename[0] != 0 - && unlink(pidfilename) < 0 && errno != ENOENT) + && unlink(pidfilename) < 0 && errno != ENOENT) warn("unable to delete pid file %s: %m", pidfilename); pidfilename[0] = 0; } @@ -942,14 +938,13 @@ get_input() return; } - if (debug /*&& (debugflags & DBG_INPACKET)*/) - dbglog("rcvd %P", p, len); - if (len < PPP_HDRLEN) { - MAINDEBUG(("io(): Received short packet.")); + dbglog("received short packet:%.*B", len, p); return; } + dump_packet("rcvd", p, len); + p += 2; /* Skip address and control */ GETSHORT(protocol, p); len -= PPP_HDRLEN; @@ -1019,6 +1014,7 @@ void die(status) int status; { + print_link_stats(); cleanup(); notify(exitnotify, status); syslog(LOG_INFO, "Exit."); @@ -1039,10 +1035,10 @@ cleanup() if (the_channel->cleanup) (*the_channel->cleanup)(); - if (pidfilename[0] != 0 && unlink(pidfilename) < 0 && errno != ENOENT) + if (pidfilename[0] != 0 && unlink(pidfilename) < 0 && errno != ENOENT) warn("unable to delete pid file %s: %m", pidfilename); pidfilename[0] = 0; - if (linkpidfile[0] != 0 && unlink(linkpidfile) < 0 && errno != ENOENT) + if (linkpidfile[0] != 0 && unlink(linkpidfile) < 0 && errno != ENOENT) warn("unable to delete pid file %s: %m", linkpidfile); linkpidfile[0] = 0; @@ -1050,6 +1046,20 @@ cleanup() cleanup_db(); } +void +print_link_stats() +{ + /* + * Print connect time and statistics. + */ + if (link_stats_valid) { + int t = (link_connect_time + 5) / 6; /* 1/10ths of minutes */ + info("Connect time %d.%d minutes.", t/10, t%10); + info("Sent %u bytes, received %u bytes.", + link_stats.bytes_out, link_stats.bytes_in); + } +} + /* * update_link_stats - get stats at link termination. */ @@ -1136,9 +1146,9 @@ untimeout(func, arg) void *arg; { struct callout **copp, *freep; - + MAINDEBUG(("Untimeout %p:%p.", func, arg)); - + /* * Find first matching timeout and remove it from the list. */ @@ -1492,7 +1502,7 @@ run_program(prog, args, must_exist, done, arg) #ifdef BSD /* Force the priority back to zero if pppd is running higher. */ if (setpriority (PRIO_PROCESS, 0, 0) < 0) - warn("can't reset priority to 0: %m"); + warn("can't reset priority to 0: %m"); #endif /* SysV recommends a second fork at this point. */ @@ -1573,7 +1583,8 @@ reap_kids(waitfor) (chp? chp->prog: "??"), pid, WTERMSIG(status)); } else if (debug) dbglog("Script %s finished (pid %d), status = 0x%x", - (chp? chp->prog: "??"), pid, status); + (chp? chp->prog: "??"), pid, + WIFEXITED(status) ? WEXITSTATUS(status) : status); if (chp && chp->done) (*chp->done)(chp->arg); if (chp) @@ -1776,6 +1787,9 @@ update_db_entry() if (tdb_store(pppdb, key, dbuf, TDB_REPLACE)) error("tdb_store failed: %s", tdb_error(pppdb)); + if (vbuf) + free(vbuf); + } /*