Mailing List Archive

[xen-unstable] libxl: Expose libxl_report_exitstatus
# HG changeset patch
# User Keir Fraser <keir.fraser@citrix.com>
# Date 1271090549 -3600
# Node ID e226618aa7156ddf500960a2e8be44220466a981
# Parent d005aa895b5a051e778fc57d20107e617a8c0b41
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>
---
tools/libxl/libxl_exec.c | 16 +++++++---------
tools/libxl/libxl_internal.h | 5 -----
tools/libxl/libxl_utils.h | 11 +++++++++++
3 files changed, 18 insertions(+), 14 deletions(-)

diff -r d005aa895b5a -r e226618aa715 tools/libxl/libxl_exec.c
--- a/tools/libxl/libxl_exec.c Mon Apr 12 17:41:58 2010 +0100
+++ b/tools/libxl/libxl_exec.c Mon Apr 12 17:42:29 2010 +0100
@@ -57,34 +57,32 @@ void libxl_exec(int stdinfd, int stdoutf
_exit(-1);
}

-void libxl_report_child_exitstatus(struct libxl_ctx *ctx,
+void libxl_report_child_exitstatus(struct libxl_ctx *ctx, int level,
const char *what, pid_t pid, int status)
{
- /* treats all exit statuses as errors; if that's not what you want,
- * check status yourself first */

if (WIFEXITED(status)) {
int st = WEXITSTATUS(status);
if (st)
- XL_LOG(ctx, XL_LOG_ERROR, "%s [%ld] exited"
+ XL_LOG(ctx, level, "%s [%ld] exited"
" with error status %d", what, (unsigned long)pid, st);
else
- XL_LOG(ctx, XL_LOG_ERROR, "%s [%ld] unexpectedly"
+ XL_LOG(ctx, level, "%s [%ld] unexpectedly"
" exited status zero", what, (unsigned long)pid);
} else if (WIFSIGNALED(status)) {
int sig = WTERMSIG(status);
const char *str = strsignal(sig);
const char *coredump = WCOREDUMP(status) ? " (core dumped)" : "";
if (str)
- XL_LOG(ctx, XL_LOG_ERROR, "%s [%ld] died due to"
+ XL_LOG(ctx, level, "%s [%ld] died due to"
" fatal signal %s%s", what, (unsigned long)pid,
str, coredump);
else
- XL_LOG(ctx, XL_LOG_ERROR, "%s [%ld] died due to unknown"
+ XL_LOG(ctx, level, "%s [%ld] died due to unknown"
" fatal signal number %d%s", what, (unsigned long)pid,
sig, coredump);
} else {
- XL_LOG(ctx, XL_LOG_ERROR, "%s [%ld] gave unknown"
+ XL_LOG(ctx, level, "%s [%ld] gave unknown"
" wait status 0x%x", what, (unsigned long)pid, status);
}
}
@@ -145,7 +143,7 @@ static void report_spawn_intermediate_st
char *intermediate_what = libxl_sprintf(ctx,
"%s intermediate process (startup monitor)",
for_spawn->what);
- libxl_report_child_exitstatus(ctx, intermediate_what,
+ libxl_report_child_exitstatus(ctx, XL_LOG_ERROR, intermediate_what,
for_spawn->intermediate, status);
}
}
diff -r d005aa895b5a -r e226618aa715 tools/libxl/libxl_internal.h
--- a/tools/libxl/libxl_internal.h Mon Apr 12 17:41:58 2010 +0100
+++ b/tools/libxl/libxl_internal.h Mon Apr 12 17:42:29 2010 +0100
@@ -48,11 +48,6 @@
#define XL_LOG_ERRNOVAL(ctx, loglevel, errnoval, _f, _a...)
#endif
/* all of these macros preserve errno (saving and restoring) */
-
-#define XL_LOG_DEBUG 3
-#define XL_LOG_INFO 2
-#define XL_LOG_WARNING 1
-#define XL_LOG_ERROR 0

/* logging */
void xl_logv(struct libxl_ctx *ctx, int errnoval, int loglevel, const char *file, int line, const char *func, char *fmt, va_list al);
diff -r d005aa895b5a -r e226618aa715 tools/libxl/libxl_utils.h
--- a/tools/libxl/libxl_utils.h Mon Apr 12 17:41:58 2010 +0100
+++ b/tools/libxl/libxl_utils.h Mon Apr 12 17:42:29 2010 +0100
@@ -48,5 +48,16 @@ int libxl_pipe(struct libxl_ctx *ctx, in
int libxl_pipe(struct libxl_ctx *ctx, int pipes[2]);
/* Just like fork(2), pipe(2), but log errors. */

+void libxl_report_child_exitstatus(struct libxl_ctx *ctx, int level,
+ const char *what, pid_t pid, int status);
+ /* treats all exit statuses as errors; if that's not what you want,
+ * check status yourself first */
+
+/* log levels: */
+#define XL_LOG_DEBUG 3
+#define XL_LOG_INFO 2
+#define XL_LOG_WARNING 1
+#define XL_LOG_ERROR 0
+
#endif


_______________________________________________
Xen-changelog mailing list
Xen-changelog@lists.xensource.com
http://lists.xensource.com/xen-changelog