debuggers.hg

changeset 21187:e226618aa715

libxl: Expose libxl_report_exitstatus

xl would like to use libxl_report_exitstatus, so expose it in
libxl_utils.h to avoid having to write it twice. Also, give it a
"level" argument to set the loglevel of the resulting message.

Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Mon Apr 12 17:42:29 2010 +0100 (2010-04-12)
parents d005aa895b5a
children cd05b6aa8c0a
files tools/libxl/libxl_exec.c tools/libxl/libxl_internal.h tools/libxl/libxl_utils.h
line diff
     1.1 --- a/tools/libxl/libxl_exec.c	Mon Apr 12 17:41:58 2010 +0100
     1.2 +++ b/tools/libxl/libxl_exec.c	Mon Apr 12 17:42:29 2010 +0100
     1.3 @@ -57,34 +57,32 @@ void libxl_exec(int stdinfd, int stdoutf
     1.4      _exit(-1);
     1.5  }
     1.6  
     1.7 -void libxl_report_child_exitstatus(struct libxl_ctx *ctx,
     1.8 +void libxl_report_child_exitstatus(struct libxl_ctx *ctx, int level,
     1.9                                     const char *what, pid_t pid, int status)
    1.10  {
    1.11 -    /* treats all exit statuses as errors; if that's not what you want,
    1.12 -     * check status yourself first */
    1.13  
    1.14      if (WIFEXITED(status)) {
    1.15          int st = WEXITSTATUS(status);
    1.16          if (st)
    1.17 -            XL_LOG(ctx, XL_LOG_ERROR, "%s [%ld] exited"
    1.18 +            XL_LOG(ctx, level, "%s [%ld] exited"
    1.19                     " with error status %d", what, (unsigned long)pid, st);
    1.20          else
    1.21 -            XL_LOG(ctx, XL_LOG_ERROR, "%s [%ld] unexpectedly"
    1.22 +            XL_LOG(ctx, level, "%s [%ld] unexpectedly"
    1.23                     " exited status zero", what, (unsigned long)pid);
    1.24      } else if (WIFSIGNALED(status)) {
    1.25          int sig = WTERMSIG(status);
    1.26          const char *str = strsignal(sig);
    1.27          const char *coredump = WCOREDUMP(status) ? " (core dumped)" : "";
    1.28          if (str)
    1.29 -            XL_LOG(ctx, XL_LOG_ERROR, "%s [%ld] died due to"
    1.30 +            XL_LOG(ctx, level, "%s [%ld] died due to"
    1.31                     " fatal signal %s%s", what, (unsigned long)pid,
    1.32                     str, coredump);
    1.33          else
    1.34 -            XL_LOG(ctx, XL_LOG_ERROR, "%s [%ld] died due to unknown"
    1.35 +            XL_LOG(ctx, level, "%s [%ld] died due to unknown"
    1.36                     " fatal signal number %d%s", what, (unsigned long)pid,
    1.37                     sig, coredump);
    1.38      } else {
    1.39 -        XL_LOG(ctx, XL_LOG_ERROR, "%s [%ld] gave unknown"
    1.40 +        XL_LOG(ctx, level, "%s [%ld] gave unknown"
    1.41                 " wait status 0x%x", what, (unsigned long)pid, status);
    1.42      }
    1.43  }
    1.44 @@ -145,7 +143,7 @@ static void report_spawn_intermediate_st
    1.45          char *intermediate_what = libxl_sprintf(ctx,
    1.46                            "%s intermediate process (startup monitor)",
    1.47                            for_spawn->what);
    1.48 -        libxl_report_child_exitstatus(ctx, intermediate_what,
    1.49 +        libxl_report_child_exitstatus(ctx, XL_LOG_ERROR, intermediate_what,
    1.50                                        for_spawn->intermediate, status);
    1.51      }
    1.52  }
     2.1 --- a/tools/libxl/libxl_internal.h	Mon Apr 12 17:41:58 2010 +0100
     2.2 +++ b/tools/libxl/libxl_internal.h	Mon Apr 12 17:42:29 2010 +0100
     2.3 @@ -49,11 +49,6 @@
     2.4  #endif
     2.5    /* all of these macros preserve errno (saving and restoring) */
     2.6  
     2.7 -#define XL_LOG_DEBUG 3
     2.8 -#define XL_LOG_INFO 2
     2.9 -#define XL_LOG_WARNING 1
    2.10 -#define XL_LOG_ERROR 0
    2.11 -
    2.12  /* logging */
    2.13  void xl_logv(struct libxl_ctx *ctx, int errnoval, int loglevel, const char *file, int line, const char *func, char *fmt, va_list al);
    2.14  void xl_log(struct libxl_ctx *ctx, int errnoval, int loglevel, const char *file, int line, const char *func, char *fmt, ...);
     3.1 --- a/tools/libxl/libxl_utils.h	Mon Apr 12 17:41:58 2010 +0100
     3.2 +++ b/tools/libxl/libxl_utils.h	Mon Apr 12 17:42:29 2010 +0100
     3.3 @@ -48,5 +48,16 @@ pid_t libxl_fork(struct libxl_ctx *ctx);
     3.4  int libxl_pipe(struct libxl_ctx *ctx, int pipes[2]);
     3.5    /* Just like fork(2), pipe(2), but log errors. */
     3.6  
     3.7 +void libxl_report_child_exitstatus(struct libxl_ctx *ctx, int level,
     3.8 +                                   const char *what, pid_t pid, int status);
     3.9 +    /* treats all exit statuses as errors; if that's not what you want,
    3.10 +     * check status yourself first */
    3.11 +
    3.12 +/* log levels: */
    3.13 +#define XL_LOG_DEBUG 3
    3.14 +#define XL_LOG_INFO 2
    3.15 +#define XL_LOG_WARNING 1
    3.16 +#define XL_LOG_ERROR 0
    3.17 +
    3.18  #endif
    3.19