2 * Copyright (C) 2005-2006 Andre Noll <maan@systemlinux.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
19 /** \file close_on_fork.c manage a list of fds that should be closed on fork */
24 static struct list_head close_on_fork_list
;
25 static int initialized
;
28 * describes an element of the close-on-fork list
32 struct close_on_fork
{
33 /** the file descriptor which should be closed after fork() */
35 /** the position in the close-on-fork list */
36 struct list_head node
;
40 * add one file descriptor to the close-on-fork list
42 * \param fd the file descriptor to add
44 void add_close_on_fork_list(int fd
)
46 struct close_on_fork
*cof
= para_malloc(sizeof(struct close_on_fork
));
49 INIT_LIST_HEAD(&close_on_fork_list
);
53 para_list_add(&cof
->node
, &close_on_fork_list
);
58 * delete one file descriptor from the close-on-fork list
60 * \param fd the file descriptor to delete
62 * Noop if \a fd does not belong to the close-on-fork list.
64 void del_close_on_fork_list(int fd
)
66 struct close_on_fork
*cof
, *tmp
;
70 list_for_each_entry_safe(cof
, tmp
, &close_on_fork_list
, node
) {
79 * call close(3) for each fd in the close-on-fork list
81 void close_listed_fds(void)
83 struct close_on_fork
*cof
;
87 list_for_each_entry(cof
, &close_on_fork_list
, node
) {
88 PARA_DEBUG_LOG("closing fd %d\n", cof
->fd
);