debuggers.hg

changeset 20834:675443b02c53

libxenlight: remove ctx dangerously passed to children

apart from ctx->waitpid, it's potentially harmful to call into
logging.

Signed-off-by: Vincent Hanquez <vincent.hanquez@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Jan 12 07:06:12 2010 +0000 (2010-01-12)
parents da6cddd20000
children 67b5ad8ae87e
files tools/libxl/libxl.c tools/libxl/libxl_exec.c tools/libxl/libxl_internal.h
line diff
     1.1 --- a/tools/libxl/libxl.c	Tue Jan 12 07:05:22 2010 +0000
     1.2 +++ b/tools/libxl/libxl.c	Tue Jan 12 07:06:12 2010 +0000
     1.3 @@ -726,8 +726,8 @@ static char ** libxl_build_device_model_
     1.4      return (char **) flexarray_contents(dm_args);
     1.5  }
     1.6  
     1.7 -void dm_xenstore_record_pid(struct libxl_ctx *ctx, void *for_spawn,
     1.8 -                            pid_t innerchild) {
     1.9 +void dm_xenstore_record_pid(void *for_spawn, pid_t innerchild)
    1.10 +{
    1.11      struct libxl_device_model_starting *starting = for_spawn;
    1.12      char *kvs[3];
    1.13      int rc;
     2.1 --- a/tools/libxl/libxl_exec.c	Tue Jan 12 07:05:22 2010 +0000
     2.2 +++ b/tools/libxl/libxl_exec.c	Tue Jan 12 07:06:12 2010 +0000
     2.3 @@ -100,8 +100,7 @@ void libxl_report_child_exitstatus(struc
     2.4  int libxl_spawn_spawn(struct libxl_ctx *ctx,
     2.5                        libxl_device_model_starting *starting,
     2.6                        const char *what,
     2.7 -                      void (*intermediate_hook)(struct libxl_ctx *ctx,
     2.8 -                                                void *for_spawn,
     2.9 +                      void (*intermediate_hook)(void *for_spawn,
    2.10                                                  pid_t innerchild))
    2.11  {
    2.12      pid_t child, got;
    2.13 @@ -127,18 +126,19 @@ int libxl_spawn_spawn(struct libxl_ctx *
    2.14  
    2.15      /* we are now the intermediate process */
    2.16  
    2.17 -    child = libxl_fork(ctx);
    2.18 -    if (!child) return 0; /* caller runs child code */
    2.19 -    if (child < 0) exit(255);
    2.20 +    child = fork();
    2.21 +    if (child == -1)
    2.22 +        exit(255);
    2.23 +    if (!child)
    2.24 +        return 0; /* caller runs child code */
    2.25  
    2.26 -    intermediate_hook(ctx, starting, child);
    2.27 +    intermediate_hook(starting, child);
    2.28  
    2.29      if (!for_spawn) _exit(0); /* just detach then */
    2.30  
    2.31      got = call_waitpid(ctx->waitpid_instead, child, &status, 0);
    2.32      assert(got == child);
    2.33  
    2.34 -    libxl_report_child_exitstatus(ctx, what, child, status);
    2.35      _exit(WIFEXITED(status) ? WEXITSTATUS(status) :
    2.36            WIFSIGNALED(status) && WTERMSIG(status) < 127
    2.37            ? WTERMSIG(status)+128 : -1);
     3.1 --- a/tools/libxl/libxl_internal.h	Tue Jan 12 07:05:22 2010 +0000
     3.2 +++ b/tools/libxl/libxl_internal.h	Tue Jan 12 07:06:12 2010 +0000
     3.3 @@ -181,9 +181,7 @@ struct libxl_device_model_starting {
     3.4  int libxl_spawn_spawn(struct libxl_ctx *ctx,
     3.5                        libxl_device_model_starting *starting,
     3.6                        const char *what,
     3.7 -                      void (*intermediate_hook)(struct libxl_ctx *ctx,
     3.8 -                                                void *for_spawn,
     3.9 -                                                pid_t innerchild));
    3.10 +                      void (*intermediate_hook)(void *for_spawn, pid_t innerchild));
    3.11    /* Logs errors.  A copy of "what" is taken.  Return values:
    3.12     *  < 0   error, for_spawn need not be detached
    3.13     *   +1   caller is now the inner child, should probably call libxl_exec