File tree Expand file tree Collapse file tree 1 file changed +16
-2
lines changed Expand file tree Collapse file tree 1 file changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -566,15 +566,29 @@ pid_t lookup_initpid_in_store(pid_t pid)
566
566
567
567
hashed_pid = lookup_verify_initpid (st .st_ino );
568
568
if (hashed_pid < 0 ) {
569
+ pid_t already_hashed_pid ;
570
+
569
571
/* release the mutex as the following call is expensive */
570
572
store_unlock ();
571
573
572
574
hashed_pid = scm_init_pid (pid );
573
575
574
576
store_lock ();
575
577
576
- if (hashed_pid > 0 )
577
- save_initpid (st .st_ino , hashed_pid );
578
+ /* recheck that entry wasn't added while lock was released */
579
+ already_hashed_pid = lookup_verify_initpid (st .st_ino );
580
+
581
+ /* no existing entry found. Just add a new one. */
582
+ if (already_hashed_pid < 0 ) {
583
+ if (hashed_pid > 0 )
584
+ save_initpid (st .st_ino , hashed_pid );
585
+
586
+ /* entry found it must have the same pid */
587
+ } else if (already_hashed_pid != hashed_pid ) {
588
+ lxcfs_error ("Different init pids (%d, %d) for the same cache entry %lu\n" ,
589
+ already_hashed_pid , hashed_pid , HASH (st .st_ino ));
590
+ hashed_pid = -1 ;
591
+ }
578
592
}
579
593
580
594
/*
You can’t perform that action at this time.
0 commit comments