vl: avoid closing stdout with 'writeconfig'
authorChen Gang <gang.chen.5i5j@gmail.com>
Tue, 22 Apr 2014 01:12:34 +0000 (09:12 +0800)
committerMichael Tokarev <mjt@tls.msk.ru>
Mon, 28 Apr 2014 04:55:31 +0000 (08:55 +0400)
'writeconfig' supports output to stdout (with '-'); when that happens,
we must not close stdout, or further command line options that also use
stdout will be impacted. (Although 'writeconfig' was copied from
'readconfig', the latter does not have the problem because it does not
support reading from '-')

Signed-off-by: Chen Gang <gang.chen.5i5j@gmail.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
vl.c

diff --git a/vl.c b/vl.c
index 773649f023888f799f7bfb187ac72b3bdd28d12a..236f95efd795def44fb3ec165eead930500f3c20 100644 (file)
--- a/vl.c
+++ b/vl.c
@@ -3890,7 +3890,9 @@ int main(int argc, char **argv, char **envp)
                         }
                     }
                     qemu_config_write(fp);
-                    fclose(fp);
+                    if (fp != stdout) {
+                        fclose(fp);
+                    }
                     break;
                 }
             case QEMU_OPTION_qtest: