libxl/xl: two more coverity related fixes
cover libxl/xl: two more coverity related fixes
The first patch is a leftover from the switch to libxl__create_qemu_logfile, and while there it also handles possible errors when opening /dev/null.
The second one is a fix for the issues present in do_daemonize.
Thanks, Roger.
PATCH 1/2 libxl: fix fd check in libxl__spawn_local_dm
Checking the logfile_w fd for -1 on failure is no longer true, because libxl__create_qemu_logfile will now return ERROR_FAIL on failure which is -3.
While there also add an error check for opening /dev/null.
--- tools/libxl/libxl_dm.c | 9 +++++++-- 1 files changed, 7 insertions(+), 2 deletions(-)
tools/libxl/libxl_dm.c +7 -2
@@ -1228,6 +1228,11 @@ void libxl__spawn_local_dm(libxl__egc *egc, libxl__dm_spawn_state *dmss) goto out; } null =open ("/dev/null" ,O_RDONLY ); +if (null <0 ) { +LOGE (ERROR ,"unable to open /dev/null" ); + rc =ERROR_FAIL ; + goto out_close; + }const char *dom_path =libxl__xs_get_dompath (gc, domid); spawn->pidpath =GCSPRINTF ("%s/%s" , dom_path,"image/device-model-pid" );
@@ -1275,8 +1280,8 @@ retry_transaction: rc =0 ; out_close: -if (null !=-1 )close (null); -if (logfile_w !=-1 )close (logfile_w); +if (null >=0 )close (null); +if (logfile_w >=0 )close (logfile_w); out:if (rc)device_model_spawn_outcome (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
PATCH 2/2 xl: fixes for do_daemonize
In reply to Roger Pau MonneFix usage of CHK_ERRNO in do_daemonize and also remove the usage of a bogus for(;;).
Coverity-ID: 1130516 and 1130520
--- tools/libxl/xl_cmdimpl.c | 15 +++++++-------- 1 files changed, 7 insertions(+), 8 deletions(-)
tools/libxl/xl_cmdimpl.c +7 -8
@@ -411,14 +411,14 @@ static int do_daemonize(char *name) child1 =xl_fork (child_waitdaemon);if (child1) { -for (;;) { - got_child =xl_waitpid (child_waitdaemon, &status,0 ); -if (got_child == child1)break ; + got_child =xl_waitpid (child_waitdaemon, &status,0 ); +if (got_child != child1) {assert (got_child ==-1 ); -perror ("failed to wait for daemonizing child" ); +LOG ("failed to wait for daemonizing child: %s" ,strerror (errno)); ret =ERROR_FAIL ; goto out; } +if (status) {libxl_report_child_exitstatus (ctx,XTL_ERROR ,"daemonizing child" , child1, status);
@@ -437,16 +437,15 @@ static int do_daemonize(char *name)exit (-1 ); } -CHK_ERRNO (( logfile =open (fullname,O_WRONLY |O_CREAT |O_APPEND , -0644 ) )<0 ); +CHK_ERRNO (logfile =open (fullname,O_WRONLY |O_CREAT |O_APPEND ,0644 ));free (fullname); -CHK_ERRNO (( nullfd =open ("/dev/null" ,O_RDONLY ) )<0 ); +CHK_ERRNO (nullfd =open ("/dev/null" ,O_RDONLY ));dup2 (nullfd,0 );dup2 (logfile,1 );dup2 (logfile,2 ); -CHK_ERRNO (daemon (0 ,1 ) <0 ); +CHK_ERRNO (daemon (0 ,1 )); out:return ret;
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] xl: fixes for do_daemonize
Quoted 7 lines · Roger Pau Monne
Fix usage of
CHK_ERRNOindo_daemonizeand also remove the usage of a bogus for(;;).Coverity-ID: 1130516 and 1130520
Signed-off-by Roger Pau Monné <[email protected]>Cc Ian Jackson <[email protected]>Cc Ian Campbell <[email protected]>
Looks plausibly like it will fix the identified issues.
Quoted 37 lines
--- tools/libxl/xl_cmdimpl.c | 15 +++++++-------- 1 files changed, 7 insertions(+), 8 deletions(-)tools/libxl/xl_cmdimpl.c +5
-7@@ -411,14 +411,14 @@ static int do_daemonize(char *name) child1 =xl_fork (child_waitdaemon);if (child1) { -for (;;) { - got_child =xl_waitpid (child_waitdaemon, &status,0 ); -if (got_child == child1)break ; + got_child =xl_waitpid (child_waitdaemon, &status,0 ); +if (got_child != child1) {assert (got_child ==-1 ); -perror ("failed to wait for daemonizing child" ); +LOG ("failed to wait for daemonizing child: %s" ,strerror (errno)); ret =ERROR_FAIL ; goto out; } +if (status) {libxl_report_child_exitstatus (ctx,XTL_ERROR ,"daemonizing child" , child1, status);@@ -437,16 +437,15 @@ static int do_daemonize(char *name)exit (-1 ); } -CHK_ERRNO (( logfile =open (fullname,O_WRONLY |O_CREAT |O_APPEND , -0644 ) )<0 ); +CHK_ERRNO (logfile =open (fullname,O_WRONLY |O_CREAT |O_APPEND ,0644 ));free (fullname); -CHK_ERRNO (( nullfd =open ("/dev/null" ,O_RDONLY ) )<0 );
tools/libxl/xl_cmdimpl.c static int do_daemonize(char *name) · line 451
Quoted 10 lines
tools/libxl/xl_cmdimpl.c +2
-1+CHK_ERRNO (nullfd =open ("/dev/null" ,O_RDONLY ));dup2 (nullfd,0 );dup2 (logfile,1 );dup2 (logfile,2 ); -CHK_ERRNO (daemon (0 ,1 ) <0 ); +CHK_ERRNO (daemon (0 ,1 )); out:return ret;
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 5 lines · Roger Pau Monne
The first patch is a leftover from the switch to
libxl__create_qemu_logfile, and while there it also handles possible errors when opening/dev/null.The second one is a fix for the issues present in
do_daemonize.
BOth acked + applied. thanks.