X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;f=close_on_fork.c;h=809f027e278d44f4413482ba433b8893b8be0843;hb=501b83a39828c9d3db5498c7352a2e5b60175bba;hp=7e0c8e6474b48a932ca0c107862391466415ec96;hpb=767a4a54c967bc4b80bd14d02e89fe91acd848dd;p=paraslash.git diff --git a/close_on_fork.c b/close_on_fork.c index 7e0c8e64..809f027e 100644 --- a/close_on_fork.c +++ b/close_on_fork.c @@ -31,10 +31,10 @@ struct close_on_fork { */ void add_close_on_fork_list(int fd) { - struct close_on_fork *cof = para_malloc(sizeof(struct close_on_fork)); + struct close_on_fork *cof = alloc(sizeof(struct close_on_fork)); if (!initialized) { - INIT_LIST_HEAD(&close_on_fork_list); + init_list_head(&close_on_fork_list); initialized = 1; } cof->fd = fd; @@ -62,13 +62,7 @@ void del_close_on_fork_list(int fd) } } -/** - * 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) +static void deplete_cof_list(bool close_fds) { struct close_on_fork *cof, *tmp; @@ -76,8 +70,32 @@ void close_listed_fds(void) return; list_for_each_entry_safe(cof, tmp, &close_on_fork_list, node) { PARA_DEBUG_LOG("closing fd %d\n", cof->fd); - close(cof->fd); + if (close_fds) + close(cof->fd); list_del(&cof->node); free(cof); } } + +/** + * 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. + * + * \sa \ref deplete_close_on_fork_list(). + */ +void close_listed_fds(void) +{ + deplete_cof_list(true); +} + +/** + * Remove all listed fds from the close on fork list. + * + * This is like \ref close_listed_fds() but does not close the fds. + */ +void deplete_close_on_fork_list(void) +{ + deplete_cof_list(false); +}