From eb8d3ed67cf66f571973d7ad324e607013c18e44 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Wed, 13 Jan 2010 09:55:52 -0800 Subject: [PATCH] ovsdb-client: Fix regression introduced with changes to daemonize(). daemonize() now closes the standard file descriptors, but ovsdb-client's "monitor" command uses stdout even after daemonizing. This caused tests that used "ovsdb-client --detach monitor" to fail without printing their complete output. This commit fixes the problem. --- ovsdb/ovsdb-client.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/ovsdb/ovsdb-client.c b/ovsdb/ovsdb-client.c index 87cb514fd..baf525d4e 100644 --- a/ovsdb/ovsdb-client.c +++ b/ovsdb/ovsdb-client.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009 Nicira Networks. + * Copyright (c) 2009, 2010 Nicira Networks. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -842,7 +842,14 @@ do_monitor(int argc, char *argv[]) && json_equal(msg->id, request_id)) { monitor_print(msg->result, table, &columns, true); fflush(stdout); - daemonize(); + if (get_detach()) { + /* daemonize() closes the standard file descriptors. We output + * to stdout, so we need to save and restore STDOUT_FILENO. */ + int fd = dup(STDOUT_FILENO); + daemonize(); + dup2(fd, STDOUT_FILENO); + close(fd); + } } else if (msg->type == JSONRPC_NOTIFY && !strcmp(msg->method, "update")) { struct json *params = msg->params; -- 2.45.2