* This work is licensed under the terms of the GNU GPL, version 2 or later.
* See the COPYING file in the top-level directory.
*/
+
#include "qemu/osdep.h"
#include <getopt.h>
#include <libgen.h>
+#ifndef _WIN32
+#include <termios.h>
+#endif
#include "qapi/error.h"
#include "qemu-io.h"
#include "qemu/readline.h"
#include "qemu/log.h"
#include "qapi/qmp/qstring.h"
-#include "qapi/qmp/qbool.h"
+#include "qapi/qmp/qdict.h"
#include "qom/object_interfaces.h"
#include "sysemu/block-backend.h"
#include "block/block_int.h"
static ReadLineState *readline_state;
+static int ttyEOF;
+
+static int get_eof_char(void)
+{
+#ifdef _WIN32
+ return 0x4; /* Ctrl-D */
+#else
+ struct termios tty;
+ if (tcgetattr(STDIN_FILENO, &tty) != 0) {
+ if (errno == ENOTTY) {
+ return 0x0; /* just expect read() == 0 */
+ } else {
+ return 0x4; /* Ctrl-D */
+ }
+ }
+
+ return tty.c_cc[VEOF];
+#endif
+}
+
static int close_f(BlockBackend *blk, int argc, char **argv)
{
blk_unref(qemuio_blk);
readline_start(readline_state, get_prompt(), 0, readline_func, &line);
while (!line) {
int ch = getchar();
- if (ch == EOF) {
+ if (ttyEOF != 0x0 && ch == ttyEOF) {
+ printf("\n");
break;
}
readline_handle_byte(readline_state, ch);
#endif
module_call_init(MODULE_INIT_TRACE);
- progname = basename(argv[0]);
+ progname = g_path_get_basename(argv[0]);
qemu_init_exec_dir(argv[0]);
qcrypto_init(&error_fatal);
qemuio_add_command(&close_cmd);
if (isatty(STDIN_FILENO)) {
+ ttyEOF = get_eof_char();
readline_state = readline_init(readline_printf_func,
readline_flush_func,
NULL,