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

Diff for /src/usr.bin/who/who.c between version 1.20 and 1.21

version 1.20, 2013/08/22 04:43:41 version 1.21, 2015/10/07 16:11:40
Line 62 
Line 62 
 #define HOST_WIDTH      45  #define HOST_WIDTH      45
   
 int hostwidth = HOST_WIDTH;  int hostwidth = HOST_WIDTH;
   char *mytty;
   
 int  int
 main(int argc, char *argv[])  main(int argc, char *argv[])
 {  {
         struct utmp usr;          struct utmp usr;
         FILE *ufp;          FILE *ufp;
           char *t;
         int c;          int c;
   
         setlocale(LC_ALL, "");          setlocale(LC_ALL, "");
   
           if (tame("stdio getpw rpath ioctl", NULL) == -1)
                   err(1, "tame");
   
           mytty = ttyname(0);
           /* strip any directory component */
           if ((t = strrchr(mytty, '/')))
                   mytty = t + 1;
   
         only_current_term = show_term = show_idle = show_labels = 0;          only_current_term = show_term = show_idle = show_labels = 0;
         show_quick = 0;          show_quick = 0;
         while ((c = getopt(argc, argv, "HmqTu")) != -1) {          while ((c = getopt(argc, argv, "HmqTu")) != -1) {
Line 179 
Line 189 
 {  {
         struct utmp usr;          struct utmp usr;
         struct passwd *pw;          struct passwd *pw;
         char *p;  
         char *t;  
   
         /* search through the utmp and find an entry for this tty */          /* search through the utmp and find an entry for this tty */
         if ((p = ttyname(0))) {          if (mytty) {
                 /* strip any directory component */  
                 if ((t = strrchr(p, '/')))  
                         p = t + 1;  
                 while (fread((char *)&usr, sizeof(usr), 1, ufp) == 1)                  while (fread((char *)&usr, sizeof(usr), 1, ufp) == 1)
                         if (*usr.ut_name && !strcmp(usr.ut_line, p)) {                          if (*usr.ut_name && !strcmp(usr.ut_line, mytty)) {
                                 output(&usr);                                  output(&usr);
                                 return;                                  return;
                         }                          }
                 /* well, at least we know what the tty is */                  /* well, at least we know what the tty is */
                 (void)strncpy(usr.ut_line, p, UT_LINESIZE);                  (void)strncpy(usr.ut_line, mytty, UT_LINESIZE);
         } else          } else
                 (void)strncpy(usr.ut_line, "tty??", UT_LINESIZE);                  (void)strncpy(usr.ut_line, "tty??", UT_LINESIZE);
   
Line 283 
Line 288 
         if (!(ufp = fopen(name, "r"))) {          if (!(ufp = fopen(name, "r"))) {
                 err(1, "%s", name);                  err(1, "%s", name);
                 /* NOTREACHED */                  /* NOTREACHED */
           }
           if (show_term || show_idle) {
                   if (tame("stdio getpw rpath", NULL) == -1)
                           err(1, "tame");
           } else {
                   if (tame("stdio getpw", NULL) == -1)
                           err(1, "tame");
         }          }
         return(ufp);          return(ufp);
 }  }

Legend:
Removed from v.1.20  
changed lines
  Added in v.1.21