%attr(-,root,root) %{_prefix}/lib/sysctl.d/70-crash-manager.conf
%attr(0750,crash_worker,crash_worker) %{_bindir}/crash-manager
%attr(0750,crash_worker,crash_worker) %{_bindir}/dump_systemstate
+%{_bindir}/crash-json2info
%{_sysconfdir}/dump_systemstate.conf.d/files/*.conf*
%{_sysconfdir}/dump_systemstate.conf.d/programs/*.conf*
%{_libexecdir}/crash-stack
--- /dev/null
+cmake_minimum_required(VERSION 2.8.11)
+
+set(CRASH_JSON_TO_INFO_BIN "crash-json2info")
+
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src)
+set(CRASH_JSON_TO_INFO_SRCS crash-json2info.c ${CMAKE_SOURCE_DIR}/src/crash-stack/report_info.c)
+
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -fPIE")
+set(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
+
+# Binary
+add_executable(${CRASH_JSON_TO_INFO_BIN} ${CRASH_JSON_TO_INFO_SRCS})
+
+include(FindPkgConfig)
+pkg_check_modules(JSON REQUIRED json-c)
+pkg_check_modules(DLOG REQUIRED dlog)
+set_property(TARGET ${CRASH_JSON_TO_INFO_BIN} APPEND_STRING PROPERTY COMPILE_FLAGS "${JSON_CFLAGS} ${DLOG_CFLAGS}")
+
+# Linking
+target_link_libraries(${CRASH_JSON_TO_INFO_BIN} ${JSON_LIBRARIES} ${DLOG_LIBRARIES} stdc++)
+
+# Installing
+install(TARGETS ${CRASH_JSON_TO_INFO_BIN} DESTINATION bin)
--- /dev/null
+#include <assert.h>
+#include <json-c/json.h>
+#include <getopt.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include "crash-stack/report_info.h"
+
+#define OPT_OUTPUT_FILE 1
+#define OPT_HELP 0
+
+const struct option opts[] = {
+ { "help", no_argument, 0, OPT_HELP },
+ { "output", required_argument, 0, OPT_OUTPUT_FILE },
+ { 0, 0, 0, 0 }
+};
+
+static void help(const char *program)
+{
+ assert(program);
+
+ printf("Usage:\n"
+ "\t%s [-o|--output <output info>] <input info json>\n", program);
+}
+
+static long file_size(FILE *fp)
+{
+ assert(fp);
+
+ struct stat stat;
+ int fd = fileno(fp);
+ if (fd == -1 || fstat(fd, &stat) == -1) {
+ printf("Get input file size error: %m\n");
+ return -1;
+ }
+
+ return stat.st_size;
+}
+
+static json_object *parse_json(FILE *fp)
+{
+ assert(fp);
+
+ json_object *jobj = NULL;
+ char *buff = NULL;
+
+ long size = file_size(fp);
+ if (size == -1)
+ goto exit;
+
+ buff = malloc(size);
+ if (fread(buff, size, 1, fp) != 1) {
+ printf("Cannot read the file: %d\n", ferror(fp));
+ goto exit;
+ }
+
+ jobj = json_tokener_parse(buff);
+ if (jobj == NULL)
+ printf("JSON parsing error\n");
+
+exit:
+ free(buff);
+ return jobj;
+}
+
+static void save_report_info(json_object *jobj, FILE *fp)
+{
+ print_report_info(jobj, fp);
+}
+
+int main(int argc, char *argv[])
+{
+ int res = EXIT_FAILURE;
+ FILE *fp_input = NULL, *fp_output = stdout;
+
+ int c;
+ while ((c = getopt_long(argc, argv, "ho:", opts, NULL)) != -1) {
+ switch(c) {
+ case 'o':
+ case OPT_OUTPUT_FILE:
+ fp_output = fopen(optarg, "w");
+ break;
+ case 'h':
+ case OPT_HELP:
+ res = EXIT_SUCCESS;
+ help(argv[0]);
+ goto exit;
+ default:
+ help(argv[0]);
+ goto exit;
+ }
+ }
+
+ if (optind < argc) {
+ fp_input = fopen(argv[optind], "r");
+ if (fp_input == NULL) {
+ printf("Cannot open file for reading: %s", argv[optind]);
+ goto exit;
+ }
+ }
+
+ if (fp_input == NULL) {
+ printf("No input file specified\n");
+ goto exit;
+ }
+
+ json_object *jobj = parse_json(fp_input);
+ if (jobj == NULL)
+ goto exit;
+
+ save_report_info(jobj, fp_output);
+ res = EXIT_SUCCESS;
+exit:
+ if (fp_input != NULL)
+ fclose(fp_input);
+ if (fp_output != NULL)
+ fclose(fp_output);
+ return res;
+}