diff mbox series

[ovs-dev,09/13] log: Support using /dev/stdin for opening logs read-only.

Message ID 20171208001240.25829-10-blp@ovn.org
State Accepted
Headers show
Series OVSDB log enhancements | expand

Commit Message

Ben Pfaff Dec. 8, 2017, 12:12 a.m. UTC
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>
---
 ovsdb/log.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Comments

Justin Pettit Dec. 23, 2017, 5:50 a.m. UTC | #1
> On Dec 7, 2017, at 4:12 PM, Ben Pfaff <blp@ovn.org> wrote:
> 
> 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>

--Justin
Ben Pfaff Dec. 24, 2017, 8:09 p.m. UTC | #2
On Fri, Dec 22, 2017 at 09:50:23PM -0800, Justin Pettit wrote:
> 
> > On Dec 7, 2017, at 4:12 PM, Ben Pfaff <blp@ovn.org> wrote:
> > 
> > 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>

Thanks, applied to master.
diff mbox series

Patch

diff --git a/ovsdb/log.c b/ovsdb/log.c
index 1769e12266d1..d25f766474dc 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"