* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
-#define RCSID "$Id: main.c,v 1.103 2001/03/08 05:11:14 paulus Exp $"
+#define RCSID "$Id: main.c,v 1.109 2002/01/11 18:10:16 etbe Exp $"
#include <stdio.h>
#include <ctype.h>
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));
struct protent *protp;
char numbuf[16];
+ link_stats_valid = 0;
new_phase(PHASE_INITIALIZE);
/*
if (the_channel->process_extra_options)
(*the_channel->process_extra_options)();
- if (dump_options || dryrun) {
- init_pr_log(NULL, LOG_INFO);
- print_options(pr_log, NULL);
- end_pr_log();
- }
+ if (debug)
+ setlogmask(LOG_UPTO(LOG_DEBUG));
/*
* Check that we are running as root.
if (the_channel->check_options)
(*the_channel->check_options)();
+
+ if (dump_options || dryrun) {
+ init_pr_log(NULL, LOG_INFO);
+ print_options(pr_log, NULL);
+ end_pr_log();
+ if (dryrun)
+ die(0);
+ }
+
/*
* Initialize system-dependent stuff.
*/
sys_init();
- if (debug)
- setlogmask(LOG_UPTO(LOG_DEBUG));
-
- if (dryrun)
- die(0);
pppdb = tdb_open(_PATH_PPPDB, 0, 0, O_RDWR|O_CREAT, 0644);
if (pppdb != NULL) {
/* set up the serial device as a ppp interface */
tdb_writelock(pppdb);
- fd_ppp = establish_ppp(devfd);
+ fd_ppp = the_channel->establish_ppp(devfd);
if (fd_ppp < 0) {
tdb_writeunlock(pppdb);
status = EXIT_FATAL_ERROR;
* 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");
}
}
- /*
- * 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 %d bytes, received %d bytes.",
- link_stats.bytes_out, link_stats.bytes_in);
- }
+ print_link_stats();
/*
* Delete pid file before disestablishing ppp. Otherwise it
*/
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;
}
*/
remove_fd(fd_ppp);
clean_check();
- if (demand)
- restore_loop();
- disestablish_ppp(devfd); /* XXX */
+ the_channel->disestablish_ppp(devfd);
fd_ppp = -1;
if (!hungup)
lcp_lowerdown(0);
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;
}
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;
die(status)
int status;
{
+ print_link_stats();
cleanup();
notify(exitnotify, status);
syslog(LOG_INFO, "Exit.");
sys_cleanup();
if (fd_ppp >= 0)
- disestablish_ppp(devfd);
+ the_channel->disestablish_ppp(devfd);
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;
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.
*/
/*
* timeout - Schedule a timeout.
- *
- * Note that this timeout takes the number of milliseconds, NOT hz (as in
- * the kernel).
*/
void
timeout(func, arg, secs, usecs)
int secs, usecs;
{
struct callout *newp, *p, **pp;
-
+
MAINDEBUG(("Timeout %p:%p in %d.%03d seconds.", func, arg,
- time / 1000, time % 1000));
-
+ secs, usecs/1000));
+
/*
* Allocate timeout.
*/
void *arg;
{
struct callout **copp, *freep;
-
+
MAINDEBUG(("Untimeout %p:%p.", func, arg));
-
+
/*
* Find first matching timeout and remove it from the list.
*/
#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. */
(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)
if (tdb_store(pppdb, key, dbuf, TDB_REPLACE))
error("tdb_store failed: %s", tdb_error(pppdb));
+ if (vbuf)
+ free(vbuf);
+
}
/*