[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 10/19] qemu-char: Chardev open error reporting, !_WI
From: |
Markus Armbruster |
Subject: |
[Qemu-devel] [PATCH 10/19] qemu-char: Chardev open error reporting, !_WIN32 part |
Date: |
Tue, 7 Feb 2012 15:09:17 +0100 |
This part takes care of backends "file", "pipe", "pty" and "stdio".
Unlike many other backends, these leave open error reporting to their
caller. Because the caller doesn't know what went wrong, this results
in a pretty useless error message.
Change them to report their errors. Improves comically user-hostile
messages like this one for "-chardev file,id=foo,path=/x"
chardev: opening backend "file" failed
to
qemu-system-x86_64: -chardev file,id=foo,path=/x: Can't create file '/x':
Permission denied
chardev: opening backend "file" failed
The useless "opening backend failed" message will be cleaned up
shortly.
Signed-off-by: Markus Armbruster <address@hidden>
---
qemu-char.c | 19 +++++++++++++++----
1 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/qemu-char.c b/qemu-char.c
index d591f70..47bab4f 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -636,11 +636,18 @@ static CharDriverState *qemu_chr_open_fd(int fd_in, int
fd_out)
static CharDriverState *qemu_chr_open_file_out(QemuOpts *opts)
{
+ const char *filename = qemu_opt_get(opts, "path");
int fd_out;
- TFR(fd_out = qemu_open(qemu_opt_get(opts, "path"),
- O_WRONLY | O_TRUNC | O_CREAT | O_BINARY, 0666));
+ if (!filename) {
+ error_report("file character device requires parameter path");
+ return NULL;
+ }
+
+ TFR(fd_out = qemu_open(filename,
+ O_WRONLY | O_TRUNC | O_CREAT | O_BINARY, 0666));
if (fd_out < 0) {
+ error_report("Can't create file '%s': %s", filename, strerror(errno));
return NULL;
}
return qemu_chr_open_fd(-1, fd_out);
@@ -653,7 +660,7 @@ static CharDriverState *qemu_chr_open_pipe(QemuOpts *opts)
const char *filename = qemu_opt_get(opts, "path");
if (filename == NULL) {
- fprintf(stderr, "chardev: pipe: no filename given\n");
+ error_report("pipe character device requires parameter path");
return NULL;
}
@@ -668,6 +675,8 @@ static CharDriverState *qemu_chr_open_pipe(QemuOpts *opts)
close(fd_out);
TFR(fd_in = fd_out = qemu_open(filename, O_RDWR | O_BINARY));
if (fd_in < 0) {
+ error_report("Can't create pipe '%s': %s",
+ filename, strerror(errno));
return NULL;
}
}
@@ -767,6 +776,7 @@ static CharDriverState *qemu_chr_open_stdio(QemuOpts *opts)
CharDriverState *chr;
if (stdio_nb_clients >= STDIO_MAX_CLIENTS) {
+ error_report("Too many stdio devices");
return NULL;
}
if (stdio_nb_clients == 0) {
@@ -987,6 +997,7 @@ static CharDriverState *qemu_chr_open_pty(QemuOpts *opts)
#endif
if (openpty(&master_fd, &slave_fd, pty_name, NULL, NULL) < 0) {
+ error_report("Can't open pty: %s", strerror(errno));
return NULL;
}
@@ -1002,7 +1013,7 @@ static CharDriverState *qemu_chr_open_pty(QemuOpts *opts)
chr->filename = g_malloc(len);
snprintf(chr->filename, len, "pty:%s", q_ptsname(master_fd));
qemu_opt_set(opts, "path", q_ptsname(master_fd));
- fprintf(stderr, "char device redirected to %s\n", q_ptsname(master_fd));
+ error_printf("char device redirected to %s\n", q_ptsname(master_fd));
s = g_malloc0(sizeof(PtyCharDriver));
chr->opaque = s;
--
1.7.6.5
- Re: [Qemu-devel] [PATCH 02/19] qemu-char: Use qemu_open() to avoid leaking fds to children, (continued)
- [Qemu-devel] [PATCH 13/19] qemu-char: Chardev open error reporting, parport part, Markus Armbruster, 2012/02/07
- [Qemu-devel] [PATCH 08/19] sockets: Clean up inet_listen_opts()'s convoluted bind() loop, Markus Armbruster, 2012/02/07
- [Qemu-devel] [PATCH 04/19] qemu-char: qemu_chr_open_fd() can't fail, don't check, Markus Armbruster, 2012/02/07
- [Qemu-devel] [PATCH 07/19] sockets: Drop sockets_debug debug code, Markus Armbruster, 2012/02/07
- [Qemu-devel] [PATCH 06/19] gdbstub: Error locations for -gdb, Markus Armbruster, 2012/02/07
- [Qemu-devel] [PATCH 14/19] console: Eliminate text_consoles[], Markus Armbruster, 2012/02/07
- [Qemu-devel] [PATCH 10/19] qemu-char: Chardev open error reporting, !_WIN32 part,
Markus Armbruster <=
- Re: [Qemu-devel] [PATCH 10/19] qemu-char: Chardev open error reporting, !_WIN32 part, Kevin Wolf, 2012/02/07
- Re: [Qemu-devel] [PATCH 10/19] qemu-char: Chardev open error reporting, !_WIN32 part, Markus Armbruster, 2012/02/09
- Re: [Qemu-devel] [PATCH 10/19] qemu-char: Chardev open error reporting, !_WIN32 part, Kevin Wolf, 2012/02/09
- Re: [Qemu-devel] [PATCH 10/19] qemu-char: Chardev open error reporting, !_WIN32 part, Markus Armbruster, 2012/02/09
- Re: [Qemu-devel] [PATCH 10/19] qemu-char: Chardev open error reporting, !_WIN32 part, Luiz Capitulino, 2012/02/09
- Re: [Qemu-devel] [PATCH 10/19] qemu-char: Chardev open error reporting, !_WIN32 part, Markus Armbruster, 2012/02/09
[Qemu-devel] [PATCH 03/19] qemu-char: Re-apply style fixes from just reverted aad04cd0, Markus Armbruster, 2012/02/07
[Qemu-devel] [PATCH 17/19] baum: Chardev open error reporting, braille part, Markus Armbruster, 2012/02/07
[Qemu-devel] [PATCH 11/19] qemu-char: Chardev open error reporting, _WIN32 part, Markus Armbruster, 2012/02/07