diff options
author | Ben Pfaff <blp@ovn.org> | 2017-10-06 11:40:00 -0700 |
---|---|---|
committer | Ben Pfaff <blp@ovn.org> | 2017-12-24 12:06:29 -0800 |
commit | 71e4030fba417085022a459bb03cbb5a98fa8b23 (patch) | |
tree | 72fcbf6c5bffaea9d32ce77c4c3dc0e3e5b6d89d /ovsdb/log.c | |
parent | bb9c57d658f37c11d18abc6b8e626697a32e5b80 (diff) | |
download | openvswitch-71e4030fba417085022a459bb03cbb5a98fa8b23.tar.gz |
log: Support using /dev/stdin for opening logs read-only.
On Unix-like systems, usually /dev/stdin opens a duplicate of fd 0, and
this will be convenient in a few places later on. This commit makes this
support universal.
Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Justin Pettit <jpettit@ovn.org>
Diffstat (limited to 'ovsdb/log.c')
-rw-r--r-- | ovsdb/log.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/ovsdb/log.c b/ovsdb/log.c index 56c642bba..65103b61e 100644 --- a/ovsdb/log.c +++ b/ovsdb/log.c @@ -166,7 +166,13 @@ ovsdb_log_open(const char *name, const char *magic, #ifdef _WIN32 flags = flags | O_BINARY; #endif - fd = open(name, flags, 0666); + /* Special case for /dev/stdin to make it work even if the operating system + * doesn't support it under that name. */ + if (!strcmp(name, "/dev/stdin") && open_mode == OVSDB_LOG_READ_ONLY) { + fd = dup(STDIN_FILENO); + } else { + fd = open(name, flags, 0666); + } if (fd < 0) { const char *op = (open_mode == OVSDB_LOG_CREATE_EXCL ? "create" : open_mode == OVSDB_LOG_CREATE ? "create or open" |