Source1001: crash-worker.manifest
BuildRequires: pkgconfig(dlog)
BuildRequires: pkgconfig(libtzplatform-config)
+BuildRequires: pkgconfig(capi-system-info)
BuildRequires: cmake
%if "%{?sys_assert}" == "on"
BuildRequires: pkgconfig(libunwind)
%define crash_path %{TZ_SYS_CRASH}
%define crash_temp %{crash_root_path}/temp
+#Path for log_dump module
+%define crash_all_log %{TZ_SYS_ALLLOGS}
+%define crash_dump_gen %{TZ_SYS_DUMPGEN}
+
%define upgrade_script_path %{TZ_SYS_RO_SHARE}/upgrade/scripts
%build
mkdir -p %{buildroot}%{crash_path}
mkdir -p %{buildroot}%{crash_temp}
-
+# log_dump dir
+mkdir -p %{buildroot}%{crash_all_log}
+mkdir -p %{buildroot}%{crash_dump_gen}
+cp dump_scripts/* %{buildroot}%{crash_dump_gen}
%if "%{?sys_assert}" == "on"
%dir %{crash_root_path}
%dir %{crash_path}
%dir %{crash_temp}
+%dir %{crash_all_log}
+%{crash_dump_gen}/*
%attr(0755,system,system) %{_bindir}/dump_systemstate
%attr(0755,system,system) %{_bindir}/crash-manager.sh
+%attr(0755,system,system) %{_bindir}/log_dump
%{_prefix}/lib/sysctl.d/99-crash-manager.conf
%if "%{?sys_assert}" == "on"
--- /dev/null
+/* log_dump: dump current system states
+ *
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <getopt.h>
+#include <limits.h>
+#include <time.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <dlog.h>
+#include <system_info.h>
+#include <tzplatform_config.h>
+#include "shared/util.h"
+
+#undef LOG_TAG
+#define LOG_TAG "LOG_DUMP"
+#define LOG_DUMP_ROOT tzplatform_getenv(TZ_SYS_ALLLOGS)
+#define LOG_DUMP_DIR tzplatform_mkpath(TZ_SYS_ALLLOGS, "dump")
+#define DUMP_SCRIPTS_DIR tzplatform_getenv(TZ_SYS_DUMPGEN)
+#define SYSTEM_INFO_KEY_BUILD_STRING "http://tizen.org/system/build.string"
+
+enum {
+ OPT_NORMAL,
+ OPT_SHORT,
+};
+
+static const struct option opts[] = {
+ { "normal", no_argument, 0, OPT_NORMAL },
+ { "short", no_argument, 0, OPT_SHORT },
+ { 0, 0, 0, 0 }
+};
+
+static inline void usage(void)
+{
+ printf("Usage: log_dump [OPTION]\n");
+ printf("Dump options:\n");
+ printf(" %-10s %s (%s)\n", "--normal",
+ "dump all logs", DUMP_SCRIPTS_DIR);
+ printf(" %-10s %s\n", "--short",
+ "dump systemstate only");
+}
+
+static int dump_scripts(const char *path)
+{
+ struct dirent **dir_list = NULL;
+ char command[PATH_MAX];
+ int script_num, i;
+
+ script_num = scandir(path, &dir_list, NULL, NULL);
+ if (script_num < 0) {
+ LOGE("Failed to scandir");
+ return -1;
+ }
+
+ for (i = 0; i < script_num; i++) {
+ if (dir_list[i]->d_type != DT_REG)
+ continue;
+
+ snprintf(command, sizeof(command), "%s/%s %s",
+ path, dir_list[i]->d_name,
+ LOG_DUMP_DIR);
+ LOGD("%s", command);
+ system_command(command);
+ }
+
+ for (i = 0; i < script_num; i++)
+ free(dir_list[i]);
+ free(dir_list);
+
+ return 0;
+}
+
+int main(int argc, char *argv[])
+{
+ int c, ret;
+ int opt_normal, opt_short;
+ char *version_str = NULL;
+ char timestr[80];
+ char command[PATH_MAX];
+ char dump_filename[NAME_MAX];
+ time_t cur_time;
+ struct tm loc_tm;
+
+ if (argc < 2) {
+ usage();
+ exit(EXIT_SUCCESS);
+ }
+
+ opt_normal = opt_short = 0;
+ while ((c = getopt_long_only(argc, argv, "", opts, NULL)) != -1) {
+ switch (c) {
+ case OPT_NORMAL:
+ opt_normal = 1;
+ break;
+ case OPT_SHORT:
+ opt_short = 1;
+ break;
+ default:
+ usage();
+ exit(EXIT_SUCCESS);
+ break;
+ }
+ }
+
+ if (opt_normal & opt_short) {
+ usage();
+ exit(EXIT_SUCCESS);
+ }
+
+ /* Make debug directory */
+ ret = snprintf(command, sizeof(command),
+ "/usr/bin/mkdir -p %s", LOG_DUMP_DIR);
+ if (ret < 0) {
+ LOGE("Failed to mkdir");
+ exit(EXIT_FAILURE);
+ }
+ system_command(command);
+
+ /* Get timestamp */
+ cur_time = time(NULL);
+ localtime_r(&cur_time, &loc_tm);
+ strftime(timestr, sizeof(timestr), "%Y%m%d%H%M%S", &loc_tm);
+
+ /* Get version */
+ ret = system_info_get_platform_string(SYSTEM_INFO_KEY_BUILD_STRING,
+ &version_str);
+ if (ret != SYSTEM_INFO_ERROR_NONE) {
+ LOGE("Failed to system_info_get_platform_string");
+ version_str = NULL;
+ }
+
+ /* Dump system states */
+ ret = snprintf(command, sizeof(command),
+ "/usr/bin/dump_systemstate -k -d -f "
+ "%s/dump_systemstate_%s.log", LOG_DUMP_DIR, timestr);
+ if (ret < 0) {
+ LOGE("Failed to snprintf for command");
+ exit(EXIT_FAILURE);
+ }
+ system_command(command);
+
+ /* Dump all logs */
+ if (opt_normal)
+ dump_scripts(DUMP_SCRIPTS_DIR);
+
+ if (version_str) {
+ ret = snprintf(dump_filename, sizeof(dump_filename), "%s_%s",
+ "log_dump", version_str);
+ if (ret < 0) {
+ LOGE("Failed to snprintf for dump path");
+ exit(EXIT_FAILURE);
+ }
+ } else {
+ ret = snprintf(dump_filename, sizeof(dump_filename), "%s",
+ "log_dump");
+ if (ret < 0) {
+ LOGE("Failed to snprintf for dump path");
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ /* Compression */
+ ret = snprintf(command, sizeof(command),
+ "/bin/tar -zcf %s/%s%s.tar.gz -C %s dump",
+ LOG_DUMP_ROOT, dump_filename, timestr, LOG_DUMP_ROOT);
+ if (ret < 0) {
+ LOGE("Failed to snprintf for command");
+ exit(EXIT_FAILURE);
+ }
+ system_command(command);
+
+ sync();
+
+ if (remove_dir(LOG_DUMP_DIR, 0) < 0) {
+ ret = -1;
+ LOGE("Failed to delete dump directory");
+ }
+
+ if (version_str)
+ free(version_str);
+
+ return ret;
+}