2 * Copyright (C) 2005-2006 Andre Noll <maan@systemlinux.org>
4 * Licensed under the GPL v2. For licencing details see COPYING.
7 /** \file close_on_fork.c manage a list of fds that should be closed on fork */
12 static struct list_head close_on_fork_list
;
13 static int initialized
;
16 * describes an element of the close-on-fork list
20 struct close_on_fork
{
21 /** the file descriptor which should be closed after fork() */
23 /** the position in the close-on-fork list */
24 struct list_head node
;
28 * add one file descriptor to the close-on-fork list
30 * \param fd the file descriptor to add
32 void add_close_on_fork_list(int fd
)
34 struct close_on_fork
*cof
= para_malloc(sizeof(struct close_on_fork
));
37 INIT_LIST_HEAD(&close_on_fork_list
);
41 para_list_add(&cof
->node
, &close_on_fork_list
);
46 * delete one file descriptor from the close-on-fork list
48 * \param fd the file descriptor to delete
50 * Noop if \a fd does not belong to the close-on-fork list.
52 void del_close_on_fork_list(int fd
)
54 struct close_on_fork
*cof
, *tmp
;
58 list_for_each_entry_safe(cof
, tmp
, &close_on_fork_list
, node
) {
67 * call close(3) for each fd in the close-on-fork list
69 void close_listed_fds(void)
71 struct close_on_fork
*cof
;
75 list_for_each_entry(cof
, &close_on_fork_list
, node
) {
76 PARA_DEBUG_LOG("closing fd %d\n", cof
->fd
);