X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;f=close_on_fork.c;h=7e0c8e6474b48a932ca0c107862391466415ec96;hb=21859dc53e11f56e76a5db0f105ee65a20d09ab9;hp=4f7c2b955a4d9f1404386f57b8246b803115a2bf;hpb=ebb0565e946770c5b83c4d28c1f674dffdeaf551;p=paraslash.git diff --git a/close_on_fork.c b/close_on_fork.c index 4f7c2b95..7e0c8e64 100644 --- a/close_on_fork.c +++ b/close_on_fork.c @@ -1,13 +1,13 @@ -/* - * Copyright (C) 2005-2008 Andre Noll - * - * Licensed under the GPL v2. For licencing details see COPYING. - */ +/* Copyright (C) 2005 Andre Noll , see file COPYING. */ /** \file close_on_fork.c Manage a list of fds that should be closed on fork. */ + +#include + #include "para.h" #include "list.h" #include "string.h" +#include "close_on_fork.h" static struct list_head close_on_fork_list; static int initialized; @@ -15,7 +15,7 @@ static int initialized; /** * Describes an element of the close-on-fork list. * - * \sa list.h + * \sa \ref list.h. */ struct close_on_fork { /** The file descriptor which should be closed after fork(). */ @@ -63,16 +63,21 @@ void del_close_on_fork_list(int fd) } /** - * Call close(3) for each fd in the close-on-fork list. + * Close all fds in the list and destroy all list entries. + * + * This function calls close(3) for each fd in the close-on-fork list + * and empties the list afterwards. */ void close_listed_fds(void) { - struct close_on_fork *cof; + struct close_on_fork *cof, *tmp; if (!initialized) return; - list_for_each_entry(cof, &close_on_fork_list, node) { + list_for_each_entry_safe(cof, tmp, &close_on_fork_list, node) { PARA_DEBUG_LOG("closing fd %d\n", cof->fd); close(cof->fd); + list_del(&cof->node); + free(cof); } }