]> git.ozlabs.org Git - ppp.git/blobdiff - pppd/main.c
minor bugfixes, now 2.4.2b1, add pkts_in/out to pppd_stats,
[ppp.git] / pppd / main.c
index e03b3621c94d3cd462015cf08d314766036c5487..498f856430ce8244b1bc45a084d645a8225f2958 100644 (file)
@@ -17,7 +17,7 @@
  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
-#define RCSID  "$Id: main.c,v 1.102 2001/02/22 03:10:57 paulus Exp $"
+#define RCSID  "$Id: main.c,v 1.106 2001/04/27 23:16:13 paulus Exp $"
 
 #include <stdio.h>
 #include <ctype.h>
@@ -54,7 +54,6 @@
 #include "chap.h"
 #include "ccp.h"
 #include "pathnames.h"
-#include "patchlevel.h"
 #include "tdb.h"
 
 #ifdef CBCP_SUPPORT
@@ -74,6 +73,8 @@ static const char rcsid[] = RCSID;
 char ifname[32];               /* Interface name */
 int ifunit;                    /* Interface unit number */
 
+struct channel *the_channel;
+
 char *progname;                        /* Name of this program */
 char hostname[MAXNAMELEN];     /* Our hostname */
 static char pidfilename[MAXPATHLEN];   /* name of pid file */
@@ -278,6 +279,10 @@ main(argc, argv)
      */
     for (i = 0; (protp = protocols[i]) != NULL; ++i)
         (*protp->init)(0);
+
+    /*
+     * Initialize the default channel.
+     */
     tty_init();
 
     progname = *argv;
@@ -296,7 +301,11 @@ main(argc, argv)
      * Work out the device name, if it hasn't already been specified,
      * and parse the tty's options file.
      */
-    tty_device_check();
+    if (the_channel->process_extra_options)
+       (*the_channel->process_extra_options)();
+
+    if (debug)
+       setlogmask(LOG_UPTO(LOG_DEBUG));
 
     /*
      * Check that we are running as root.
@@ -315,6 +324,7 @@ main(argc, argv)
     /*
      * Check that the options given are valid and consistent.
      */
+    check_options();
     if (!sys_check_options())
        exit(EXIT_OPTION_ERROR);
     auth_check_options();
@@ -324,14 +334,22 @@ main(argc, argv)
     for (i = 0; (protp = protocols[i]) != NULL; ++i)
        if (protp->check_options != NULL)
            (*protp->check_options)();
-    tty_check_options();
+    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));
 
     pppdb = tdb_open(_PATH_PPPDB, 0, 0, O_RDWR|O_CREAT, 0644);
     if (pppdb != NULL) {
@@ -359,8 +377,7 @@ main(argc, argv)
        else
            p = "(unknown)";
     }
-    syslog(LOG_NOTICE, "pppd %s.%d%s started by %s, uid %d",
-          VERSION, PATCHLEVEL, IMPLEMENTATION, p, uid);
+    syslog(LOG_NOTICE, "pppd %s started by %s, uid %d", VERSION, p, uid);
     script_setenv("PPPLOGNAME", p, 0);
 
     if (devnam[0])
@@ -430,13 +447,13 @@ main(argc, argv)
 
        new_phase(PHASE_SERIALCONN);
 
-       devfd = connect_tty();
+       devfd = the_channel->connect();
        if (devfd < 0)
            goto fail;
 
        /* 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;
@@ -482,7 +499,7 @@ main(argc, argv)
        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.",
+           info("Sent %u bytes, received %u bytes.",
                 link_stats.bytes_out, link_stats.bytes_in);
        }
 
@@ -505,9 +522,7 @@ main(argc, argv)
         */
        remove_fd(fd_ppp);
        clean_check();
-       if (demand)
-           restore_loop();
-       disestablish_ppp(devfd);
+       the_channel->disestablish_ppp(devfd);
        fd_ppp = -1;
        if (!hungup)
            lcp_lowerdown(0);
@@ -520,10 +535,11 @@ main(argc, argv)
         */
     disconnect:
        new_phase(PHASE_DISCONNECT);
-       disconnect_tty();
+       the_channel->disconnect();
 
     fail:
-       cleanup_tty();
+       if (the_channel->cleanup)
+           (*the_channel->cleanup)();
 
        if (!demand) {
            if (pidfilename[0] != 0
@@ -741,7 +757,7 @@ detach()
     close(1);
     close(2);
     detached = 1;
-    if (!log_to_file && !log_to_specific_fd)
+    if (log_default)
        log_to_fd = -1;
     /* update pid files if they have been written already */
     if (pidfilename[0])
@@ -1019,8 +1035,9 @@ cleanup()
     sys_cleanup();
 
     if (fd_ppp >= 0)
-       disestablish_ppp(devfd);
-    cleanup_tty();
+       the_channel->disestablish_ppp(devfd);
+    if (the_channel->cleanup)
+       (*the_channel->cleanup)();
 
     if (pidfilename[0] != 0 && unlink(pidfilename) < 0 && errno != ENOENT) 
        warn("unable to delete pid file %s: %m", pidfilename);
@@ -1070,9 +1087,6 @@ static struct timeval timenow;            /* Current time */
 
 /*
  * 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)
@@ -1081,10 +1095,10 @@ 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.
      */
@@ -1378,7 +1392,8 @@ device_script(program, in, out, dont_wait)
     close(1);
     close(2);
     sys_close();
-    tty_close_fds();
+    if (the_channel->close)
+       (*the_channel->close)();
     closelog();
 
     /* dup the in, out, err fds to 0, 1, 2 */
@@ -1460,7 +1475,8 @@ run_program(prog, args, must_exist, done, arg)
        close (0);
        close (1);
        close (2);
-       tty_close_fds();
+       if (the_channel->close)
+           (*the_channel->close)();
 
         /* Don't pass handles to the PPP device, even by accident. */
        new_fd = open (_PATH_DEVNULL, O_RDWR);