diff mbox

[v11,04/27] tools/libxl: Introduce new helper function dup_fd_helper()

Message ID 1457080891-26054-5-git-send-email-xiecl.fnst@cn.fujitsu.com (mailing list archive)
State New, archived
Headers show

Commit Message

Changlong Xie March 4, 2016, 8:41 a.m. UTC
From: Wen Congyang <wency@cn.fujitsu.com>

It is pure refactoring and no functional changes.

Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
Signed-off-by: Changlong Xie <xiecl.fnst@cn.fujitsu.com>
Acked-by: Wei Liu <wei.liu2@citrix.com>
---
 tools/libxl/libxl_save_callout.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

Comments

Ian Jackson March 4, 2016, 4:42 p.m. UTC | #1
Changlong Xie writes ("[PATCH v11 04/27] tools/libxl: Introduce new helper function dup_fd_helper()"):
> From: Wen Congyang <wency@cn.fujitsu.com>
> 
> It is pure refactoring and no functional changes.
...
>  /*----- helper execution -----*/
> +static int dup_fd_helper(libxl__gc *gc, int fd, const char *what)
> +{

This is a fine thing to do.  But the function name is less than
informative.  I think I would call it something like `dup_cloexec'.
The use of the term `helper' here is particularly confusing because it
also refers to the `save helper' of which this is part.

And
 - missing newline after the /*---*/ comment
 - this function should have a doc comment saying it cannot fail

Ian.
Changlong Xie March 17, 2016, 8:08 a.m. UTC | #2
On 03/05/2016 12:42 AM, Ian Jackson wrote:
> Changlong Xie writes ("[PATCH v11 04/27] tools/libxl: Introduce new helper function dup_fd_helper()"):
>> From: Wen Congyang <wency@cn.fujitsu.com>
>>
>> It is pure refactoring and no functional changes.
> ...
>>   /*----- helper execution -----*/
>> +static int dup_fd_helper(libxl__gc *gc, int fd, const char *what)
>> +{
>
> This is a fine thing to do.  But the function name is less than
> informative.  I think I would call it something like `dup_cloexec'.

ok

> The use of the term `helper' here is particularly confusing because it
> also refers to the `save helper' of which this is part.
>
> And
>   - missing newline after the /*---*/ comment
>   - this function should have a doc comment saying it cannot fail
>

ok, will fix in next version.

Thanks
	-Xie

> Ian.
>
>
> .
>
diff mbox

Patch

diff --git a/tools/libxl/libxl_save_callout.c b/tools/libxl/libxl_save_callout.c
index 7f1f5d4..a885504 100644
--- a/tools/libxl/libxl_save_callout.c
+++ b/tools/libxl/libxl_save_callout.c
@@ -118,6 +118,21 @@  void libxl__save_helper_init(libxl__save_helper_state *shs)
 }
 
 /*----- helper execution -----*/
+static int dup_fd_helper(libxl__gc *gc, int fd, const char *what)
+{
+    int dup_fd = fd;
+
+    if (fd <= 2) {
+        dup_fd = dup(fd);
+        if (dup_fd < 0) {
+            LOGE(ERROR,"dup %s", what);
+            exit(-1);
+        }
+    }
+    libxl_fd_set_cloexec(CTX, dup_fd, 0);
+
+    return dup_fd;
+}
 
 /*
  * Both save and restore share four parameters:
@@ -186,14 +201,7 @@  static void run_helper(libxl__egc *egc, libxl__save_helper_state *shs,
 
     pid_t pid = libxl__ev_child_fork(gc, &shs->child, helper_exited);
     if (!pid) {
-        if (stream_fd <= 2) {
-            stream_fd = dup(stream_fd);
-            if (stream_fd < 0) {
-                LOGE(ERROR,"dup migration stream fd");
-                exit(-1);
-            }
-        }
-        libxl_fd_set_cloexec(CTX, stream_fd, 0);
+        stream_fd = dup_fd_helper(gc, stream_fd, "migration stream fd");
         *stream_fd_arg = GCSPRINTF("%d", stream_fd);
 
         for (i=0; i<num_preserve_fds; i++)