X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=lib%2Fsocket-util.c;fp=lib%2Fsocket-util.c;h=d537434879ccf085304c085979aad1fcae421378;hb=3b01baa3970139c3a195017ab1ea3e42761e3db2;hp=e5b86e42773a4105c9cac09a1b5b99523ff5124c;hpb=080ec396fd98fa6848295a7582c3fbfeb0a3589d;p=sliver-openvswitch.git diff --git a/lib/socket-util.c b/lib/socket-util.c index e5b86e427..d53743487 100644 --- a/lib/socket-util.c +++ b/lib/socket-util.c @@ -466,6 +466,24 @@ exit: return error ? -error : fd; } +/* 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 int null_fd = -1; + if (null_fd < 0) { + null_fd = open("/dev/null", O_RDWR); + if (null_fd < 0) { + int error = errno; + VLOG_ERR("could not open /dev/null: %s", strerror(error)); + return -error; + } + } + return null_fd; +} + int read_fully(int fd, void *p_, size_t size, size_t *bytes_read) {