libxl: fixes for coverity reported issues
cover libxl: fixes for coverity reported issues
Fixes for two bugs coverity found after the driver domain series went in.
PATCH 1/2 libxl: fix use of aodev->dev after free
Coverity-ID: 1130521
--- tools/libxl/libxl.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
tools/libxl/libxl.c +3 -3
@@ -3596,14 +3596,14 @@ static void device_complete(libxl__egc *egc, libxl__ao_device *aodev) {STATE_AO_GC (aodev->ao); -if (aodev->action ==LIBXL__DEVICE_ACTION_REMOVE ) -free (aodev->dev); -LOG (DEBUG ,"device %s %s %s" ,libxl__device_backend_path (gc, aodev->dev),libxl__device_action_to_string (aodev->action), aodev->rc ?"failed" :"succeed" ); +if (aodev->action ==LIBXL__DEVICE_ACTION_REMOVE ) +free (aodev->dev); +libxl__nested_ao_free (aodev->ao); }
Signature · 7 lines
1.7.7.5 (Apple Git-26) _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH 1/2] libxl: fix use of aodev->dev after free
Roger Pau Monne writes ("[PATCH 1/2] libxl: fix use of aodev->dev after free"):
Quoted 4 lines
Coverity-ID: 1130521
Signed-off-by Roger Pau Monné <[email protected]>Cc Ian Jackson <[email protected]>Cc Ian Campbell <[email protected]>
Thanks,
And added to my backport list.
Ian.
PATCH 2/2 libxl: libxl__spawn_qdisk_backend has to close opened files on error
In reply to Roger Pau MonneCoverity-ID: 1130517 and 1130518
--- tools/libxl/libxl_dm.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-)
tools/libxl/libxl_dm.c +4 -1
@@ -1393,7 +1393,7 @@ void libxl__spawn_qdisk_backend(libxl__egc *egc, libxl__dm_spawn_state *dmss) dmss->spawn.detached_cb = device_model_detached; rc =libxl__spawn_spawn (egc, &dmss->spawn);if (rc <0 ) - goto error; + goto error_close;if (!rc) {/* inner child */ setsid ();libxl__exec (gc, null, logfile_w, logfile_w, dm, args,NULL );
@@ -1401,6 +1401,9 @@ void libxl__spawn_qdisk_backend(libxl__egc *egc, libxl__dm_spawn_state *dmss)return ; +error_close: +close (null); +close (logfile_w); error:assert (rc); dmss->callback (egc, dmss, rc);
Signature · 7 lines
1.7.7.5 (Apple Git-26) _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH 2/2] libxl: libxl__spawn_qdisk_backend has to close opened files on error
Roger Pau Monne writes ("[PATCH 2/2] libxl: libxl__spawn_qdisk_backend has to close opened files on error"):
Quoted 2 lines
Coverity-ID: 1130517 and 1130518
Signed-off-by Roger Pau Monné <[email protected]>
I'm don't think that's the right fix. I think the fds are leaked in the success case too. How about this ?
Quoted 1 line
From
c2b3a5a9225398e6c2381d34ff2d6e9aa07d74faMon Sep 17 00:00:00 2001
From: Ian Jackson <[email protected]>
Date: Thu, 21 Nov 2013 18:37:16 +0000
Subject: [PATCH] libxl: libxl__spawn_qdisk_backend closes fds
This function needs to close both null and logfile_w on both error and normal exits. (The child gets its own copy during the fork, and the parent doesn't need them any more.)
Use the standard initialise-to-unallocated, always-free style. As a result the label "error" becomes "out", and only makes the callback if rc is nonzero.
Coverity-ID: 1130517 and 1130518
Cc: Roger Pau Monne <[email protected]>
Cc: Ian Campbell <[email protected]>
--- tools/libxl/libxl_dm.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)
tools/libxl/libxl_dm.c +11 -6
@@ -1343,7 +1343,7 @@ void libxl__spawn_qdisk_backend(libxl__egc *egc, libxl__dm_spawn_state *dmss)flexarray_t *dm_args;char **args;const char *dm; -int logfile_w, null, rc; +int logfile_w =-1 , null =-1 , rc;uint32_t domid = dmss->guest_domid;/* Always use qemu-xen as device model */
@@ -1393,17 +1393,22 @@ void libxl__spawn_qdisk_backend(libxl__egc *egc, libxl__dm_spawn_state *dmss) dmss->spawn.detached_cb = device_model_detached; rc =libxl__spawn_spawn (egc, &dmss->spawn);if (rc <0 ) - goto error; + goto out;if (!rc) {/* inner child */ setsid ();libxl__exec (gc, null, logfile_w, logfile_w, dm, args,NULL ); } -return ; + rc =0 ; -error: -assert (rc); - dmss->callback (egc, dmss, rc); + out: +if (logfile_w >=0 )close (logfile_w); +if (null >=0 )close (null); + +/* rc is nonzero iff we had an error; if we had no error then +* spawn succeeded and we will continue in a further callback */ +if (rc) + dmss->callback (egc, dmss, rc);return ; }
Signature · 1 line
1.7.10.4
Re: [PATCH 2/2] libxl: libxl__spawn_qdisk_backend has to close opened files on error
Ian Jackson writes ("Re: [PATCH 2/2] libxl: libxl__spawn_qdisk_backend has to close opened files on error"):
Quoted 6 lines
Roger Pau Monne writes ("[PATCH 2/2] libxl:
libxl__spawn_qdisk_backendhas to close opened files on error"):Quoted 2 lines
Coverity-ID: 1130517 and 1130518
Signed-off-by Roger Pau Monné <[email protected]>I'm don't think that's the right fix. I think the fds are leaked in the success case too. How about this ?
Maybe you'd prefer a version which at least compiles...
Ian.
From: Ian Jackson <[email protected]>
Date: Thu, 21 Nov 2013 18:37:16 +0000
Subject: [PATCH v2] libxl: libxl__spawn_qdisk_backend closes fds
This function needs to close both null and logfile_w on both error and normal exits. (The child gets its own copy during the fork, and the parent doesn't need them any more.)
Use the standard initialise-to-unallocated, always-free style. As a result the label "error" becomes "out", and only makes the callback if rc is nonzero.
Coverity-ID: 1130517 and 1130518
Cc: Roger Pau Monne <[email protected]>
Cc: Ian Campbell <[email protected]>
--- tools/libxl/libxl_dm.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)
tools/libxl/libxl_dm.c +12 -7
@@ -1343,7 +1343,7 @@ void libxl__spawn_qdisk_backend(libxl__egc *egc, libxl__dm_spawn_state *dmss)flexarray_t *dm_args;char **args;const char *dm; -int logfile_w, null, rc; +int logfile_w =-1 , null =-1 , rc;uint32_t domid = dmss->guest_domid;/* Always use qemu-xen as device model */
@@ -1366,7 +1366,7 @@ void libxl__spawn_qdisk_backend(libxl__egc *egc, libxl__dm_spawn_state *dmss) logfile_w =libxl__create_qemu_logfile (gc,GCSPRINTF ("qdisk-%u" , domid));if (logfile_w <0 ) { rc = logfile_w; - goto error; + goto out; } null =open ("/dev/null" ,O_RDONLY );
@@ -1393,17 +1393,22 @@ void libxl__spawn_qdisk_backend(libxl__egc *egc, libxl__dm_spawn_state *dmss) dmss->spawn.detached_cb = device_model_detached; rc =libxl__spawn_spawn (egc, &dmss->spawn);if (rc <0 ) - goto error; + goto out;if (!rc) {/* inner child */ setsid ();libxl__exec (gc, null, logfile_w, logfile_w, dm, args,NULL ); } -return ; + rc =0 ; -error: -assert (rc); - dmss->callback (egc, dmss, rc); + out: +if (logfile_w >=0 )close (logfile_w); +if (null >=0 )close (null); + +/* rc is nonzero iff we had an error; if we had no error then +* spawn succeeded and we will continue in a further callback */ +if (rc) + dmss->callback (egc, dmss, rc);return ; }
Signature · 1 line
1.7.10.4
Re: [PATCH 2/2] libxl: libxl__spawn_qdisk_backend has to close opened files on error
Quoted 18 lines · Ian Jackson
Ian Jackson writes ("Re: [PATCH 2/2] libxl:
libxl__spawn_qdisk_backendhas to close opened files on error"):Quoted 5 lines
Roger Pau Monne writes ("[PATCH 2/2] libxl:
libxl__spawn_qdisk_backendhas to close opened files on error"):Quoted 2 lines
Coverity-ID: 1130517 and 1130518
Signed-off-by Roger Pau Monné <[email protected]>I'm don't think that's the right fix. I think the fds are leaked in the success case too. How about this ?
Maybe you'd prefer a version which at least compiles...
Ian.
From: Ian Jackson <[email protected]>
Date: Thu, 21 Nov 2013 18:37:16 +0000
Subject: [PATCH v2] libxl:libxl__spawn_qdisk_backendcloses fdsThis function needs to close both null and
logfile_won both error and normal exits. (The child gets its own copy during the fork, and the parent doesn't need them any more.)
Quoted 8 lines
Use the standard initialise-to-unallocated, always-free style. As a result the label "error" becomes "out", and only makes the callback if rc is nonzero.
Signed-off-by Ian Jackson <[email protected]>Coverity-ID: 1130517 and 1130518
Cc: Roger Pau Monne <[email protected]>
Cc: Ian Campbell <[email protected]>
Right - this clarifies my question about cleanup on the success case.
Quoted 9 lines
--- tools/libxl/libxl_dm.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)tools/libxl/libxl_dm.c +0
-0
tools/libxl/libxl_dm.c void libxl__spawn_qdisk_backend(libxl__egc *egc, libxl__dm_spawn_state *dmss) · line 1346
Quoted 5 lines
tools/libxl/libxl_dm.c +1
-1@@ -1343,7 +1343,7 @@ void libxl__spawn_qdisk_backend(libxl__egc *egc, libxl__dm_spawn_state *dmss)flexarray_t *dm_args;char **args;const char *dm; -int logfile_w, null, rc; +int logfile_w =-1 , null =-1 , rc;
The rc logic is a little awkward. Would it be better to initialise to -1 here...
tools/libxl/libxl_dm.c void libxl__spawn_qdisk_backend(libxl__egc *egc, libxl__dm_spawn_state *dmss) · line 1368
Quoted 7 lines
tools/libxl/libxl_dm.c +0
-0uint32_t domid = dmss->guest_domid;/* Always use qemu-xen as device model */ @@ -1366,7 +1366,7 @@ void libxl__spawn_qdisk_backend(libxl__egc *egc, libxl__dm_spawn_state *dmss) logfile_w =libxl__create_qemu_logfile (gc,GCSPRINTF ("qdisk-%u" , domid));if (logfile_w <0 ) { rc = logfile_w;
... and avoid this somewhat odd assignment?
~Andrew
Quoted 33 lines
tools/libxl/libxl_dm.c +11
-6- goto error; + goto out; } null =open ("/dev/null" ,O_RDONLY );@@ -1393,17 +1393,22 @@ void libxl__spawn_qdisk_backend(libxl__egc *egc, libxl__dm_spawn_state *dmss) dmss->spawn.detached_cb = device_model_detached; rc =libxl__spawn_spawn (egc, &dmss->spawn);if (rc <0 ) - goto error; + goto out;if (!rc) {/* inner child */ setsid ();libxl__exec (gc, null, logfile_w, logfile_w, dm, args,NULL ); } -return ; + rc =0 ; -error: -assert (rc); - dmss->callback (egc, dmss, rc); + out: +if (logfile_w >=0 )close (logfile_w); +if (null >=0 )close (null); + +/* rc is nonzero iff we had an error; if we had no error then +* spawn succeeded and we will continue in a further callback */ +if (rc) + dmss->callback (egc, dmss, rc);return ; }
Re: [PATCH 2/2] libxl: libxl__spawn_qdisk_backend has to close opened files on error
Quoted 48 lines · Andrew Cooper
Quoted 18 lines · Ian Jackson
Ian Jackson writes ("Re: [PATCH 2/2] libxl:
libxl__spawn_qdisk_backendhas to close opened files on error"):Quoted 5 lines
Roger Pau Monne writes ("[PATCH 2/2] libxl:
libxl__spawn_qdisk_backendhas to close opened files on error"):Quoted 2 lines
Coverity-ID: 1130517 and 1130518
Signed-off-by Roger Pau Monné <[email protected]>I'm don't think that's the right fix. I think the fds are leaked in the success case too. How about this ?
Maybe you'd prefer a version which at least compiles...
Ian.
From: Ian Jackson <[email protected]>
Date: Thu, 21 Nov 2013 18:37:16 +0000
Subject: [PATCH v2] libxl:libxl__spawn_qdisk_backendcloses fdsThis function needs to close both null and
logfile_won both error and normal exits. (The child gets its own copy during the fork, and the parent doesn't need them any more.)Quoted 8 lines
Use the standard initialise-to-unallocated, always-free style. As a result the label "error" becomes "out", and only makes the callback if rc is nonzero.
Signed-off-by Ian Jackson <[email protected]>Coverity-ID: 1130517 and 1130518
Cc: Roger Pau Monne <[email protected]>
Cc: Ian Campbell <[email protected]>Right - this clarifies my question about cleanup on the success case.
Quoted 9 lines
--- tools/libxl/libxl_dm.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)tools/libxl/libxl_dm.c +0
-0tools/libxl/libxl_dm.c void libxl__spawn_qdisk_backend(libxl__egc *egc, libxl__dm_spawn_state *dmss) · line 1346
Quoted 5 lines
tools/libxl/libxl_dm.c +1
-1@@ -1343,7 +1343,7 @@ void libxl__spawn_qdisk_backend(libxl__egc *egc, libxl__dm_spawn_state *dmss)flexarray_t *dm_args;char **args;const char *dm; -int logfile_w, null, rc; +int logfile_w =-1 , null =-1 , rc;The rc logic is a little awkward. Would it be better to initialise to -1 here...
Quoted 2 lines
tools/libxl/libxl_dm.c +0
-0uint32_t domid = dmss->guest_domid;
Quoted 13 lines
tools/libxl/libxl_dm.c void libxl__spawn_qdisk_backend(libxl__egc *egc, libxl__dm_spawn_state *dmss) · line 1368
Quoted 5 lines
tools/libxl/libxl_dm.c +0
-0/* Always use qemu-xen as device model */ @@ -1366,7 +1366,7 @@ void libxl__spawn_qdisk_backend(libxl__egc *egc, libxl__dm_spawn_state *dmss) logfile_w =libxl__create_qemu_logfile (gc,GCSPRINTF ("qdisk-%u" , domid));if (logfile_w <0 ) { rc = logfile_w;... and avoid this somewhat odd assignment?
~Andrew
Quoted 4 lines
tools/libxl/libxl_dm.c +1
-1- goto error; + goto out; } null =open ("/dev/null" ,O_RDONLY );
And thinking about it, this open() should also have some error checking.
~Andrew
Quoted 34 lines
Quoted 19 lines
tools/libxl/libxl_dm.c +3
-5@@ -1393,17 +1393,22 @@ void libxl__spawn_qdisk_backend(libxl__egc *egc, libxl__dm_spawn_state *dmss) dmss->spawn.detached_cb = device_model_detached; rc =libxl__spawn_spawn (egc, &dmss->spawn);if (rc <0 ) - goto error; + goto out;if (!rc) {/* inner child */ setsid ();libxl__exec (gc, null, logfile_w, logfile_w, dm, args,NULL ); } -return ; + rc =0 ; -error: -assert (rc); - dmss->callback (egc, dmss, rc); + out:tools/libxl/libxl_dm.c void libxl__spawn_qdisk_backend(libxl__egc *egc, libxl__dm_spawn_state *dmss) · line 1414
Quoted 10 lines
tools/libxl/libxl_dm.c +7
-0+if (logfile_w >=0 )close (logfile_w); +if (null >=0 )close (null); + +/* rc is nonzero iff we had an error; if we had no error then +* spawn succeeded and we will continue in a further callback */ +if (rc) + dmss->callback (egc, dmss, rc);return ; }_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH 2/2] libxl: libxl__spawn_qdisk_backend has to close opened files on error
In reply to Andrew CooperQuoted 50 lines · Andrew Cooper
Quoted 18 lines · Ian Jackson
Ian Jackson writes ("Re: [PATCH 2/2] libxl:
libxl__spawn_qdisk_backendhas to close opened files on error"):Quoted 5 lines
Roger Pau Monne writes ("[PATCH 2/2] libxl:
libxl__spawn_qdisk_backendhas to close opened files on error"):Quoted 2 lines
Coverity-ID: 1130517 and 1130518
Signed-off-by Roger Pau Monné <[email protected]>I'm don't think that's the right fix. I think the fds are leaked in the success case too. How about this ?
Maybe you'd prefer a version which at least compiles...
Ian.
From: Ian Jackson <[email protected]>
Date: Thu, 21 Nov 2013 18:37:16 +0000
Subject: [PATCH v2] libxl:libxl__spawn_qdisk_backendcloses fdsThis function needs to close both null and
logfile_won both error and normal exits. (The child gets its own copy during the fork, and the parent doesn't need them any more.)Quoted 8 lines
Use the standard initialise-to-unallocated, always-free style. As a result the label "error" becomes "out", and only makes the callback if rc is nonzero.
Signed-off-by Ian Jackson <[email protected]>Coverity-ID: 1130517 and 1130518
Cc: Roger Pau Monne <[email protected]>
Cc: Ian Campbell <[email protected]>Right - this clarifies my question about cleanup on the success case.
Quoted 9 lines
--- tools/libxl/libxl_dm.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)tools/libxl/libxl_dm.c +0
-0tools/libxl/libxl_dm.c void libxl__spawn_qdisk_backend(libxl__egc *egc, libxl__dm_spawn_state *dmss) · line 1346
Quoted 5 lines
tools/libxl/libxl_dm.c +1
-1@@ -1343,7 +1343,7 @@ void libxl__spawn_qdisk_backend(libxl__egc *egc, libxl__dm_spawn_state *dmss)flexarray_t *dm_args;char **args;const char *dm; -int logfile_w, null, rc; +int logfile_w =-1 , null =-1 , rc;The rc logic is a little awkward. Would it be better to initialise to -1 here...
Quoted 2 lines
tools/libxl/libxl_dm.c +0
-0uint32_t domid = dmss->guest_domid;
Quoted 7 lines
tools/libxl/libxl_dm.c void libxl__spawn_qdisk_backend(libxl__egc *egc, libxl__dm_spawn_state *dmss) · line 1368
Quoted 5 lines
tools/libxl/libxl_dm.c +0
-0/* Always use qemu-xen as device model */ @@ -1366,7 +1366,7 @@ void libxl__spawn_qdisk_backend(libxl__egc *egc, libxl__dm_spawn_state *dmss) logfile_w =libxl__create_qemu_logfile (gc,GCSPRINTF ("qdisk-%u" , domid));if (logfile_w <0 ) { rc = logfile_w;... and avoid this somewhat odd assignment?
rc is traditionally a libxl ERROR_FOO not -1. libxl__create_qemu_logfile returns one of those or a valid fd >= 0.
Quoted 22 lines
~Andrew
Quoted 19 lines
tools/libxl/libxl_dm.c +3
-3- goto error; + goto out; } null =open ("/dev/null" ,O_RDONLY );@@ -1393,17 +1393,22 @@ void libxl__spawn_qdisk_backend(libxl__egc *egc, libxl__dm_spawn_state *dmss) dmss->spawn.detached_cb = device_model_detached; rc =libxl__spawn_spawn (egc, &dmss->spawn);if (rc <0 ) - goto error; + goto out;if (!rc) {/* inner child */ setsid ();libxl__exec (gc, null, logfile_w, logfile_w, dm, args,NULL ); } -return ; + rc =0 ;
Quoted 15 lines
Quoted 4 lines
tools/libxl/libxl_dm.c +1
-3-error: -assert (rc); - dmss->callback (egc, dmss, rc); + out:tools/libxl/libxl_dm.c void libxl__spawn_qdisk_backend(libxl__egc *egc, libxl__dm_spawn_state *dmss) · line 1414
Quoted 10 lines
tools/libxl/libxl_dm.c +7
-0+if (logfile_w >=0 )close (logfile_w); +if (null >=0 )close (null); + +/* rc is nonzero iff we had an error; if we had no error then +* spawn succeeded and we will continue in a further callback */ +if (rc) + dmss->callback (egc, dmss, rc);return ; }
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Roger Pau Monné
Acked-byRe: [PATCH 2/2] libxl: libxl__spawn_qdisk_backend has to close opened files on error
In reply to Ian JacksonQuoted 69 lines · Ian Jackson
Ian Jackson writes ("Re: [PATCH 2/2] libxl:
libxl__spawn_qdisk_backendhas to close opened files on error"):Quoted 6 lines
Roger Pau Monne writes ("[PATCH 2/2] libxl:
libxl__spawn_qdisk_backendhas to close opened files on error"):Quoted 2 lines
Coverity-ID: 1130517 and 1130518
Signed-off-by Roger Pau Monné <[email protected]>I'm don't think that's the right fix. I think the fds are leaked in the success case too. How about this ?
Maybe you'd prefer a version which at least compiles...
Ian.
From: Ian Jackson <[email protected]>
Date: Thu, 21 Nov 2013 18:37:16 +0000
Subject: [PATCH v2] libxl:libxl__spawn_qdisk_backendcloses fdsThis function needs to close both null and
logfile_won both error and normal exits. (The child gets its own copy during the fork, and the parent doesn't need them any more.)Use the standard initialise-to-unallocated, always-free style. As a result the label "error" becomes "out", and only makes the callback if rc is nonzero.
Signed-off-by Ian Jackson <[email protected]>Coverity-ID: 1130517 and 1130518
Cc: Roger Pau Monne <[email protected]>
Cc: Ian Campbell <[email protected]>--- tools/libxl/libxl_dm.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)tools/libxl/libxl_dm.c +4
-5@@ -1343,7 +1343,7 @@ void libxl__spawn_qdisk_backend(libxl__egc *egc, libxl__dm_spawn_state *dmss)flexarray_t *dm_args;char **args;const char *dm; -int logfile_w, null, rc; +int logfile_w =-1 , null =-1 , rc;uint32_t domid = dmss->guest_domid;/* Always use qemu-xen as device model */ @@ -1366,7 +1366,7 @@ void libxl__spawn_qdisk_backend(libxl__egc *egc, libxl__dm_spawn_state *dmss) logfile_w =libxl__create_qemu_logfile (gc,GCSPRINTF ("qdisk-%u" , domid));if (logfile_w <0 ) { rc = logfile_w; - goto error; + goto out; } null =open ("/dev/null" ,O_RDONLY );@@ -1393,17 +1393,22 @@ void libxl__spawn_qdisk_backend(libxl__egc *egc, libxl__dm_spawn_state *dmss) dmss->spawn.detached_cb = device_model_detached; rc =libxl__spawn_spawn (egc, &dmss->spawn);if (rc <0 ) - goto error; + goto out;if (!rc) {/* inner child */ setsid ();libxl__exec (gc, null, logfile_w, logfile_w, dm, args,NULL ); } -return ; + rc =0 ; -error:
tools/libxl/libxl_dm.c void libxl__spawn_qdisk_backend(libxl__egc *egc, libxl__dm_spawn_state *dmss) · line 1411
Quoted 10 lines
tools/libxl/libxl_dm.c +8
-2-assert (rc); - dmss->callback (egc, dmss, rc); + out: +if (logfile_w >=0 )close (logfile_w); +if (null >=0 )close (null); + +/* rc is nonzero iff we had an error; if we had no error then +* spawn succeeded and we will continue in a further callback */ +if (rc) + dmss->callback (egc, dmss, rc);
I didn't catch that when modifying the original patch to be more similar to libxl__spawn_local_dm, but IMHO you could use device_model_spawn_outcome here which will print a nice error message about the device model is unable to start. Apart from this (that can be done in a separate patch):
Re: [PATCH 2/2] libxl: libxl__spawn_qdisk_backend has to close opened files on error
Quoted 87 lines · Roger Pau Monné
Quoted 69 lines · Ian Jackson
Ian Jackson writes ("Re: [PATCH 2/2] libxl:
libxl__spawn_qdisk_backendhas to close opened files on error"):Quoted 6 lines
Roger Pau Monne writes ("[PATCH 2/2] libxl:
libxl__spawn_qdisk_backendhas to close opened files on error"):Quoted 2 lines
Coverity-ID: 1130517 and 1130518
Signed-off-by Roger Pau Monné <[email protected]>I'm don't think that's the right fix. I think the fds are leaked in the success case too. How about this ?
Maybe you'd prefer a version which at least compiles...
Ian.
From: Ian Jackson <[email protected]>
Date: Thu, 21 Nov 2013 18:37:16 +0000
Subject: [PATCH v2] libxl:libxl__spawn_qdisk_backendcloses fdsThis function needs to close both null and
logfile_won both error and normal exits. (The child gets its own copy during the fork, and the parent doesn't need them any more.)Use the standard initialise-to-unallocated, always-free style. As a result the label "error" becomes "out", and only makes the callback if rc is nonzero.
Signed-off-by Ian Jackson <[email protected]>Coverity-ID: 1130517 and 1130518
Cc: Roger Pau Monne <[email protected]>
Cc: Ian Campbell <[email protected]>--- tools/libxl/libxl_dm.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)tools/libxl/libxl_dm.c +4
-5@@ -1343,7 +1343,7 @@ void libxl__spawn_qdisk_backend(libxl__egc *egc, libxl__dm_spawn_state *dmss)flexarray_t *dm_args;char **args;const char *dm; -int logfile_w, null, rc; +int logfile_w =-1 , null =-1 , rc;uint32_t domid = dmss->guest_domid;/* Always use qemu-xen as device model */ @@ -1366,7 +1366,7 @@ void libxl__spawn_qdisk_backend(libxl__egc *egc, libxl__dm_spawn_state *dmss) logfile_w =libxl__create_qemu_logfile (gc,GCSPRINTF ("qdisk-%u" , domid));if (logfile_w <0 ) { rc = logfile_w; - goto error; + goto out; } null =open ("/dev/null" ,O_RDONLY );@@ -1393,17 +1393,22 @@ void libxl__spawn_qdisk_backend(libxl__egc *egc, libxl__dm_spawn_state *dmss) dmss->spawn.detached_cb = device_model_detached; rc =libxl__spawn_spawn (egc, &dmss->spawn);if (rc <0 ) - goto error; + goto out;if (!rc) {/* inner child */ setsid ();libxl__exec (gc, null, logfile_w, logfile_w, dm, args,NULL ); } -return ; + rc =0 ; -error:tools/libxl/libxl_dm.c void libxl__spawn_qdisk_backend(libxl__egc *egc, libxl__dm_spawn_state *dmss) · line 1411
Quoted 10 lines
tools/libxl/libxl_dm.c +8
-2-assert (rc); - dmss->callback (egc, dmss, rc); + out: +if (logfile_w >=0 )close (logfile_w); +if (null >=0 )close (null); + +/* rc is nonzero iff we had an error; if we had no error then +* spawn succeeded and we will continue in a further callback */ +if (rc) + dmss->callback (egc, dmss, rc);I didn't catch that when modifying the original patch to be more similar to
libxl__spawn_local_dm, but IMHO you could usedevice_model_spawn_outcomehere which will print a nice error message about the device model is unable to start. Apart from this (that can be done in a separate patch):
Quoted 1 line
Acked-by Roger Pau Monné <[email protected]>
The version of the patch at http://bugs.xenproject.org/xen/mid/%
[email protected]%3E/raw (which should be reasonably unmangled) has gotten quoted printable'd somewhere.
Would also be good to add the error handling on opening of null as well. Currently on failure there libxl__exec will translate the -1 into STDxxx_FILENO.
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 2 lines · Roger Pau Monne
Fixes for two bugs coverity found after the driver domain series went in.
Both Reviewed-by: Andrew Cooper <[email protected]> as I did the initial coverity triage.
Roger: Are you going to do the daemonise issues or shall I?
~Andrew
Quoted 4 lines
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel