Skip to contentSkip to conversation

tools/libxl: close the logfile_w and null file descriptors in libxl__spawn_qdisk_backend() error path

PATCH In review Koushik Chakravarty 3 participants 5 messages Mar 16, 2015 – Mar 20, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools/libxl: close the logfile_w and null file descriptors in libxl__spawn_qdisk_backend() error path

CC Ian Jackson <[email protected]>
CC Stefano Stabellini <[email protected]>
CC Ian Campbell <[email protected]>
CC Wei Liu <[email protected]>
---
 tools/libxl/libxl_dm.c |   10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
tools/libxl/libxl_dm.c +9 -1
index cb006df..161401c 100644
@@ -1508,7 +1508,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, null = -1, rc;
     uint32_t domid = dmss->guest_domid;
 
     /* Always use qemu-xen as device model */
@@ -1534,6 +1534,10 @@ void libxl__spawn_qdisk_backend(libxl__egc *egc, libxl__dm_spawn_state *dmss)
         goto error;
     }
     null = open("/dev/null", O_RDONLY);
+    if (null < 0) {
+       rc = ERROR_FAIL;
+       goto error;
+    }
 
     dmss->guest_config = NULL;
     /*
@@ -1568,6 +1572,10 @@ void libxl__spawn_qdisk_backend(libxl__egc *egc, libxl__dm_spawn_state *dmss)
 
 error:
     assert(rc);
+    if(logfile_w >= 0)
+       close(logfile_w);
+    if(null >= 0)
+       close(null);
     dmss->callback(egc, dmss, rc);
     return;
 }
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 34 lines · Koushik Chakravarty
CC Ian Jackson <[email protected]>
CC Stefano Stabellini <[email protected]>
CC Ian Campbell <[email protected]>
CC Wei Liu <[email protected]>
---
 tools/libxl/libxl_dm.c |   10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
tools/libxl/libxl_dm.c +5 -1
index cb006df..161401c 100644
@@ -1508,7 +1508,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, null = -1, rc;
     uint32_t domid = dmss->guest_domid;
 
     /* Always use qemu-xen as device model */
@@ -1534,6 +1534,10 @@ void libxl__spawn_qdisk_backend(libxl__egc *egc, libxl__dm_spawn_state *dmss)
         goto error;
     }
     null = open("/dev/null", O_RDONLY);
+    if (null < 0) {
+       rc = ERROR_FAIL;
+       goto error;
+    }
 
     dmss->guest_config = NULL;
     /*

tools/libxl/libxl_dm.c void libxl__spawn_qdisk_backend(libxl__egc *egc, libxl__dm_spawn_state *dmss) · line 1578

Quoted 7 lines
tools/libxl/libxl_dm.c +4 -0
@@ -1568,6 +1572,10 @@ void libxl__spawn_qdisk_backend(libxl__egc *egc, libxl__dm_spawn_state *dmss)
 
 error:
     assert(rc);
+    if(logfile_w >= 0)
+       close(logfile_w);
+    if(null >= 0)
+       close(null);

Please add space between if' and ('.

Also you can just write

       if (logfile_w >= 0) close (logfile_w);
       if (null >= 0) close (null);

Wei.

Quoted 5 lines
tools/libxl/libxl_dm.c +0 -0
     dmss->callback(egc, dmss, rc);
     return;
 }
Signature · 1 line
1.7.10.4
#2 lore raw

PATCH v2 1/1 tools/libxl: close the logfile_w and null file descriptors in libxl__spawn_qdisk_backend() error path

In reply to Koushik Chakravarty
CC Ian Jackson <[email protected]>
CC Stefano Stabellini <[email protected]>
CC Ian Campbell <[email protected]>
CC Wei Liu <[email protected]>
---
 tools/libxl/libxl_dm.c |    8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
tools/libxl/libxl_dm.c +7 -1
index cb006df..2678be2 100644
@@ -1508,7 +1508,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, null = -1, rc;
     uint32_t domid = dmss->guest_domid;
 
     /* Always use qemu-xen as device model */
@@ -1534,6 +1534,10 @@ void libxl__spawn_qdisk_backend(libxl__egc *egc, libxl__dm_spawn_state *dmss)
         goto error;
     }
     null = open("/dev/null", O_RDONLY);
+    if (null < 0) {
+       rc = ERROR_FAIL;
+       goto error;
+    }
 
     dmss->guest_config = NULL;
     /*
@@ -1568,6 +1572,8 @@ void libxl__spawn_qdisk_backend(libxl__egc *egc, libxl__dm_spawn_state *dmss)
 
 error:
     assert(rc);
+    if (logfile_w >= 0) close(logfile_w);
+    if (null >= 0) close(null);
     dmss->callback(egc, dmss, rc);
     return;
 }
Signature · 1 line
1.7.10.4
Acked-by on v2 1/1
#3 lore raw
Quoted 5 lines · Koushik Chakravarty
CC Ian Jackson <[email protected]>
CC Stefano Stabellini <[email protected]>
CC Ian Campbell <[email protected]>
CC Wei Liu <[email protected]>
Quoted 39 lines
---
 tools/libxl/libxl_dm.c |    8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
tools/libxl/libxl_dm.c +7 -1
index cb006df..2678be2 100644
@@ -1508,7 +1508,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, null = -1, rc;
     uint32_t domid = dmss->guest_domid;
 
     /* Always use qemu-xen as device model */
@@ -1534,6 +1534,10 @@ void libxl__spawn_qdisk_backend(libxl__egc *egc, libxl__dm_spawn_state *dmss)
         goto error;
     }
     null = open("/dev/null", O_RDONLY);
+    if (null < 0) {
+       rc = ERROR_FAIL;
+       goto error;
+    }
 
     dmss->guest_config = NULL;
     /*
@@ -1568,6 +1572,8 @@ void libxl__spawn_qdisk_backend(libxl__egc *egc, libxl__dm_spawn_state *dmss)
 
 error:
     assert(rc);
+    if (logfile_w >= 0) close(logfile_w);
+    if (null >= 0) close(null);
     dmss->callback(egc, dmss, rc);
     return;
 }
Signature · 1 line
1.7.10.4