vnc: Fixes for unix socket error handling
v3 cover vnc: Fixes for unix socket error handling
Minor fixes for unix socket error handling, see patches for details
v3:
Scoop up the v2 of patch 3
Fix checkpatch warnings
Cole Robinson (3):
vnc: Don't assert if opening unix socket fails
vnc: Tweak error when init fails
qemu-sockets: Report explicit error if unlink fails
ui/vnc.c | 6 ++++-- util/qemu-sockets.c | 7 ++++++- 2 files changed, 10 insertions(+), 3 deletions(-)
Signature · 1 line
2.4.0
PATCH v3 1/3 vnc: Don't assert if opening unix socket fails
Reproducer:
$ qemu-system-x86_64 -display vnc=unix:/root/i-cant-access-you.sock qemu-system-x86_64: iohandler.c:60: qemu_set_fd_handler2: Assertion `fd >= 0' failed. Aborted (core dumped)
---
v3:
Fix checkpatch warning
ui/vnc.c | 3 +++ 1 file changed, 3 insertions(+)
ui/vnc.c +3 -0
@@ -3685,6 +3685,9 @@ void vnc_display_open(const char *id, Error **errp)/* listen for connects */ if (strncmp (vnc,"unix:" ,5 ) ==0 ) { vs->lsock =unix_listen (vnc+5 ,NULL ,0 , errp); +if (vs->lsock <0 ) { + goto fail; + } vs->is_unix = true; }else { vs->lsock =inet_listen_opts (sopts,5900 , errp);
Signature · 1 line
2.4.0
PATCH v3 2/3 vnc: Tweak error when init fails
In reply to Cole RobinsonBefore:
qemu-system-x86_64: -display vnc=unix:/root/foo.sock: Failed to start VNC server on `(null)': Failed to bind socket to /root/foo.sock: Permission denied
After:
qemu-system-x86_64: -display vnc=unix:/root/foo.sock: Failed to start VNC server: Failed to bind socket to /root/foo.sock: Permission denied
Rather than tweak the string possibly show unix: value as well, just drop the explicit display reporting. We already get the cli string in the error message, that should be sufficient.
---
v3:
No change
ui/vnc.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
ui/vnc.c +1 -2
@@ -3780,8 +3780,7 @@ int vnc_init_func(QemuOpts *opts, void *opaque)vnc_display_init (id);vnc_display_open (id, &local_err);if (local_err !=NULL ) { -error_report ("Failed to start VNC server on `%s': %s" , -qemu_opt_get (opts,"display" ), +error_report ("Failed to start VNC server: %s" ,error_get_pretty (local_err));error_free (local_err);exit (1 );
Signature · 1 line
2.4.0
PATCH v3 3/3 qemu-sockets: Report explicit error if unlink fails
In reply to Cole RobinsonConsider this case:
$ ls -ld ~/root-owned/ drwx--x--x. 2 root root 4096 Apr 29 12:55 /home/crobinso/root-owned/ $ ls -l ~/root-owned/foo.sock -rwxrwxrwx. 1 crobinso crobinso 0 Apr 29 12:55 /home/crobinso/root-owned/foo.sock
$ qemu-system-x86_64 -vnc unix:~/root-owned/foo.sock qemu-system-x86_64: -vnc unix:/home/crobinso/root-owned/foo.sock: Failed to start VNC server: Failed to bind socket to /home/crobinso/root-owned/foo.sock: Address already in use
...which is techinically true, but the real error is that we failed to unlink. So report it.
This may seem pathological but it's a real possibility via libvirt.
---
v3:
Fix checkpatch warning
util/qemu-sockets.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
util/qemu-sockets.c +6 -1
@@ -729,7 +729,12 @@ int unix_listen_opts(QemuOpts *opts, Error **errp)qemu_opt_set (opts,"path" , un.sun_path, &error_abort); } -unlink (un.sun_path); +if ((access (un.sun_path,F_OK ) ==0 ) && +unlink (un.sun_path) <0 ) { +error_setg_errno (errp, errno, +"Failed to unlink socket %s" , un.sun_path); + goto err; + }if (bind (sock, (struct sockaddr *) &un,sizeof (un)) <0 ) {error_setg_errno (errp, errno,"Failed to bind socket to %s" , un.sun_path); goto err;
Signature · 1 line
2.4.0
Quoted 5 lines · Cole Robinson
Minor fixes for unix socket error handling, see patches for details
v3:
Scoop up the v2 of patch 3
Fix checkpatch warnings
Quoted 10 lines
Cole Robinson (3):
vnc: Don't assert if opening unix socket fails
vnc: Tweak error when init fails
qemu-sockets: Report explicit error if unlink failsui/vnc.c | 6 ++++-- util/qemu-sockets.c | 7 ++++++- 2 files changed, 10 insertions(+), 3 deletions(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 1 line · Cole Robinson
Minor fixes for unix socket error handling, see patches for details
added to vnc queue.
thanks,
Gerd