[BACK]Return to last.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / last

Diff for /src/usr.bin/last/last.c between version 1.17 and 1.18

version 1.17, 2001/11/05 09:42:13 version 1.18, 2002/02/04 17:40:59
Line 64 
Line 64 
   
 #define NO      0                               /* false/no */  #define NO      0                               /* false/no */
 #define YES     1                               /* true/yes */  #define YES     1                               /* true/yes */
 #define ATOI2(ar)       ((ar)[0] - '0') * 10 + ((ar)[1] - '0'); (ar) += 2;  #define ATOI2(ar)       ((ar)[0] - '0') * 10 + ((ar)[1] - '0'); (ar) += 2;
   
 static struct utmp      buf[1024];              /* utmp read buffer */  static struct utmp      buf[1024];              /* utmp read buffer */
   
Line 104 
Line 104 
 time_t   dateconv __P((char *));  time_t   dateconv __P((char *));
 int      want __P((struct utmp *, int));  int      want __P((struct utmp *, int));
 void     wtmp __P((void));  void     wtmp __P((void));
 void     checkargs __P((void));  void     checkargs __P((void));
   
 #define NAME_WIDTH      8  #define NAME_WIDTH      8
 #define HOST_WIDTH      24  #define HOST_WIDTH      24
Line 181 
Line 181 
                         addarg(USER_TYPE, *argv);                          addarg(USER_TYPE, *argv);
                 }                  }
         }          }
   
         checkargs();          checkargs();
         wtmp();          wtmp();
         exit(0);          exit(0);
Line 189 
Line 189 
   
 /*  /*
  * checkargs --   * checkargs --
  *      if snaptime is set, print warning if usernames, or -t or -h   *      if snaptime is set, print warning if usernames, or -t or -h
  *      flags are also provided   *      flags are also provided
  */   */
   
 void  void
 checkargs()  checkargs()
 {  {
         ARG     *step;          ARG     *step;
         int     ttyflag = 0;          int     ttyflag = 0;
   
         if (!snaptime)          if (!snaptime)
                 return;                  return;
   
         if (!arglist)          if (!arglist)
                 return;                  return;
   
Line 212 
Line 212 
                             "Warning: Ignoring hostname flag\n");                              "Warning: Ignoring hostname flag\n");
                         break;                          break;
                 case TTY_TYPE:                  case TTY_TYPE:
                         if (!ttyflag) { /* don't print this twice */                          if (!ttyflag) { /* don't print this twice */
                                 (void)fprintf(stderr,                                  (void)fprintf(stderr,
                                     "Warning: Ignoring tty flag\n");                                      "Warning: Ignoring tty flag\n");
                                 ttyflag = 1;                                  ttyflag = 1;
Line 225 
Line 225 
                 default:                  default:
                         /* PRINT NOTHING */                          /* PRINT NOTHING */
                 }                  }
 }  }
   
   
 /*  /*
Line 244 
Line 244 
         int     timesize;               /* how long time string gonna be */          int     timesize;               /* how long time string gonna be */
         int     bytes, wfd;          int     bytes, wfd;
         char    *ct, *crmsg;          char    *ct, *crmsg;
         int     snapfound = 0;          /* found snapshot entry? */          int     snapfound = 0;          /* found snapshot entry? */
         if ((wfd = open(file, O_RDONLY, 0)) < 0 || fstat(wfd, &stb) == -1)          if ((wfd = open(file, O_RDONLY, 0)) < 0 || fstat(wfd, &stb) == -1)
                 err(1, "%s", file);                  err(1, "%s", file);
         bl = (stb.st_size + sizeof(buf) - 1) / sizeof(buf);          bl = (stb.st_size + sizeof(buf) - 1) / sizeof(buf);
Line 274 
Line 274 
                                 currentout = -bp->ut_time;                                  currentout = -bp->ut_time;
                                 crmsg = strncmp(bp->ut_name, "shutdown",                                  crmsg = strncmp(bp->ut_name, "shutdown",
                                     UT_NAMESIZE) ? "crash" : "shutdown";                                      UT_NAMESIZE) ? "crash" : "shutdown";
                                 /*                                  /*
                                  * if we're in snapshop mode, we want to                                   * if we're in snapshot mode, we want to
                                  * exit if this shutdown/reboot appears                                   * exit if this shutdown/reboot appears
                                  * while we we are tracking the active                                   * while we we are tracking the active
                                  * range                                   * range
                                  */                                   */
                                 if (snaptime && snapfound)                                  if (snaptime && snapfound)
                                         return;                                          return;
                                 /*                                  /*
                                  * don't print shutdown/reboot entries                                   * don't print shutdown/reboot entries
                                  * unless flagged for                                   * unless flagged for
                                  */                                   */
                                 if (want(bp, NO)) {                                  if (want(bp, NO)) {
                                         if (seconds) {                                          if (seconds) {
                                                 printf("%-*.*s %-*.*s %-*.*s %ld \n",                                                  printf("%-*.*s %-*.*s %-*.*s %ld \n",
Line 322 
Line 322 
                                         UT_LINESIZE, UT_LINESIZE, bp->ut_line,                                          UT_LINESIZE, UT_LINESIZE, bp->ut_line,
                                         HOST_WIDTH, UT_HOSTSIZE, bp->ut_host,                                          HOST_WIDTH, UT_HOSTSIZE, bp->ut_host,
                                         (long)bp->ut_time);                                          (long)bp->ut_time);
                                         } else {                                          } else {
                                                 ct = ctime(&bp->ut_time);                                                  ct = ctime(&bp->ut_time);
                                 printf("%-*.*s  %-*.*s %-*.*s %10.10s %*.*s \n",                                  printf("%-*.*s  %-*.*s %-*.*s %10.10s %*.*s \n",
                                         NAME_WIDTH, UT_NAMESIZE, bp->ut_name,                                          NAME_WIDTH, UT_NAMESIZE, bp->ut_name,
                                         UT_LINESIZE, UT_LINESIZE, bp->ut_line,                                          UT_LINESIZE, UT_LINESIZE, bp->ut_line,
                                         HOST_WIDTH, UT_HOSTSIZE, bp->ut_host,                                          HOST_WIDTH, UT_HOSTSIZE, bp->ut_host,
                                         ct, timesize, timesize, ct + 11);                                          ct, timesize, timesize, ct + 11);
                                         }                                          }
                                         if (maxrec && !--maxrec)                                          if (maxrec && !--maxrec)
                                                 return;                                                  return;
                                 }                                  }
Line 345 
Line 345 
                                 if (!strncmp(T->tty, bp->ut_line, UT_LINESIZE))                                  if (!strncmp(T->tty, bp->ut_line, UT_LINESIZE))
                                         break;                                          break;
                         }                          }
                         /*                          /*
                          * print record if not in snapshot mode and wanted                           * print record if not in snapshot mode and wanted
                          * or in snapshot mode and in snapshot range                           * or in snapshot mode and in snapshot range
                          */                           */
                         if (bp->ut_name[0] &&                          if (bp->ut_name[0] &&
                             ((want(bp, YES)) ||                              ((want(bp, YES)) ||
                              (bp->ut_time < snaptime &&                               (bp->ut_time < snaptime &&
                               (T->logout > snaptime || !T->logout ||                                (T->logout > snaptime || !T->logout ||
                                T->logout < 0)))) {                                 T->logout < 0)))) {
                                 snapfound = 1;                                  snapfound = 1;
Line 376 
Line 376 
                                                 T->logout = -T->logout;                                                  T->logout = -T->logout;
                                                 printf("- %s", crmsg);                                                  printf("- %s", crmsg);
                                         } else {                                          } else {
                                                 if (seconds)                                                  if (seconds)
                                                         printf("- %ld",                                                          printf("- %ld",
                                                             (long)T->logout);                                                              (long)T->logout);
                                                 else                                                  else
Line 448 
Line 448 
                         bp->ut_line[4] = '\0';                          bp->ut_line[4] = '\0';
         }          }
   
         if (snaptime)           /* if snaptime is set, return NO */          if (snaptime)           /* if snaptime is set, return NO */
                 return (NO);                  return (NO);
   
         if (!arglist)          if (!arglist)
Line 567 
Line 567 
         return (arg);          return (arg);
 }  }
   
 /*  /*
  * dateconv --   * dateconv --
  *      Convert the snapshot time in command line given in the format   * Convert the snapshot time in command line given in the format
  *      [[CC]YY][MMDD]hhmm[.ss]] to a time_t.   *      [[CC]YY][MMDD]hhmm[.ss]] to a time_t.
  *      Derived from atime_arg1() in usr.bin/touch/touch.c   *      Derived from atime_arg1() in usr.bin/touch/touch.c
  */   */
 time_t  time_t
 dateconv(arg)  dateconv(arg)
Line 590 
Line 590 
   
         /* [[yy]yy][mmdd]hhmm[.ss] */          /* [[yy]yy][mmdd]hhmm[.ss] */
         if ((p = strchr(arg, '.')) == NULL)          if ((p = strchr(arg, '.')) == NULL)
                 t->tm_sec = 0;          /* Seconds defaults to 0. */                  t->tm_sec = 0;          /* Seconds defaults to 0. */
         else {          else {
                 if (strlen(p + 1) != 2)                  if (strlen(p + 1) != 2)
                         goto terr;                          goto terr;
Line 620 
Line 620 
                 /* FALLTHROUGH */                  /* FALLTHROUGH */
         case 8:                         /* MMDDhhmm */          case 8:                         /* MMDDhhmm */
                 t->tm_mon = ATOI2(arg);                  t->tm_mon = ATOI2(arg);
                 --t->tm_mon;            /* Convert from 01-12 to 00-11 */                  --t->tm_mon;            /* Convert from 01-12 to 00-11 */
                 t->tm_mday = ATOI2(arg);                  t->tm_mday = ATOI2(arg);
                 t->tm_hour = ATOI2(arg);                  t->tm_hour = ATOI2(arg);
                 t->tm_min = ATOI2(arg);                  t->tm_min = ATOI2(arg);
Line 632 
Line 632 
         default:          default:
                 goto terr;                  goto terr;
         }          }
         t->tm_isdst = -1;               /* Figure out DST. */          t->tm_isdst = -1;               /* Figure out DST. */
         timet = mktime(t);          timet = mktime(t);
         if (timet == -1)          if (timet == -1)
 terr:      errx(1,  terr:      errx(1,

Legend:
Removed from v.1.17  
changed lines
  Added in v.1.18