Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Andy Zhou <azhou@nicira.com>
- static int max_fds = -1;
- if (max_fds < 0) {
+ static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER;
+ static int max_fds;
+
+ if (ovsthread_once_start(&once)) {
struct rlimit r;
if (!getrlimit(RLIMIT_NOFILE, &r) && rlim_is_finite(r.rlim_cur)) {
max_fds = r.rlim_cur;
struct rlimit r;
if (!getrlimit(RLIMIT_NOFILE, &r) && rlim_is_finite(r.rlim_cur)) {
max_fds = r.rlim_cur;
VLOG_WARN("failed to obtain fd limit, defaulting to 1024");
max_fds = 1024;
}
VLOG_WARN("failed to obtain fd limit, defaulting to 1024");
max_fds = 1024;
}
+ ovsthread_once_done(&once);
- static int null_fd = -1;
- if (null_fd < 0) {
+ 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 = open("/dev/null", O_RDWR);
if (null_fd < 0) {
int error = errno;
VLOG_ERR("could not open /dev/null: %s", ovs_strerror(error));
+ ovsthread_once_done(&once);