#define APPID_MAX 128
#define PKGNAME_MAX 128
-#define CRASH_CHECK_DISK_PATH "/opt/usr"
+#define CRASH_TEMP_SUBDIR "/temp/"
+#define CRASH_PATH_SUBDIR "/dump/"
+
#define WAIT_FOR_OPT_TIMEOUT_SEC 60
#define MINICOREDUMPER_TIMEOUT 12*60
static int max_retention_sec;
static int max_crash_dump;
static bool allow_zip;
+static char* crash_root_path;
+static char* crash_crash_path;
+static char* crash_temp_path;
/* Paths and variables */
static struct crash_info {
return ret;
}
-static void get_config(void)
+static int prepare_paths(void)
+{
+ int tmp_len;
+ tmp_len = strlen(crash_root_path) + strlen(CRASH_PATH_SUBDIR);
+ crash_crash_path = (char*)malloc(tmp_len + 1);
+ if (crash_crash_path == NULL) {
+ _E("Couldn't allocate memory for crash_crash_path: %m\n");
+ return 0;
+ }
+ snprintf(crash_crash_path, tmp_len, "%s%s", crash_root_path, CRASH_PATH_SUBDIR);
+
+ tmp_len = strlen(crash_root_path) + strlen(CRASH_TEMP_SUBDIR);
+ crash_temp_path = (char*)malloc(tmp_len + 1);
+ if (crash_temp_path == NULL) {
+ _E("Couldn't allocate memory for crash_temp_path: %m\n");
+ return 0;
+ }
+ snprintf(crash_temp_path, tmp_len, "%s%s", crash_root_path, CRASH_TEMP_SUBDIR);
+ return 1;
+}
+
+static int get_config(void)
{
dictionary *ini = NULL;
char key[KEY_MAX];
int value;
+ char *value_str;
system_max_use = SYSTEM_MAX_USE;
system_keep_free = SYSTEM_KEEP_FREE;
max_retention_sec = MAX_RETENTION_SEC;
max_crash_dump = MAX_CRASH_DUMP;
allow_zip = ALLOW_ZIP;
+ crash_root_path = strdup(CRASH_ROOT_PATH);
+ if (crash_root_path == NULL) {
+ _E("strdup error: %m\n");
+ return -1;
+ }
ini = iniparser_load(CRASH_CONF_FILE);
if (!ini) {
- _E("Failed to load conf file");
- return;
+ _E("Failed to load conf file %s", CRASH_CONF_FILE);
+ return 0;
}
snprintf(key, sizeof(key), "%s:%s", CRASH_SECTION, "SystemMaxUse");
allow_zip = value;
}
+ snprintf(key, sizeof(key), "%s:%s", CRASH_SECTION, "CrashRootPath");
+ value_str = iniparser_getstring(ini, key, NULL);
+ if (value_str == NULL) {
+ _D("Invalid value for CrashRootPath. Use default value [ %s ]",
+ CRASH_ROOT_PATH);
+ } else {
+ _D("CrashRootPath [ %s ]", value_str);
+ free(crash_root_path);
+ crash_root_path = strdup(value_str);
+ if (crash_root_path == NULL) {
+ _E("strdup error: %m\n");
+ return -1;
+ }
+ }
+
iniparser_freedict(ini);
+ return 1;
}
static int make_dump_dir(void)
{
struct stat st;
- if (!stat(CRASH_PATH, &st)) {
+ if (!stat(crash_crash_path, &st)) {
if (!(st.st_mode & S_IFDIR)) {
- _E("%s (not DIR) is already exist", CRASH_PATH);
+ _E("%s (not DIR) is already exist", crash_crash_path);
return -1;
}
} else {
- if (mkdir(CRASH_PATH, 0775) < 0) {
- _E("Failed to mkdir for %s", CRASH_PATH);
+ if (mkdir(crash_crash_path, 0775) < 0) {
+ _E("Failed to mkdir for %s", crash_crash_path);
return -1;
}
}
- if (!stat(CRASH_TEMP, &st)) {
+ if (!stat(crash_temp_path, &st)) {
if (!(st.st_mode & S_IFDIR)) {
- _E("%s (not DIR) is already exist", CRASH_TEMP);
+ _E("%s (not DIR) is already exist", crash_temp_path);
return -1;
}
} else {
- if (mkdir(CRASH_TEMP, 0775) < 0) {
- _E("Failed to mkdir for %s", CRASH_TEMP);
+ if (mkdir(crash_temp_path, 0775) < 0) {
+ _E("Failed to mkdir for %s", crash_temp_path);
return -1;
}
}
"%Y%m%d%H%M%S", &loc_tm);
ret = snprintf(crash_info.temp_dir, sizeof(crash_info.temp_dir),
- "%s/crash.XXXXXX", CRASH_TEMP);
+ "%s/crash.XXXXXX", crash_temp_path);
if (ret < 0) {
_E("Failed to snprintf for temp_dir");
return -1;
if (allow_zip)
ret = snprintf(crash_info.result_path,
sizeof(crash_info.result_path),
- "%s/%s.zip", CRASH_PATH, crash_info.name);
+ "%s/%s.zip", crash_crash_path, crash_info.name);
else
ret = snprintf(crash_info.result_path,
sizeof(crash_info.result_path),
- "%s/%s", CRASH_PATH, crash_info.name);
+ "%s/%s", crash_crash_path, crash_info.name);
if (ret < 0) {
_E("Failed to snprintf for result path");
goto rm_temp;
{
int fd;
- if ((fd = open(CRASH_PATH, O_RDONLY | O_DIRECTORY)) < 0) {
- _E("Failed to open %s", CRASH_PATH);
+ if ((fd = open(crash_crash_path, O_RDONLY | O_DIRECTORY)) < 0) {
+ _E("Failed to open %s", crash_crash_path);
return -1;
}
int i, scan_num, dump_num = 0;
int fd;
- if ((fd = open(CRASH_PATH, O_DIRECTORY)) < 0) {
- _E("Failed to open %s", CRASH_PATH);
+ if ((fd = open(crash_crash_path, O_DIRECTORY)) < 0) {
+ _E("Failed to open %s", crash_crash_path);
return -1;
}
- scan_num = scandir(CRASH_PATH, &scan_list, &dump_filter, NULL);
+ scan_num = scandir(crash_crash_path, &scan_list, &dump_filter, NULL);
if (scan_num < 0) {
close(fd);
return -1;
}
if (asprintf(&(temp_list[dump_num].path), "%s/%s",
- CRASH_PATH, scan_list[i]->d_name) < 0) {
+ crash_crash_path, scan_list[i]->d_name) < 0) {
_E("Failed to asprintf");
continue;
}
/* Check disk free space to keep */
if (system_keep_free &&
- check_disk_available(CRASH_CHECK_DISK_PATH,
+ check_disk_available(crash_root_path,
system_keep_free) < 0) {
_I("Disk is not available! so set the maximum number of dump to 1");
max_crash_dump = 1;
{
unsigned int count = 0;
- while (check_disk_available(CRASH_ROOT_PATH, 0) < 0 && count < timeout) {
- log_kmsg("crash-manager: path %s is not available\n", CRASH_ROOT_PATH);
+ while (check_disk_available(crash_root_path, 0) < 0 && count < timeout) {
+ log_kmsg("crash-manager: path %s is not available\n", crash_root_path);
sleep(1);
count++;
}
if (count >= timeout) {
log_kmsg("crash-manager: timeout (%ds) while waiting for %s."
- "Probably /opt is not mounted.\n", timeout, CRASH_ROOT_PATH);
+ "Probably /opt is not mounted.\n", timeout, crash_root_path);
return 0;
}
#if defined(TIZEN_ENABLE_COREDUMP) || defined(TIZEN_ENABLE_MINICOREDUMP)
int debug_mode = access(DEBUGMODE_PATH, F_OK) == 0;
#endif
+ int res = 0;
/*
* prctl(PR_SET_DUMPABLE, 0) is not neccessary. Kernel runs the
* value that prevents from running crash-manager recursively.
*/
- if (!wait_for_opt(WAIT_FOR_OPT_TIMEOUT_SEC))
- exit(EXIT_FAILURE);
-
/* Get Configuration */
- get_config();
+ if (get_config() < 0) {
+ res = EXIT_FAILURE;
+ goto exit;
+ }
+
+ /* Prepare paths */
+ if (!prepare_paths()) {
+ res = EXIT_FAILURE;
+ goto exit;
+ }
+
+ if (!wait_for_opt(WAIT_FOR_OPT_TIMEOUT_SEC)) {
+ res = EXIT_FAILURE;
+ goto exit;
+ }
/* Create crash directories */
- if (make_dump_dir() < 0)
- exit(EXIT_FAILURE);
+ if (make_dump_dir() < 0) {
+ res = EXIT_FAILURE;
+ goto exit;
+ }
/* Set crash info */
- if (set_crash_info(argc, argv) < 0)
- exit(EXIT_FAILURE);
+ if (set_crash_info(argc, argv) < 0) {
+ res = EXIT_FAILURE;
+ goto exit;
+ }
#ifdef SYS_ASSERT
/* Fetch callstack of sys-assert */
send_notify(¬ify_params);
+exit:
close(crash_info.prstatus_fd);
- return 0;
+ free(crash_temp_path);
+ free(crash_root_path);
+ free(crash_crash_path);
+
+ return res;
}