From: Vincent Hanquez Subject: [PATCH 6/6] remove ctx dangerously passed to children. Date: Mon, 11 Jan 2010 21:48:26 +0000 Message-ID: <1263246506-5488-7-git-send-email-vincent.hanquez@eu.citrix.com> References: <1263246506-5488-1-git-send-email-vincent.hanquez@eu.citrix.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------1.6.6" Return-path: In-Reply-To: <1263246506-5488-1-git-send-email-vincent.hanquez@eu.citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com Cc: Vincent Hanquez List-Id: xen-devel@lists.xenproject.org --------------1.6.6 Content-Type: text/plain; charset="UTF-8"; format=fixed Content-Transfer-Encoding: quoted-printable apart from ctx->waitpid, it's potentially harmful to call into logging. Signed-off-by: Vincent Hanquez --- tools/libxl/libxl.c | 4 ++-- tools/libxl/libxl_exec.c | 14 +++++++------- tools/libxl/libxl_internal.h | 4 +--- 3 files changed, 10 insertions(+), 12 deletions(-) --------------1.6.6 Content-Type: text/x-patch; name="0006-remove-ctx-dangerously-passed-to-children.patch" Content-Disposition: attachment; filename="0006-remove-ctx-dangerously-passed-to-children.patch" Content-Transfer-Encoding: quoted-printable diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c index 36e72cf..df3ddc0 100644 --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -726,8 +726,8 @@ static char ** libxl_build_device_model_args(struct l= ibxl_ctx *ctx, return (char **) flexarray_contents(dm_args); } =20 -void dm_xenstore_record_pid(struct libxl_ctx *ctx, void *for_spawn, - pid_t innerchild) { +void dm_xenstore_record_pid(void *for_spawn, pid_t innerchild) +{ struct libxl_device_model_starting *starting =3D for_spawn; char *kvs[3]; int rc; diff --git a/tools/libxl/libxl_exec.c b/tools/libxl/libxl_exec.c index 011ed84..e8cc74c 100644 --- a/tools/libxl/libxl_exec.c +++ b/tools/libxl/libxl_exec.c @@ -100,8 +100,7 @@ void libxl_report_child_exitstatus(struct libxl_ctx *= ctx, int libxl_spawn_spawn(struct libxl_ctx *ctx, libxl_device_model_starting *starting, const char *what, - void (*intermediate_hook)(struct libxl_ctx *ctx, - void *for_spawn, + void (*intermediate_hook)(void *for_spawn, pid_t innerchild)) { pid_t child, got; @@ -127,18 +126,19 @@ int libxl_spawn_spawn(struct libxl_ctx *ctx, =20 /* we are now the intermediate process */ =20 - child =3D libxl_fork(ctx); - if (!child) return 0; /* caller runs child code */ - if (child < 0) exit(255); + child =3D fork(); + if (child =3D=3D -1) + exit(255); + if (!child) + return 0; /* caller runs child code */ =20 - intermediate_hook(ctx, starting, child); + intermediate_hook(starting, child); =20 if (!for_spawn) _exit(0); /* just detach then */ =20 got =3D call_waitpid(ctx->waitpid_instead, child, &status, 0); assert(got =3D=3D child); =20 - libxl_report_child_exitstatus(ctx, what, child, status); _exit(WIFEXITED(status) ? WEXITSTATUS(status) : WIFSIGNALED(status) && WTERMSIG(status) < 127 ? WTERMSIG(status)+128 : -1); diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 14952ca..7664e59 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -181,9 +181,7 @@ struct libxl_device_model_starting { int libxl_spawn_spawn(struct libxl_ctx *ctx, libxl_device_model_starting *starting, const char *what, - void (*intermediate_hook)(struct libxl_ctx *ctx, - void *for_spawn, - pid_t innerchild)); + void (*intermediate_hook)(void *for_spawn, pid_t i= nnerchild)); /* Logs errors. A copy of "what" is taken. Return values: * < 0 error, for_spawn need not be detached * +1 caller is now the inner child, should probably call libxl_ex= ec --------------1.6.6 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --------------1.6.6--