From: Gurucharan Shetty Date: Fri, 21 Feb 2014 18:52:18 +0000 (-0800) Subject: socket-util: Move get_null_fd() to daemon.c. X-Git-Tag: sliver-openvswitch-2.1.90-1~1^2~6 X-Git-Url: http://git.onelab.eu/?p=sliver-openvswitch.git;a=commitdiff_plain;h=fb14862dcf197ed025a3a337ca47c2f5e9560c0d socket-util: Move get_null_fd() to daemon.c. 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 Acked-by: Ben Pfaff --- diff --git a/lib/daemon.c b/lib/daemon.c index f9290efbd..9d96cba8b 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 a13a59cfd..6bc5d2cba 100644 --- a/lib/socket-util.c +++ b/lib/socket-util.c @@ -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) { diff --git a/lib/socket-util.h b/lib/socket-util.h index f7f128a3f..61372f8a7 100644 --- a/lib/socket-util.h +++ b/lib/socket-util.h @@ -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);