list: Fix indentation.
[openvswitch] / ovsdb / ovsdb-client.c
index 87cb514fd9b5716598cf95004cb4b4e8e8e9381e..e7d3b50def7d95d95340b8ec30aab0e10aaada6e 100644 (file)
@@ -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.
@@ -67,6 +67,7 @@ static void parse_options(int argc, char *argv[]);
 int
 main(int argc, char *argv[])
 {
+    proctitle_init(argc, argv);
     set_program_name(argv[0]);
     time_init();
     vlog_init();
@@ -832,6 +833,7 @@ do_monitor(int argc, char *argv[])
 
         error = jsonrpc_recv_block(rpc, &msg);
         if (error) {
+            ovsdb_schema_destroy(schema);
             ovs_fatal(error, "%s: receive failed", argv[1]);
         }
 
@@ -842,7 +844,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;
@@ -854,6 +863,7 @@ do_monitor(int argc, char *argv[])
                 fflush(stdout);
             }
         }
+        jsonrpc_msg_destroy(msg);
     }
 }