From e13ba3b5ca0ad7c830a678ae74f72c71ab2fcbb8 Mon Sep 17 00:00:00 2001 From: jingrui Date: Tue, 18 Feb 2020 21:27:31 +0800 Subject: [PATCH] isulad: optimize shim or runtime error message Signed-off-by: jingrui --- src/runtime/isula/isula_rt_ops.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/runtime/isula/isula_rt_ops.c b/src/runtime/isula/isula_rt_ops.c index c5caf35..25e4e53 100644 --- a/src/runtime/isula/isula_rt_ops.c +++ b/src/runtime/isula/isula_rt_ops.c @@ -123,20 +123,29 @@ static char *get_err_message(const char *workdir, const char *file) static void show_shim_runtime_errlog(const char *workdir) { - char *msg = NULL; + char buf[BUFSIZ] = {0}; + char *log1 = NULL; + char *log2 = NULL; - msg = get_err_message(workdir, "shim-log.json"); - if (msg != NULL) { - ERROR("shim-log error %s", msg); - isulad_set_error_message("shim-log error %s", msg); - free(msg); + log1 = get_err_message(workdir, "shim-log.json"); + if (log1 != NULL) { + ERROR("shim-log error %s", log1); + } else { + log1 = util_strdup_s("NULL"); } - msg = get_err_message(workdir, "log.json"); - if (msg != NULL) { - ERROR("runtime-log error %s", msg); - isulad_set_error_message("runtime-log error %s", msg); - free(msg); + + log2 = get_err_message(workdir, "log.json"); + if (log2 != NULL) { + ERROR("runtime-log error %s", log2); + } else { + log2 = util_strdup_s("NULL"); } + + (void)snprintf(buf, sizeof(buf), "shim-log error: %s\nruntime-log error: %s\n", log1, log2); + isulad_set_error_message(buf); + + UTIL_FREE_AND_SET_NULL(log1); + UTIL_FREE_AND_SET_NULL(log2); } bool rt_isula_detect(const char *runtime) -- GitLab