socket-util: Move get_null_fd() to daemon.c.
authorGurucharan Shetty <gshetty@nicira.com>
Fri, 21 Feb 2014 18:52:18 +0000 (10:52 -0800)
committerGurucharan Shetty <gshetty@nicira.com>
Fri, 21 Feb 2014 22:44:31 +0000 (14:44 -0800)
get_null_fd() is only called from daemon.c.
It does not need thread safety features anymore as
it is called either through daemonize_start() or
indirectly through daemonize_complete() once.

Signed-off-by: Gurucharan Shetty <gshetty@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
lib/daemon.c
lib/socket-util.c
lib/socket-util.h

index f9290ef..9d96cba 100644 (file)
@@ -441,6 +441,26 @@ monitor_daemon(pid_t daemon_pid)
     set_subprogram_name("");
 }
 
+/* Returns a readable and writable fd for /dev/null, if successful, otherwise
+ * a negative errno value.  The caller must not close the returned fd (because
+ * the same fd will be handed out to subsequent callers). */
+static int
+get_null_fd(void)
+{
+    static int null_fd;
+
+    if (!null_fd) {
+        null_fd = open("/dev/null", O_RDWR);
+        if (null_fd < 0) {
+            int error = errno;
+            VLOG_ERR("could not open /dev/null: %s", ovs_strerror(error));
+            null_fd = -error;
+        }
+    }
+
+    return null_fd;
+}
+
 /* Close standard file descriptors (except any that the client has requested we
  * leave open by calling daemon_save_fd()).  If we're started from e.g. an SSH
  * session, then this keeps us from holding that session open artificially. */
index a13a59c..6bc5d2c 100644 (file)
@@ -925,28 +925,6 @@ error:
     return -error;
 }
 
-/* Returns a readable and writable fd for /dev/null, if successful, otherwise
- * a negative errno value.  The caller must not close the returned fd (because
- * the same fd will be handed out to subsequent callers). */
-int
-get_null_fd(void)
-{
-    static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER;
-    static int null_fd;
-
-    if (ovsthread_once_start(&once)) {
-        null_fd = open("/dev/null", O_RDWR);
-        if (null_fd < 0) {
-            int error = errno;
-            VLOG_ERR("could not open /dev/null: %s", ovs_strerror(error));
-            null_fd = -error;
-        }
-        ovsthread_once_done(&once);
-    }
-
-    return null_fd;
-}
-
 int
 read_fully(int fd, void *p_, size_t size, size_t *bytes_read)
 {
index f7f128a..61372f8 100644 (file)
@@ -46,7 +46,6 @@ int make_unix_socket(int style, bool nonblock,
 int get_unix_name_len(socklen_t sun_len);
 #endif
 ovs_be32 guess_netmask(ovs_be32 ip);
-int get_null_fd(void);
 
 bool inet_parse_active(const char *target, uint16_t default_port,
                        struct sockaddr_storage *ssp);