Skip to content

Commit 52f814d

Browse files
committed
src/bindings: add iter_initpid_store helper
Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
1 parent 070b7bc commit 52f814d

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
@@ -312,6 +312,27 @@ static void clear_initpid_store(void)
312312
store_unlock();
313313
}
314314

315+
int iter_initpid_store(pidns_store_iter_func_t f, void *data)
316+
{
317+
int ret;
318+
319+
if (!pidns_hash_table)
320+
return 0;
321+
322+
store_lock();
323+
for (int i = 0; i < PIDNS_HASH_SIZE; i++) {
324+
for (struct pidns_store *entry = pidns_hash_table[i]; entry; entry = entry->next) {
325+
ret = f(entry, data);
326+
if (ret)
327+
goto out;
328+
}
329+
}
330+
331+
out:
332+
store_unlock();
333+
return ret;
334+
}
335+
315336
/* Must be called under store_lock */
316337
static void save_initpid(ino_t pidns_inode, pid_t pid)
317338
{

src/bindings.h

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

175+
typedef int (*pidns_store_iter_func_t) (struct pidns_store *cur, void *data);
175176

177+
extern int iter_initpid_store(pidns_store_iter_func_t f, void *data);
176178
extern pid_t lookup_initpid_in_store(pid_t qpid);
177179
extern void prune_init_slice(char *cg);
178180
extern bool supports_pidfd(void);

0 commit comments

Comments
 (0)