Skip to content

Commit e67e4e0

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

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

src/bindings.c

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -355,14 +355,7 @@ static void save_initpid(ino_t pidns_inode, pid_t pid)
355355
lxcfs_debug("Added cache entry %d for pid %d to init pid cache", ino_hash, pid);
356356
}
357357

358-
/*
359-
* Given the stat(2) info for a nsfd pid inode, lookup the init_pid_store
360-
* entry for the inode number and creation time. Verify that the init pid
361-
* is still valid. If not, remove it. Return the entry if valid, NULL
362-
* otherwise.
363-
* Must be called under store_lock
364-
*/
365-
static pid_t lookup_verify_initpid(ino_t pidns_inode)
358+
static struct pidns_store *lookup_verify_pidns_entry(ino_t pidns_inode)
366359
{
367360
struct pidns_store *entry;
368361

@@ -375,16 +368,33 @@ static pid_t lookup_verify_initpid(ino_t pidns_inode)
375368
if (entry->ino == pidns_inode) {
376369
if (initpid_still_valid(entry)) {
377370
entry->lastcheck = time(NULL);
378-
return entry->initpid;
371+
return entry;
379372
}
380373

381374
remove_initpid(entry);
382-
return ret_errno(ESRCH);
375+
return NULL;
383376
}
384377
entry = entry->next;
385378
}
386379

387-
return ret_errno(ESRCH);
380+
return NULL;
381+
}
382+
383+
/*
384+
* Given the stat(2) info for a nsfd pid inode, lookup the init_pid_store
385+
* entry for the inode number and creation time. Verify that the init pid
386+
* is still valid. If not, remove it. Return the entry if valid, NULL
387+
* otherwise.
388+
* Must be called under store_lock
389+
*/
390+
static pid_t lookup_verify_initpid(ino_t pidns_inode)
391+
{
392+
struct pidns_store *entry = lookup_verify_pidns_entry(pidns_inode);
393+
394+
if (!entry)
395+
return ret_errno(ESRCH);
396+
397+
return entry->initpid;
388398
}
389399

390400
static bool send_creds_ok(int sock_fd)

0 commit comments

Comments
 (0)