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

Diff for /src/usr.bin/fstat/fstat.c between version 1.97 and 1.98

version 1.97, 2019/01/25 00:19:26 version 1.98, 2019/01/28 17:49:50
Line 87 
Line 87 
   
 #define MAXIMUM(a, b)   (((a) > (b)) ? (a) : (b))  #define MAXIMUM(a, b)   (((a) > (b)) ? (a) : (b))
   
   struct fstat_filter {
           int what;
           int arg;
   };
   
 struct fileargs fileargs = SLIST_HEAD_INITIALIZER(fileargs);  struct fileargs fileargs = SLIST_HEAD_INITIALIZER(fileargs);
   
 int     fsflg;  /* show files on same filesystem as file(s) argument */  int     fsflg;  /* show files on same filesystem as file(s) argument */
 int     pflg;   /* show files open by a particular pid */  
 int     uflg;   /* show files open by a particular (effective) user */  int     uflg;   /* show files open by a particular (effective) user */
 int     checkfile; /* true if restricting to particular files or filesystems */  int     checkfile; /* true if restricting to particular files or filesystems */
 int     nflg;   /* (numerical) display f.s. and rdev as dev_t */  int     nflg;   /* (numerical) display f.s. and rdev as dev_t */
Line 102 
Line 106 
 int     fuser;  /* 1 if we are fuser, 0 if we are fstat */  int     fuser;  /* 1 if we are fuser, 0 if we are fstat */
 int     signo;  /* signal to send (fuser only) */  int     signo;  /* signal to send (fuser only) */
   
   int     nfilter = 0;    /* How many uid/pid filters are in place */
   struct fstat_filter *filter = NULL; /* An array of uid/pid filters */
   
 kvm_t *kd;  kvm_t *kd;
 uid_t uid;  uid_t uid;
   
Line 137 
Line 144 
 {  {
         struct passwd *passwd;          struct passwd *passwd;
         struct kinfo_file *kf, *kflast;          struct kinfo_file *kf, *kflast;
         int arg, ch, what;          int ch;
         char *memf, *nlistf, *optstr;          char *memf, *nlistf, *optstr;
         char buf[_POSIX2_LINE_MAX];          char buf[_POSIX2_LINE_MAX];
         const char *errstr;          const char *errstr;
Line 145 
Line 152 
   
         hideroot = getuid();          hideroot = getuid();
   
         arg = -1;  
         what = KERN_FILE_BYPID;  
         nlistf = memf = NULL;          nlistf = memf = NULL;
         oflg = 0;          oflg = 0;
   
Line 196 
Line 201 
                         oflg = 1;                          oflg = 1;
                         break;                          break;
                 case 'p':                  case 'p':
                         if (pflg++)                          if ((filter = recallocarray(filter, nfilter, nfilter + 1,
                                 usage();                              sizeof(*filter))) == NULL)
                         arg = strtonum(optarg, 0, INT_MAX, &errstr);                                  err(1, NULL);
                           filter[nfilter].arg = strtonum(optarg, 0, INT_MAX,
                               &errstr);
                         if (errstr != NULL) {                          if (errstr != NULL) {
                                 warnx("-p requires a process id, %s: %s",                                  warnx("-p requires a process id, %s: %s",
                                         errstr, optarg);                                          errstr, optarg);
                                 usage();                                  usage();
                         }                          }
                         what = KERN_FILE_BYPID;                          filter[nfilter].what = KERN_FILE_BYPID;
                           nfilter++;
                         break;                          break;
                 case 's':                  case 's':
                         sflg = 1;                          sflg = 1;
Line 217 
Line 225 
                         }                          }
                         break;                          break;
                 case 'u':                  case 'u':
                         if (uflg++)                          uflg = 1;
                                 usage();  
                         if (!fuser) {                          if (!fuser) {
                                 uid_t uid;                                  uid_t uid;
   
Line 230 
Line 237 
                                                     optarg);                                                      optarg);
                                         }                                          }
                                 }                                  }
                                 arg = uid;                                  if ((filter = recallocarray(filter, nfilter,
                                 what = KERN_FILE_BYUID;                                      nfilter + 1, sizeof(*filter))) == NULL)
                                           err(1, NULL);
                                   filter[nfilter].arg = uid;
                                   filter[nfilter].what = KERN_FILE_BYUID;
                                   nfilter++;
                         }                          }
                         break;                          break;
                 case 'v':                  case 'v':
Line 275 
Line 286 
                 checkfile = 1;                  checkfile = 1;
         }          }
   
         if ((kf = kvm_getfiles(kd, what, arg, sizeof(*kf), &cnt)) == NULL)          if (nfilter == 1) {
                 errx(1, "%s", kvm_geterr(kd));                  if ((kf = kvm_getfiles(kd, filter[0].what, filter[0].arg,
                       sizeof(*kf), &cnt)) == NULL)
                           errx(1, "%s", kvm_geterr(kd));
           } else {
                   if ((kf = kvm_getfiles(kd, KERN_FILE_BYPID, -1, sizeof(*kf),
                       &cnt)) == NULL)
                           errx(1, "%s", kvm_geterr(kd));
           }
   
         if (fuser) {          if (fuser) {
                 /*                  /*
Line 367 
Line 385 
 void  void
 fstat_dofile(struct kinfo_file *kf)  fstat_dofile(struct kinfo_file *kf)
 {  {
           int i;
   
         Uname = user_from_uid(kf->p_uid, 0);          Uname = user_from_uid(kf->p_uid, 0);
         procuid = &kf->p_uid;          procuid = &kf->p_uid;
         Pid = kf->p_pid;          Pid = kf->p_pid;
         Comm = kf->p_comm;          Comm = kf->p_comm;
   
           for (i = 0; i < nfilter; i++) {
                   if (filter[i].what == KERN_FILE_BYPID) {
                           if (filter[i].arg == Pid)
                                   break;
                   } else if (filter[i].arg == *procuid) {
                           break;
                   }
           }
           if (i == nfilter && nfilter != 0)
                   return;
   
         switch (kf->f_type) {          switch (kf->f_type) {
         case DTYPE_VNODE:          case DTYPE_VNODE:

Legend:
Removed from v.1.97  
changed lines
  Added in v.1.98