Navigation Menu

Skip to content

Commit

Permalink
log: Support using /dev/stdin for opening logs read-only.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
blp committed Dec 24, 2017
1 parent bb9c57d commit 71e4030
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion ovsdb/log.c
Expand Up @@ -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"
Expand Down

0 comments on commit 71e4030

Please sign in to comment.