Skip to content

Commit 23fc603

Browse files
committed
src/bindings: add iter_initpid_store helper
Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
1 parent d0274a8 commit 23fc603

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/bindings.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,27 @@ static void clear_initpid_store(void)
330330
store_unlock();
331331
}
332332

333+
int iter_initpid_store(pidns_store_iter_func_t f, void *data)
334+
{
335+
int ret;
336+
337+
if (!pidns_hash_table)
338+
return 0;
339+
340+
store_lock();
341+
for (int i = 0; i < PIDNS_HASH_SIZE; i++) {
342+
for (struct pidns_store *entry = pidns_hash_table[i]; entry; entry = entry->next) {
343+
ret = f(entry, data);
344+
if (ret)
345+
goto out;
346+
}
347+
}
348+
349+
out:
350+
store_unlock();
351+
return ret;
352+
}
353+
333354
/* Must be called under store_lock */
334355
static void save_initpid(ino_t pidns_inode, pid_t pid)
335356
{

src/bindings.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,9 @@ typedef enum lxcfs_opt_t {
170170
LXCFS_OPTS_MAX = LXCFS_CFS_ON,
171171
} lxcfs_opt_t;
172172

173+
typedef int (*pidns_store_iter_func_t) (struct pidns_store *cur, void *data);
173174

175+
extern int iter_initpid_store(pidns_store_iter_func_t f, void *data);
174176
extern pid_t lookup_initpid_in_store(pid_t qpid);
175177
extern void prune_init_slice(char *cg);
176178
extern bool supports_pidfd(void);

0 commit comments

Comments
 (0)