]> git.ozlabs.org Git - ppp.git/blobdiff - pppd/main.c
Add timestamp at beginning of each section of record file.
[ppp.git] / pppd / main.c
index c69d6c245ed578a848f5c30f96aa66ce6b6dbea6..c0615c510da6e10b75da5a4547c97d2ac57ae7b5 100644 (file)
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static char rcsid[] = "$Id: main.c,v 1.65 1999/03/23 01:23:46 paulus Exp $";
+static char rcsid[] = "$Id: main.c,v 1.67 1999/03/25 01:30:32 paulus Exp $";
 #endif
 
 #include <stdio.h>
@@ -246,7 +246,25 @@ main(argc, argv)
     if (!options_from_file(_PATH_SYSOPTIONS, !privileged, 0, 1)
        || !options_from_user())
        exit(1);
+    using_pty = notty || ptycommand != NULL;
     scan_args(argc-1, argv+1); /* look for tty name on command line */
+
+    /*
+     * Work out the device name, if it hasn't already been specified.
+     */
+    if (!using_pty) {
+       p = isatty(0)? ttyname(0): NULL;
+       if (p != NULL) {
+           if (default_device)
+               strlcpy(devnam, p, sizeof(devnam));
+           else if (strcmp(devnam, p) == 0)
+               default_device = 1;
+       }
+    }
+
+    /*
+     * Parse the tty options file and the command line.
+     */
     if (!options_for_tty()
        || !parse_args(argc-1, argv+1))
        exit(1);
@@ -279,7 +297,7 @@ main(argc, argv)
        exit(1);
     }
 
-    if (ptycommand != NULL || notty) {
+    if (using_pty) {
        if (!default_device) {
            option_error("%s option precludes specifying device name",
                         notty? "notty": "pty");
@@ -293,21 +311,9 @@ main(argc, argv)
        lockflag = 0;
        modem = 0;
     } else {
-       /*
-        * If the user has specified the default device name explicitly,
-        * pretend they hadn't.
-        */
-       p = isatty(0)? ttyname(0): NULL;
-       if (p == NULL) {
-           if (default_device) {
-               option_error("no device specified and stdin is not a tty");
-               exit(1);
-           }
-       } else {
-           if (default_device)
-               strlcpy(devnam, p, sizeof(devnam));
-           else if (strcmp(devnam, p) == 0)
-               default_device = 1;
+       if (devnam[0] == 0) {
+           option_error("no device specified and stdin is not a tty");
+           exit(1);
        }
     }
     if (default_device)
@@ -526,10 +532,10 @@ main(argc, argv)
            for (;;) {
                /* If the user specified the device name, become the
                   user before opening it. */
-               if (!devnam_info.priv)
+               if (!devnam_info.priv && !default_device)
                    seteuid(uid);
                ttyfd = open(devnam, O_NONBLOCK | O_RDWR, 0);
-               if (!devnam_info.priv)
+               if (!devnam_info.priv && !default_device)
                    seteuid(0);
                if (ttyfd >= 0)
                    break;
@@ -2373,8 +2379,16 @@ charshunt(ifd, ofd, record_file)
     nibuf = nobuf = 0;
     ibufp = obufp = NULL;
     pty_readable = stdin_readable = 1;
-    gettimeofday(&lasttime, NULL);
     nfds = (ofd > pty_master? ofd: pty_master) + 1;
+    if (recordf != NULL) {
+       gettimeofday(&lasttime, NULL);
+       putc(7, recordf);       /* put start marker */
+       putc(lasttime.tv_sec >> 24, recordf);
+       putc(lasttime.tv_sec >> 16, recordf);
+       putc(lasttime.tv_sec >> 8, recordf);
+       putc(lasttime.tv_sec, recordf);
+       lasttime.tv_usec = 0;
+    }
 
     while (nibuf != 0 || nobuf != 0 || pty_readable || stdin_readable) {
        FD_ZERO(&ready);
@@ -2490,8 +2504,8 @@ record_write(f, code, buf, nb, tp)
     int diff;
 
     gettimeofday(&now, NULL);
-    diff = (now.tv_sec - tp->tv_sec) * 10
-       + (now.tv_usec - tp->tv_usec) / 100000;
+    now.tv_usec /= 100000;     /* actually 1/10 s, not usec now */
+    diff = (now.tv_sec - tp->tv_sec) * 10 + (now.tv_usec - tp->tv_usec);
     if (diff > 0) {
        if (diff > 255) {
            putc(5, f);