afh: Move audio_format_name() up.
[paraslash.git] / close_on_fork.c
index fb1906462b30b74935a64d53370c9810046df771..28c5eabb1ae9a4821b60b638be559e837dc54f36 100644 (file)
@@ -1,8 +1,4 @@
-/*
- * Copyright (C) 2005-2009 Andre Noll <maan@systemlinux.org>
- *
- * Licensed under the GPL v2. For licencing details see COPYING.
- */
+/* Copyright (C) 2005 Andre Noll <maan@tuebingen.mpg.de>, see file COPYING. */
 
 /** \file close_on_fork.c Manage a list of fds that should be closed on fork. */
 
@@ -11,6 +7,7 @@
 #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;
@@ -18,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(). */
@@ -65,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;
 
@@ -79,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);
+}