/* Paths and variables */
static struct crash_info {
- char *pid_info;
- char *tid_info;
- char *sig_info;
+ pid_t pid_info;
+ pid_t tid_info;
+ int uid_info;
+ int gid_info;
+ int sig_info;
char cmd_line[PATH_MAX];
char cmd_path[PATH_MAX];
- char time_info[80];
+ time_t time_info;
char temp_dir[PATH_MAX];
char name[FILENAME_MAX];
char result_path[PATH_MAX];
int ret;
char prstatus_name[NAME_MAX+1];
- ret = snprintf(prstatus_name, NAME_MAX, "/%s.prstatus", crash_info.pid_info);
+ ret = snprintf(prstatus_name, NAME_MAX, "/%d.prstatus", crash_info.pid_info);
if (ret < 0) {
_E("Failed to snprintf for prstatus path");
goto close_fd;
{
int ret;
char *temp_dir_ret = NULL;
- time_t time_val;
+ char date[80];
struct tm loc_tm;
- crash_info.pid_info = argv[1];
- crash_info.sig_info = argv[4];
- if (argc > 6) {
- crash_info.tid_info = strdup(argv[6]);
- if (crash_info.tid_info == NULL) {
- _E("strdup error: %m");
- return -1;
- }
- } else {
- crash_info.tid_info = NULL;
- int pid = atoi(crash_info.pid_info);
- int tid = find_crash_tid(pid);
- if (tid < 0) {
+ crash_info.pid_info = strtol(argv[1], NULL, 10);
+ crash_info.sig_info = atoi(argv[4]);
+ if (argc > 6)
+ crash_info.tid_info = strtol(argv[6], NULL, 10);
+ else {
+ crash_info.tid_info = find_crash_tid(crash_info.pid_info);
+ if (crash_info.tid_info < 0) {
_I("TID not found");
- tid = pid;
- }
-
- if (asprintf(&crash_info.tid_info, "%d", tid) == -1) {
- _E("asprintf error: %m");
- return -1;
+ crash_info.tid_info = crash_info.pid_info;
}
}
return -1;
}
- time_val = atoll(argv[5]);
- localtime_r(&time_val, &loc_tm);
- strftime(crash_info.time_info, sizeof(crash_info.time_info),
- "%Y%m%d%H%M%S", &loc_tm);
+ crash_info.time_info = strtol(argv[5], NULL, 10);
+ localtime_r(&crash_info.time_info, &loc_tm);
+ strftime(date, sizeof(date), "%Y%m%d%H%M%S", &loc_tm);
ret = snprintf(crash_info.temp_dir, sizeof(crash_info.temp_dir),
"%s/crash.XXXXXX", crash_temp_path);
return -1;
}
- ret = snprintf(crash_info.name, sizeof(crash_info.name), "%s_%s_%s",
+ ret = snprintf(crash_info.name, sizeof(crash_info.name), "%s_%d_%s",
basename(crash_info.cmd_line),
crash_info.pid_info,
- crash_info.time_info);
+ date);
if (ret < 0) {
_E("Failed to snprintf for name");
goto rm_temp;
#ifdef SYS_ASSERT
ret = snprintf(crash_info.sysassert_cs_path,
sizeof(crash_info.sysassert_cs_path),
- "/tmp/crash_stack/%s_%s.info",
+ "/tmp/crash_stack/%s_%d.info",
basename(crash_info.cmd_line), crash_info.pid_info);
if (ret < 0) {
_E("Failed to snprintf for sys-assert callstack path");
{
char maps_path[PATH_MAX];
char temp_maps_path[PATH_MAX];
- snprintf(maps_path, sizeof(maps_path), "/proc/%s/maps",
+ snprintf(maps_path, sizeof(maps_path), "/proc/%d/maps",
crash_info.pid_info);
snprintf(temp_maps_path, sizeof(temp_maps_path), "%s/%s",
get_and_save_so_info(maps_path, so_info_path);
}
-static int execute_minicoredump(int argc, char *argv[])
+static int execute_minicoredump()
{
+#define SNPRINTF_OR_EXIT(name, format) if (snprintf(name##_str, sizeof(name##_str), format, crash_info.name##_info) < 0) goto out;
+
char *coredump_name = NULL;
char *prstatus_fd_str = NULL;
- int ret = 0;
+ int ret = -1;
if (asprintf(&coredump_name, "%s.coredump", crash_info.name) == -1
|| asprintf(&prstatus_fd_str, "%d", crash_info.prstatus_fd) == -1) {
_E("Unable to allocate memory");
- ret = -1;
goto out;
}
+ char pid_str[11], uid_str[11], gid_str[11], sig_str[11], time_str[11];
+
+ SNPRINTF_OR_EXIT(pid, "%d")
+ SNPRINTF_OR_EXIT(uid, "%d")
+ SNPRINTF_OR_EXIT(gid, "%d")
+ SNPRINTF_OR_EXIT(sig, "%d")
+ SNPRINTF_OR_EXIT(time, "%ld")
+
/* Execute minicoredumper */
char *args[] = {
MINICOREDUMPER_BIN_PATH, // minicoredumper filename path
- crash_info.pid_info, // %p - pid
- argv[2], // %u - UID
- argv[3], // %g - GID
- crash_info.sig_info, // %s - number of signal
- argv[5], // %t - time of dump
+ pid_str, // %p - pid
+ uid_str, // %u - UID
+ gid_str, // %g - GID
+ sig_str, // %s - number of signal
+ time_str, // %t - time of dump
"localhost", // %h - hostname
"core", // %e - exe name (need for result filename)
MINICOREDUMPER_CONFIG_PATH, // config file
args[12], args[13], args[14]);
run_command_timeout(args[0], args, NULL, MINICOREDUMPER_TIMEOUT);
+ ret = 0;
/* Minicoredumper must be executed to dump at least PRSTATUS for
other tools, coredump, however, might have been disabled. */
free(prstatus_fd_str);
return ret;
+#undef SNPRINTF_OR_EXIT
}
-static void execute_crash_stack(int argc, char *argv[])
+static void execute_crash_stack()
{
int ret;
char command[PATH_MAX];
/* Execute crash-stack */
ret = snprintf(command, sizeof(command),
- "%s --pid %s --tid %s --sig %s --prstatus_fd %d > %s",
+ "%s --pid %d --tid %d --sig %d --prstatus_fd %d > %s",
CRASH_STACK_PATH,
crash_info.pid_info,
crash_info.tid_info,
system_command(command);
}
-static int execute_crash_modules(int argc, char *argv[])
+static int execute_crash_modules()
{
_D("Execute crash module: ");
- if (execute_minicoredump(argc, argv) < 0) {
+ if (execute_minicoredump() < 0) {
_E("Failed to run minicoredumper - can not continue");
return -1;
}
if (crash_info.have_sysassert_report)
return -1;
#endif
- execute_crash_stack(argc, argv);
+ execute_crash_stack();
return 0;
}
copy_maps();
}
/* Exec crash modules */
- if (execute_crash_modules(argc, argv) < 0) {
+ if (execute_crash_modules() < 0) {
res = EXIT_FAILURE;
goto exit;
}
struct NotifyParams notify_params = {
.prstatus_fd = crash_info.prstatus_fd,
- .pid = strtol(crash_info.pid_info, NULL, 10),
- .tid = strtol(crash_info.tid_info, NULL, 10),
+ .pid = crash_info.pid_info,
+ .tid = crash_info.tid_info,
.cmd_name = basename(crash_info.cmd_line),
.cmd_path = crash_info.cmd_path,
.report_path = crash_info.result_path,
exit:
close(crash_info.prstatus_fd);
- free(crash_info.tid_info);
free(crash_temp_path);
free(crash_root_path);
free(crash_crash_path);