[ovs-dev] [PATCH v2 4/4] socket-util: Move get_null_fd() to daemon.c.
Gurucharan Shetty
shettyg at nicira.com
Fri Feb 21 21:14:36 UTC 2014
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 at nicira.com>
---
lib/daemon.c | 20 ++++++++++++++++++++
lib/socket-util.c | 22 ----------------------
lib/socket-util.h | 1 -
3 files changed, 20 insertions(+), 23 deletions(-)
diff --git a/lib/daemon.c b/lib/daemon.c
index f9290ef..9d96cba 100644
--- a/lib/daemon.c
+++ b/lib/daemon.c
@@ -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. */
diff --git a/lib/socket-util.c b/lib/socket-util.c
index b59ce65..b6cc35a 100644
--- a/lib/socket-util.c
+++ b/lib/socket-util.c
@@ -927,28 +927,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)
{
diff --git a/lib/socket-util.h b/lib/socket-util.h
index 5566fcd..1dcc828 100644
--- a/lib/socket-util.h
+++ b/lib/socket-util.h
@@ -44,7 +44,6 @@ int make_unix_socket(int style, bool nonblock,
const char *bind_path, const char *connect_path);
int get_unix_name_len(socklen_t sun_len);
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);
--
1.7.9.5
More information about the dev
mailing list