@@ -562,19 +562,30 @@ static pid_t scm_init_pid(pid_t task)
562
562
return pid_ret ;
563
563
}
564
564
565
- pid_t lookup_initpid_in_store (pid_t pid )
565
+ static ino_t get_pidns_ino (pid_t pid )
566
566
{
567
- pid_t hashed_pid = 0 ;
568
567
char path [LXCFS_PROC_PID_NS_LEN ];
569
568
struct stat st ;
570
569
571
570
snprintf (path , sizeof (path ), "/proc/%d/ns/pid" , pid );
572
571
if (stat (path , & st ))
572
+ return 0 ;
573
+
574
+ return st .st_ino ;
575
+ }
576
+
577
+ pid_t lookup_initpid_in_store (pid_t pid )
578
+ {
579
+ pid_t hashed_pid = 0 ;
580
+ ino_t pidns_ino ;
581
+
582
+ pidns_ino = get_pidns_ino (pid );
583
+ if (!pidns_ino )
573
584
return ret_errno (ESRCH );
574
585
575
586
store_lock ();
576
587
577
- hashed_pid = lookup_verify_initpid (st . st_ino );
588
+ hashed_pid = lookup_verify_initpid (pidns_ino );
578
589
if (hashed_pid < 0 ) {
579
590
pid_t already_hashed_pid ;
580
591
@@ -586,17 +597,17 @@ pid_t lookup_initpid_in_store(pid_t pid)
586
597
store_lock ();
587
598
588
599
/* recheck that entry wasn't added while lock was released */
589
- already_hashed_pid = lookup_verify_initpid (st . st_ino );
600
+ already_hashed_pid = lookup_verify_initpid (pidns_ino );
590
601
591
602
/* no existing entry found. Just add a new one. */
592
603
if (already_hashed_pid < 0 ) {
593
604
if (hashed_pid > 0 )
594
- save_initpid (st . st_ino , hashed_pid );
605
+ save_initpid (pidns_ino , hashed_pid );
595
606
596
607
/* entry found it must have the same pid */
597
608
} else if (already_hashed_pid != hashed_pid ) {
598
609
lxcfs_error ("Different init pids (%d, %d) for the same cache entry %lu\n" ,
599
- already_hashed_pid , hashed_pid , HASH (st . st_ino ));
610
+ already_hashed_pid , hashed_pid , HASH (pidns_ino ));
600
611
hashed_pid = -1 ;
601
612
}
602
613
}
0 commit comments