@@ -85,15 +85,14 @@ static int HbyMPCCt = 0; /* HbyMPC entry count */
8585 */
8686
8787void hashSfile (struct lsof_context * ctx ) {
88- static int hs = 0 ;
8988 int i ;
9089 struct sfile * s ;
9190 struct hsfile * sh , * sn ;
9291 /*
9392 * Do nothing if there are no file search arguments cached or if the
9493 * hashes have already been constructed.
9594 */
96- if (!Sfile || hs )
95+ if (!Sfile || Hs )
9796 return ;
9897 /*
9998 * Allocate hash buckets by (device,inode), file system device, MPC device,
@@ -134,7 +133,7 @@ void hashSfile(struct lsof_context *ctx) {
134133 SFNMHASH );
135134 Error (ctx );
136135 }
137- hs ++ ;
136+ Hs ++ ;
138137 /*
139138 * Scan the Sfile chain, building file, file system, MPC file, and file
140139 * name hash bucket chains.
@@ -387,7 +386,7 @@ char *print_dev(struct lfile *lf, /* file whose device to be printed */
387386 */
388387
389388void process_file (struct lsof_context * ctx , /* context */
390- KA_T fp ) /* kernel file structure address */
389+ KA_T fp ) /* kernel file structure address */
391390{
392391 struct file f ;
393392 int flag ;
@@ -430,26 +429,26 @@ void process_file(struct lsof_context *ctx, /* context */
430429 * Save file structure values.
431430 */
432431
433- #if !defined(HASNOFSCOUNT )
432+ # if !defined(HASNOFSCOUNT )
434433 Lf -> fct = (long )f .f_count ;
435434 Lf -> fsv |= FSV_CT ;
436- #endif /* !defined(HASNOFSCOUNT) */
435+ # endif /* !defined(HASNOFSCOUNT) */
437436
438- #if !defined(HASNOFSADDR )
437+ # if !defined(HASNOFSADDR )
439438 Lf -> fsa = fp ;
440439 Lf -> fsv |= FSV_FA ;
441- #endif /* !defined(HASNOFSADDR) */
440+ # endif /* !defined(HASNOFSADDR) */
442441
443- #if !defined(HASNOFSFLAGS )
442+ # if !defined(HASNOFSFLAGS )
444443 Lf -> ffg = (long )f .f_flag ;
445444 Lf -> fsv |= FSV_FG ;
446- #endif /* !defined(HASNOFSFLAGS) */
445+ # endif /* !defined(HASNOFSFLAGS) */
447446
448- #if !defined(HASNOFSNADDR )
447+ # if !defined(HASNOFSNADDR )
449448 Lf -> fna = (KA_T )f .f_data ;
450449 Lf -> fsv |= FSV_NI ;
451- #endif /* !defined(HASNOFSNADDR) */
452- #endif /* defined(HASFSTRUCT) */
450+ # endif /* !defined(HASNOFSNADDR) */
451+ #endif /* defined(HASFSTRUCT) */
453452
454453 /*
455454 * Process structure by its type.
@@ -458,18 +457,18 @@ void process_file(struct lsof_context *ctx, /* context */
458457
459458#if defined(DTYPE_PIPE )
460459 case DTYPE_PIPE :
461- #if defined(HASPIPEFN )
460+ # if defined(HASPIPEFN )
462461 if (!Selinet )
463462 HASPIPEFN (ctx , (KA_T )f .f_data );
464- #endif /* defined(HASPIPEFN) */
463+ # endif /* defined(HASPIPEFN) */
465464 return ;
466465#endif /* defined(DTYPE_PIPE) */
467466
468467#if defined(DTYPE_PTS )
469468 case DTYPE_PTS :
470- #if defined(HASPTSFN )
469+ # if defined(HASPTSFN )
471470 HASPTSFN (ctx , (KA_T )f .f_data );
472- #endif /* defined(HASPTSFN) */
471+ # endif /* defined(HASPTSFN) */
473472 return ;
474473#endif /* defined(DTYPE_PTS) */
475474
@@ -494,10 +493,10 @@ void process_file(struct lsof_context *ctx, /* context */
494493 /*
495494 * AIX-specific: Capture filename from file structure.
496495 *
497- * AIX limitation: The kernel doesn't provide an accessible name cache,
498- * so we can only obtain the leaf filename from f_fnamep. We'll combine
499- * this with the filesystem mount point (if available) after calling
500- * process_node() to provide partial path context.
496+ * AIX limitation: The kernel doesn't provide an accessible name
497+ * cache, so we can only obtain the leaf filename from f_fnamep.
498+ * We'll combine this with the filesystem mount point (if available)
499+ * after calling process_node() to provide partial path context.
501500 *
502501 * Full path reconstruction is not possible on AIX without expensive
503502 * userspace filesystem scanning.
@@ -507,12 +506,14 @@ void process_file(struct lsof_context *ctx, /* context */
507506 int have_leaf = 0 ;
508507
509508 /* Try to read the leaf filename from the file structure */
510- if (f .f_vnode && f .f_fnamep
511- && !kread (ctx , (KA_T )f .f_vnode , (char * )& v , sizeof (v ))
512- && v .v_gnode && !kread (ctx , (KA_T )v .v_gnode , (char * )& g , sizeof (g ))
513- && (g .gn_type == VREG || g .gn_type == VDIR )) {
514- if (!kread (ctx , (KA_T )f .f_fnamep , leafname , sizeof (leafname )- 1 )) {
515- leafname [sizeof (leafname )- 1 ] = '\0' ;
509+ if (f .f_vnode && f .f_fnamep &&
510+ !kread (ctx , (KA_T )f .f_vnode , (char * )& v , sizeof (v )) &&
511+ v .v_gnode &&
512+ !kread (ctx , (KA_T )v .v_gnode , (char * )& g , sizeof (g )) &&
513+ (g .gn_type == VREG || g .gn_type == VDIR )) {
514+ if (!kread (ctx , (KA_T )f .f_fnamep , leafname ,
515+ sizeof (leafname ) - 1 )) {
516+ leafname [sizeof (leafname ) - 1 ] = '\0' ;
516517 /* Only use if we got a non-empty string */
517518 if (leafname [0 ]) {
518519 have_leaf = 1 ;
@@ -521,22 +522,25 @@ void process_file(struct lsof_context *ctx, /* context */
521522 }
522523
523524 /* Process the node to get vfs/mount info and other metadata */
524- #if defined(HASF_VNODE )
525+ # if defined(HASF_VNODE )
525526 process_node (ctx , (KA_T )f .f_vnode );
526- #else /* !defined(HASF_VNODE) */
527+ # else /* !defined(HASF_VNODE) */
527528 process_node (ctx , (KA_T )f .f_data );
528- #endif /* defined(HASF_VNODE) */
529+ # endif /* defined(HASF_VNODE) */
529530
530531 /*
531532 * If we have a leaf name, combine it with mount point info.
532533 * This provides better context than just the leaf name alone.
533- * Use ellipsis (...) to indicate missing path components between
534- * the mount point and the leaf filename.
534+ * Use ellipsis (...) to indicate missing path components
535+ * between the mount point and the leaf filename.
535536 */
536537 if (have_leaf ) {
537- if (Lf -> fsdir && Lf -> fsdir [0 ] && strcmp (Lf -> fsdir , "/" ) != 0 ) {
538- /* We have a non-root mount point, show mount/.../leaf */
539- (void )snpf (Namech , Namechl , "%s/.../%s" , Lf -> fsdir , leafname );
538+ if (Lf -> fsdir && Lf -> fsdir [0 ] &&
539+ strcmp (Lf -> fsdir , "/" ) != 0 ) {
540+ /* We have a non-root mount point, show mount/.../leaf
541+ */
542+ (void )snpf (Namech , Namechl , "%s/.../%s" , Lf -> fsdir ,
543+ leafname );
540544 } else if (Lf -> fsdir && strcmp (Lf -> fsdir , "/" ) == 0 ) {
541545 /* Root filesystem, show /.../leaf */
542546 (void )snpf (Namech , Namechl , "/.../%s" , leafname );
0 commit comments