All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] libxl/xl: two more coverity related fixes
@ 2013-11-22 11:54 Roger Pau Monne
  2013-11-22 11:54 ` [PATCH 1/2] libxl: fix fd check in libxl__spawn_local_dm Roger Pau Monne
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Roger Pau Monne @ 2013-11-22 11:54 UTC (permalink / raw)
  To: xen-devel

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.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] libxl: fix fd check in libxl__spawn_local_dm
  2013-11-22 11:54 [PATCH 0/2] libxl/xl: two more coverity related fixes Roger Pau Monne
@ 2013-11-22 11:54 ` Roger Pau Monne
  2013-11-22 11:54 ` [PATCH 2/2] xl: fixes for do_daemonize Roger Pau Monne
  2013-11-26 11:14 ` [PATCH 0/2] libxl/xl: two more coverity related fixes Ian Campbell
  2 siblings, 0 replies; 5+ messages in thread
From: Roger Pau Monne @ 2013-11-22 11:54 UTC (permalink / raw)
  To: xen-devel; +Cc: Andrew Cooper, Ian Jackson, Ian Campbell, Roger Pau Monne

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.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Cc: Ian Jackson <Ian.Jackson@eu.citrix.com>
Cc: Ian Campbell <ian.campbell@citrix.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
---
 tools/libxl/libxl_dm.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c
index 469b82e..017ef70 100644
--- a/tools/libxl/libxl_dm.c
+++ b/tools/libxl/libxl_dm.c
@@ -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);
-- 
1.7.7.5 (Apple Git-26)


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] xl: fixes for do_daemonize
  2013-11-22 11:54 [PATCH 0/2] libxl/xl: two more coverity related fixes Roger Pau Monne
  2013-11-22 11:54 ` [PATCH 1/2] libxl: fix fd check in libxl__spawn_local_dm Roger Pau Monne
@ 2013-11-22 11:54 ` Roger Pau Monne
  2013-11-22 12:00   ` Andrew Cooper
  2013-11-26 11:14 ` [PATCH 0/2] libxl/xl: two more coverity related fixes Ian Campbell
  2 siblings, 1 reply; 5+ messages in thread
From: Roger Pau Monne @ 2013-11-22 11:54 UTC (permalink / raw)
  To: xen-devel; +Cc: Andrew Cooper, Ian Jackson, Ian Campbell, Roger Pau Monne

Fix usage of CHK_ERRNO in do_daemonize and also remove the usage of a
bogus for(;;).

Coverity-ID: 1130516 and 1130520
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Cc: Ian Jackson <Ian.Jackson@eu.citrix.com>
Cc: Ian Campbell <ian.campbell@citrix.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
---
 tools/libxl/xl_cmdimpl.c |   15 +++++++--------
 1 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
index 341863e..0f623a0 100644
--- a/tools/libxl/xl_cmdimpl.c
+++ b/tools/libxl/xl_cmdimpl.c
@@ -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;
-- 
1.7.7.5 (Apple Git-26)


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] xl: fixes for do_daemonize
  2013-11-22 11:54 ` [PATCH 2/2] xl: fixes for do_daemonize Roger Pau Monne
@ 2013-11-22 12:00   ` Andrew Cooper
  0 siblings, 0 replies; 5+ messages in thread
From: Andrew Cooper @ 2013-11-22 12:00 UTC (permalink / raw)
  To: Roger Pau Monne; +Cc: xen-devel, Ian Jackson, Ian Campbell

On 22/11/13 11:54, Roger Pau Monne wrote:
> Fix usage of CHK_ERRNO in do_daemonize and also remove the usage of a
> bogus for(;;).
>
> Coverity-ID: 1130516 and 1130520
> Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
> Cc: Ian Jackson <Ian.Jackson@eu.citrix.com>
> Cc: Ian Campbell <ian.campbell@citrix.com>

Looks plausibly like it will fix the identified issues.

Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>

> ---
>  tools/libxl/xl_cmdimpl.c |   15 +++++++--------
>  1 files changed, 7 insertions(+), 8 deletions(-)
>
> diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
> index 341863e..0f623a0 100644
> --- a/tools/libxl/xl_cmdimpl.c
> +++ b/tools/libxl/xl_cmdimpl.c
> @@ -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;


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/2] libxl/xl: two more coverity related fixes
  2013-11-22 11:54 [PATCH 0/2] libxl/xl: two more coverity related fixes Roger Pau Monne
  2013-11-22 11:54 ` [PATCH 1/2] libxl: fix fd check in libxl__spawn_local_dm Roger Pau Monne
  2013-11-22 11:54 ` [PATCH 2/2] xl: fixes for do_daemonize Roger Pau Monne
@ 2013-11-26 11:14 ` Ian Campbell
  2 siblings, 0 replies; 5+ messages in thread
From: Ian Campbell @ 2013-11-26 11:14 UTC (permalink / raw)
  To: Roger Pau Monne; +Cc: xen-devel

On Fri, 2013-11-22 at 12:54 +0100, Roger Pau Monne wrote:
> 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.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-11-26 11:14 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-22 11:54 [PATCH 0/2] libxl/xl: two more coverity related fixes Roger Pau Monne
2013-11-22 11:54 ` [PATCH 1/2] libxl: fix fd check in libxl__spawn_local_dm Roger Pau Monne
2013-11-22 11:54 ` [PATCH 2/2] xl: fixes for do_daemonize Roger Pau Monne
2013-11-22 12:00   ` Andrew Cooper
2013-11-26 11:14 ` [PATCH 0/2] libxl/xl: two more coverity related fixes Ian Campbell

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.