Skip to content

Commit 070b7bc

Browse files
committed
src/bindings: introduce a get_pidns_ino helper
Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
1 parent e67e4e0 commit 070b7bc

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

src/bindings.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -562,19 +562,30 @@ static pid_t scm_init_pid(pid_t task)
562562
return pid_ret;
563563
}
564564

565-
pid_t lookup_initpid_in_store(pid_t pid)
565+
static ino_t get_pidns_ino(pid_t pid)
566566
{
567-
pid_t hashed_pid = 0;
568567
char path[LXCFS_PROC_PID_NS_LEN];
569568
struct stat st;
570569

571570
snprintf(path, sizeof(path), "/proc/%d/ns/pid", pid);
572571
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)
573584
return ret_errno(ESRCH);
574585

575586
store_lock();
576587

577-
hashed_pid = lookup_verify_initpid(st.st_ino);
588+
hashed_pid = lookup_verify_initpid(pidns_ino);
578589
if (hashed_pid < 0) {
579590
pid_t already_hashed_pid;
580591

@@ -586,17 +597,17 @@ pid_t lookup_initpid_in_store(pid_t pid)
586597
store_lock();
587598

588599
/* 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);
590601

591602
/* no existing entry found. Just add a new one. */
592603
if (already_hashed_pid < 0) {
593604
if (hashed_pid > 0)
594-
save_initpid(st.st_ino, hashed_pid);
605+
save_initpid(pidns_ino, hashed_pid);
595606

596607
/* entry found it must have the same pid */
597608
} else if (already_hashed_pid != hashed_pid) {
598609
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));
600611
hashed_pid = -1;
601612
}
602613
}

0 commit comments

Comments
 (0)