Simple qemu-ga fixes and cleanups
cover Simple qemu-ga fixes and cleanups
Markus Armbruster (6):
qemu-ga: Document intentional fall through in channel_event_cb()
qemu-ga: Drop pointless lseek() from ga_open_pidfile()
qemu-ga: Plug file descriptor leak on ga_open_pidfile() error path
qemu-ga: Plug fd leak on ga_channel_listen_accept() error path
qemu-ga: Plug fd leak on ga_channel_open() error paths
qemu-ga: Handle errors uniformely in ga_channel_open()
qga/channel-posix.c | 13 +++++++++---- qga/main.c | 5 ++++- 2 files changed, 13 insertions(+), 5 deletions(-)
Signature · 1 line
1.7.11.7
PATCH 1/6 qemu-ga: Document intentional fall through in channel_event_cb()
For clarity, and to hush up Coverity.
--- qga/main.c | 1 + 1 file changed, 1 insertion(+)
qga/main.c +1 -0
@@ -605,6 +605,7 @@ static gboolean channel_event_cb(GIOCondition condition, gpointer data)if (!s->virtio) {return false; } +/* fall through */ case G_IO_STATUS_AGAIN :/* virtio causes us to spin here when no process is attached to * host-side chardev. sleep a bit to mitigate this
Signature · 1 line
1.7.11.7
Re: [Qemu-devel] [PATCH 1/6] qemu-ga: Document intentional fall through in channel_event_cb()
Quoted 3 lines · Markus Armbruster
For clarity, and to hush up Coverity.
Signed-off-by Markus Armbruster <[email protected]>
Quoted 19 lines
--- qga/main.c | 1 + 1 file changed, 1 insertion(+)qga/main.c +1
-0@@ -605,6 +605,7 @@ static gboolean channel_event_cb(GIOCondition condition, gpointer data)if (!s->virtio) {return false; } +/* fall through */ case G_IO_STATUS_AGAIN :/* virtio causes us to spin here when no process is attached to * host-side chardev. sleep a bit to mitigate this Signature · 1 line
1.7.11.7
PATCH 2/6 qemu-ga: Drop pointless lseek() from ga_open_pidfile()
In reply to Markus ArmbrusterAfter open(), the file offset is already zero, and neither lockf() nor ftruncate() change it.
--- qga/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
qga/main.c +1 -1
@@ -276,7 +276,7 @@ static bool ga_open_pidfile(const char *pidfile)return false; } -if (ftruncate (pidfd,0 ) ||lseek (pidfd,0 ,SEEK_SET )) { +if (ftruncate (pidfd,0 )) {g_critical ("Failed to truncate pid file" ); goto fail; }
Signature · 1 line
1.7.11.7
Re: [Qemu-devel] [PATCH 2/6] qemu-ga: Drop pointless lseek() from ga_open_pidfile()
Quoted 4 lines · Markus Armbruster
After
open(), the file offset is already zero, and neitherlockf()norftruncate()change it.Signed-off-by Markus Armbruster <[email protected]>
Quoted 20 lines
--- qga/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)qga/main.c +1
-1@@ -276,7 +276,7 @@ static bool ga_open_pidfile(const char *pidfile)return false; } -if (ftruncate (pidfd,0 ) ||lseek (pidfd,0 ,SEEK_SET )) { +if (ftruncate (pidfd,0 )) {g_critical ("Failed to truncate pid file" ); goto fail; }Signature · 1 line
1.7.11.7
PATCH 3/6 qemu-ga: Plug file descriptor leak on ga_open_pidfile() error path
In reply to Markus ArmbrusterSpotted by Coverity. Also document why we keep it open on success.
--- qga/main.c | 2 ++ 1 file changed, 2 insertions(+)
qga/main.c +2 -0
@@ -286,10 +286,12 @@ static bool ga_open_pidfile(const char *pidfile) goto fail; } +/* keep pidfile open & locked forever */ return true; fail:unlink (pidfile); +close (pidfd);return false; }#else /* _WIN32 */
Signature · 1 line
1.7.11.7
Re: [Qemu-devel] [PATCH 3/6] qemu-ga: Plug file descriptor leak on ga_open_pidfile() error path
Quoted 3 lines · Markus Armbruster
Spotted by Coverity. Also document why we keep it open on success.
Signed-off-by Markus Armbruster <[email protected]>
Quoted 24 lines
--- qga/main.c | 2 ++ 1 file changed, 2 insertions(+)qga/main.c +2
-0@@ -286,10 +286,12 @@ static bool ga_open_pidfile(const char *pidfile) goto fail; } +/* keep pidfile open & locked forever */ return true; fail:unlink (pidfile); +close (pidfd);return false; }#else /* _WIN32 */ Signature · 1 line
1.7.11.7
PATCH 4/6 qemu-ga: Plug fd leak on ga_channel_listen_accept() error path
In reply to Markus ArmbrusterSpotted by Coverity.
--- qga/channel-posix.c | 1 + 1 file changed, 1 insertion(+)
qga/channel-posix.c +1 -0
@@ -45,6 +45,7 @@ static gboolean ga_channel_listen_accept(GIOChannel *channel, ret =ga_channel_client_add (c, client_fd);if (ret) {g_warning ("error setting up connection" ); +close (client_fd); goto out; } accepted = true;
Signature · 1 line
1.7.11.7
Re: [Qemu-devel] [PATCH 4/6] qemu-ga: Plug fd leak on ga_channel_listen_accept() error path
Quoted 3 lines · Markus Armbruster
Spotted by Coverity.
Signed-off-by Markus Armbruster <[email protected]>
Quoted 19 lines
--- qga/channel-posix.c | 1 + 1 file changed, 1 insertion(+)qga/channel-posix.c +1
-0@@ -45,6 +45,7 @@ static gboolean ga_channel_listen_accept(GIOChannel *channel, ret =ga_channel_client_add (c, client_fd);if (ret) {g_warning ("error setting up connection" ); +close (client_fd); goto out; } accepted = true;Signature · 1 line
1.7.11.7
PATCH 5/6 qemu-ga: Plug fd leak on ga_channel_open() error paths
In reply to Markus ArmbrusterSpotted by Coverity.
--- qga/channel-posix.c | 1 + 1 file changed, 1 insertion(+)
qga/channel-posix.c +1 -0
@@ -153,6 +153,7 @@ static gboolean ga_channel_open(GAChannel *c, const gchar *path, GAChannelMethod ret =ga_channel_client_add (c, fd);if (ret) {g_critical ("error adding channel to main loop" ); +close (fd);return false; }break ;
Signature · 1 line
1.7.11.7
Re: [Qemu-devel] [PATCH 5/6] qemu-ga: Plug fd leak on ga_channel_open() error paths
Quoted 3 lines · Markus Armbruster
Spotted by Coverity.
Signed-off-by Markus Armbruster <[email protected]>
Quoted 19 lines
--- qga/channel-posix.c | 1 + 1 file changed, 1 insertion(+)qga/channel-posix.c +1
-0@@ -153,6 +153,7 @@ static gboolean ga_channel_open(GAChannel *c, const gchar *path, GAChannelMethod ret =ga_channel_client_add (c, fd);if (ret) {g_critical ("error adding channel to main loop" ); +close (fd);return false; }break ;Signature · 1 line
1.7.11.7
PATCH 6/6 qemu-ga: Handle errors uniformely in ga_channel_open()
In reply to Markus ArmbrusterWe detect errors in seven places. One reports with g_error(), which calls abort(), the others report with g_critical(). Three of them exit(), three return false.
Always report with g_critical(), and return false.
--- qga/channel-posix.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
qga/channel-posix.c +7 -4
@@ -140,14 +140,15 @@ static gboolean ga_channel_open(GAChannel *c, const gchar *path, GAChannelMethod );if (fd ==-1 ) {g_critical ("error opening channel: %s" ,strerror (errno)); -exit (EXIT_FAILURE ); +return false; }#ifdef CONFIG_SOLARIS ret =ioctl (fd,I_SETSIG ,S_OUTPUT |S_INPUT |S_HIPRI );if (ret ==-1 ) {g_critical ("error setting event mask for channel: %s" ,strerror (errno)); -exit (EXIT_FAILURE ); +close (fd); +return false; }#endif ret =ga_channel_client_add (c, fd);
@@ -163,7 +164,7 @@ static gboolean ga_channel_open(GAChannel *c, const gchar *path, GAChannelMethodint fd =qemu_open (path,O_RDWR |O_NOCTTY |O_NONBLOCK );if (fd ==-1 ) {g_critical ("error opening channel: %s" ,strerror (errno)); -exit (EXIT_FAILURE ); +return false; }tcgetattr (fd, &tio);/* set up serial port for non-canonical, dumb byte streaming */
@@ -183,7 +184,9 @@ static gboolean ga_channel_open(GAChannel *c, const gchar *path, GAChannelMethodtcsetattr (fd,TCSANOW , &tio); ret =ga_channel_client_add (c, fd);if (ret) { -g_error ("error adding channel to main loop" ); +g_critical ("error adding channel to main loop" ); +close (fd); +return false; }break ; }
Signature · 1 line
1.7.11.7
Re: [Qemu-devel] [PATCH 6/6] qemu-ga: Handle errors uniformely in ga_channel_open()
Quoted 1 line · Markus Armbruster
We detect errors in seven places. One reports with
g_error(), which
Do you mean "in several places"? I can fix this in tree.
Quoted 6 lines
calls
abort(), the others report withg_critical(). Three of themexit(), three return false.Always report with
g_critical(), and return false.Signed-off-by Markus Armbruster <[email protected]>
Quoted 49 lines
--- qga/channel-posix.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)qga/channel-posix.c +7
-4@@ -140,14 +140,15 @@ static gboolean ga_channel_open(GAChannel *c, const gchar *path, GAChannelMethod );if (fd ==-1 ) {g_critical ("error opening channel: %s" ,strerror (errno)); -exit (EXIT_FAILURE ); +return false; }#ifdef CONFIG_SOLARIS ret =ioctl (fd,I_SETSIG ,S_OUTPUT |S_INPUT |S_HIPRI );if (ret ==-1 ) {g_critical ("error setting event mask for channel: %s" ,strerror (errno)); -exit (EXIT_FAILURE ); +close (fd); +return false; }#endif ret =ga_channel_client_add (c, fd);@@ -163,7 +164,7 @@ static gboolean ga_channel_open(GAChannel *c, const gchar *path, GAChannelMethodint fd =qemu_open (path,O_RDWR |O_NOCTTY |O_NONBLOCK );if (fd ==-1 ) {g_critical ("error opening channel: %s" ,strerror (errno)); -exit (EXIT_FAILURE ); +return false; }tcgetattr (fd, &tio);/* set up serial port for non-canonical, dumb byte streaming */ @@ -183,7 +184,9 @@ static gboolean ga_channel_open(GAChannel *c, const gchar *path, GAChannelMethodtcsetattr (fd,TCSANOW , &tio); ret =ga_channel_client_add (c, fd);if (ret) { -g_error ("error adding channel to main loop" ); +g_critical ("error adding channel to main loop" ); +close (fd); +return false; }break ; }Signature · 1 line
1.7.11.7
Re: [Qemu-devel] [PATCH 6/6] qemu-ga: Handle errors uniformely in ga_channel_open()
Quoted 4 lines · mdroth
Quoted 1 line · Markus Armbruster
We detect errors in seven places. One reports with
g_error(), whichDo you mean "in several places"? I can fix this in tree.
I counted seven places, but it doesn't really matter, "several" would be fine, too.
Quoted 8 lines
Quoted 6 lines
calls
abort(), the others report withg_critical(). Three of themexit(), three return false.Always report with
g_critical(), and return false.Signed-off-by Markus Armbruster <[email protected]>Reviewed-by Michael Roth <[email protected]>
Thanks!
Quoted 7 lines · Markus Armbruster
Markus Armbruster (6):
qemu-ga: Document intentional fall through inchannel_event_cb()
qemu-ga: Drop pointlesslseek()fromga_open_pidfile()
qemu-ga: Plug file descriptor leak onga_open_pidfile()error path
qemu-ga: Plug fd leak onga_channel_listen_accept()error path
qemu-ga: Plug fd leak onga_channel_open()error paths
qemu-ga: Handle errors uniformely inga_channel_open()
Series: Reviewed-by: Eric Blake <[email protected]>
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 7 lines · On Fri, 11 Jan 2013 11:24:56 +0100 Markus Armbruster <[email protected]> wrote:
Markus Armbruster (6):
qemu-ga: Document intentional fall through inchannel_event_cb()
qemu-ga: Drop pointlesslseek()fromga_open_pidfile()
qemu-ga: Plug file descriptor leak onga_open_pidfile()error path
qemu-ga: Plug fd leak onga_channel_listen_accept()error path
qemu-ga: Plug fd leak onga_channel_open()error paths
qemu-ga: Handle errors uniformely inga_channel_open()
series:
Quoted 5 lines
qga/channel-posix.c | 13 +++++++++---- qga/main.c | 5 ++++- 2 files changed, 13 insertions(+), 5 deletions(-)
mdroth
AppliedQuoted 11 lines · Markus Armbruster
Markus Armbruster (6):
qemu-ga: Document intentional fall through inchannel_event_cb()
qemu-ga: Drop pointlesslseek()fromga_open_pidfile()
qemu-ga: Plug file descriptor leak onga_open_pidfile()error path
qemu-ga: Plug fd leak onga_channel_listen_accept()error path
qemu-ga: Plug fd leak onga_channel_open()error paths
qemu-ga: Handle errors uniformely inga_channel_open()qga/channel-posix.c | 13 +++++++++---- qga/main.c | 5 ++++- 2 files changed, 13 insertions(+), 5 deletions(-)
Thanks, applied to qga branch with minor commit msg fix for patch 6.
Quoted 4 lines
Signature · 2 lines
-- 1.7.11.7