X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=close_on_fork.c;h=37f727e278c6b61cedede8e6a84e77db3ba4c74b;hp=299aab0b0f613750481657951837da1626ed9aff;hb=23b121a85984baa9252f4b4c0b8c4f186e394bb7;hpb=002731cd3938f3be6b71651e56c062af1adcdec0 diff --git a/close_on_fork.c b/close_on_fork.c index 299aab0b..37f727e2 100644 --- a/close_on_fork.c +++ b/close_on_fork.c @@ -1,10 +1,13 @@ /* - * Copyright (C) 2005-2009 Andre Noll + * Copyright (C) 2005-2013 Andre Noll * * Licensed under the GPL v2. For licencing details see 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" @@ -63,16 +66,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); } }