return false;
}
- if (asprintf(&cinfo->name, "%s_%d_%s", basename(cinfo->cmd_path),
+ bool is_app = false;
+ if (get_appid(cinfo->cmd_line, cinfo->appid, sizeof(cinfo->appid)) < 0) {
+ snprintf(cinfo->appid, sizeof(cinfo->appid), "%s", basename(cinfo->cmd_line));
+ snprintf(cinfo->pkgid, sizeof(cinfo->pkgid), "%s", basename(cinfo->cmd_line));
+ } else {
+ is_app = true;
+ if (get_pkgid(cinfo->appid, cinfo->pkgid, sizeof(cinfo->pkgid)) < 0)
+ snprintf(cinfo->pkgid, sizeof(cinfo->pkgid), "%s", cinfo->appid);
+ }
+
+ if (asprintf(&cinfo->name, "%s_%d_%s", is_app ? cinfo->pkgid : basename(cinfo->cmd_path),
cinfo->pid_info, date) == -1) {
_E("Failed to snprintf for name");
cinfo->name = NULL;
goto rm_temp;
}
- if (config.allow_zip)
- ret = asprintf(&cinfo->result_path,
- "%s/%s.zip", crash_dump_path, cinfo->name);
- else
- ret = asprintf(&cinfo->result_path,
- "%s/%s", crash_dump_path, cinfo->name);
- if (ret == -1) {
- _E("Failed to asprintf for result path");
- cinfo->result_path = NULL;
- goto rm_temp;
- }
-
if (asprintf(&cinfo->pfx, "%s/%s", cinfo->temp_dir, cinfo->name) == -1) {
_E("Failed to asprintf for pfx");
cinfo->pfx = NULL;
goto rm_temp;
}
- if (set_prstatus(cinfo) < 0)
+ if (asprintf(&cinfo->zip_path, "%s/report.zip", cinfo->temp_dir) == -1) {
+ _E("Out of memory");
goto rm_temp;
-
- if (get_appid(cinfo->cmd_line, cinfo->appid, sizeof(cinfo->appid)) < 0) {
- snprintf(cinfo->appid, sizeof(cinfo->appid), "%s", basename(cinfo->cmd_line));
- snprintf(cinfo->pkgid, sizeof(cinfo->pkgid), "%s", basename(cinfo->cmd_line));
- } else {
- if (get_pkgid(cinfo->appid, cinfo->pkgid, sizeof(cinfo->pkgid)) < 0)
- snprintf(cinfo->pkgid, sizeof(cinfo->pkgid), "%s", cinfo->appid);
}
+ bool is_fullreport = config.report_type >= REP_TYPE_FULL;
+ const char *suffix = is_fullreport ? (config.allow_zip ? ".zip" : "") : ".info";
+
+ ret = asprintf(&cinfo->result_path, "%s/%s%s", crash_dump_path, cinfo->name, suffix);
+ if (ret == -1)
+ goto rm_temp;
+
+ if (set_prstatus(cinfo) < 0)
+ goto rm_temp;
+
return true;
rm_temp:
static void compress(struct crash_info *cinfo)
{
- int ret, lock_fd;
- char zip_path[PATH_MAX];
-
- ret = snprintf(zip_path, sizeof(zip_path), "%s/report.zip",
- cinfo->temp_dir);
- if (ret < 0) {
- _E("Failed to snprintf for zip path");
- return;
- }
-
- char *args[] = {"/bin/zip", "-qyr", zip_path, cinfo->name, NULL};
+ char *args[] = {"/bin/zip", "-qyr", cinfo->zip_path, cinfo->name, NULL};
spawn_param_s param1 = { .fn = spawn_nullstdfds };
spawn_param_s param0 = { .fn = spawn_chdir, .u.char_ptr = cinfo->temp_dir, .next = ¶m1 };
(void)spawn_wait(args, NULL, ¶m0, ZIP_TIMEOUT_MS, NULL);
-
- if ((lock_fd = lock_dumpdir()) < 0)
- return;
- if (!rename(zip_path, cinfo->result_path))
- clean_dump();
- else
- _E("Failed to move %s to %s", zip_path, cinfo->result_path);
- unlock_dumpdir(lock_fd);
-
- if (remove_dir(cinfo->temp_dir, 1) < 0)
- _E("Failed to delete temp directory");
}
static void move_dump_data(const char *from_path, const struct crash_info *cinfo)
free(cinfo->info_path);
free(cinfo->core_path);
free(cinfo->log_path);
+ free(cinfo->zip_path);
}
void crash_info_init(struct crash_info *cinfo)
cinfo->info_path = NULL;
cinfo->core_path = NULL;
cinfo->log_path = NULL;
+ cinfo->zip_path = NULL;
}
static bool run(struct crash_info *cinfo)
return false;
}
+ char *temp_report;
if (config.report_type >= REP_TYPE_FULL) {
/* Save shared objects info (file names, bulid IDs, rpm package names) */
save_so_info(cinfo);
if (extra_script_pid > 0)
wait_for_pid(extra_script_pid, NULL);
- /* Tar compression */
if (config.allow_zip)
compress(cinfo);
- else
- move_dump_data(cinfo->pfx, cinfo);
- } else {
- free(cinfo->result_path);
- if (asprintf(&cinfo->result_path, "%s/%s.info",
- crash_dump_path, cinfo->name) == -1) {
- cinfo->result_path = NULL;
- _E("asprintf() error: %m");
- return false;
- }
- move_dump_data(cinfo->info_path, cinfo);
- }
+
+ temp_report = config.allow_zip ? cinfo->zip_path : cinfo->pfx;
+ } else
+ temp_report = cinfo->info_path;
+
+ move_dump_data(temp_report, cinfo);
if (cinfo->print_result_path)
printf("REPORT_PATH=%s\n", cinfo->result_path);