dictionary *ini = NULL;
char key[KEY_MAX];
int value;
+ int result = 1;
char *value_str;
system_max_use = SYSTEM_MAX_USE;
crash_root_path = strdup(value_str);
if (crash_root_path == NULL) {
_E("strdup error: %m\n");
- return -1;
+ result = -1;
+ goto out;
}
}
}
}
+out:
iniparser_freedict(ini);
- return 1;
+ return result;
}
static int make_dump_dir(void)
crash_info.prstatus_fd = shm_open(prstatus_name, O_RDWR | O_CREAT, 0600);
if (crash_info.prstatus_fd < 0) {
- _E("shm_open: %s", strerror(errno));
+ _E("shm_open: %m");
goto close_fd;
}
ret = shm_unlink(prstatus_name);
if (ret < 0) {
- _E("shm_unlink: %s", strerror(errno));
+ _E("shm_unlink: %m");
goto close_fd;
}
ret = fcntl(crash_info.prstatus_fd, F_GETFD);
if (ret < 0) {
- _E("fcntl(): %s", strerror(errno));
+ _E("fcntl(): %m");
goto close_fd;
}
ret = fcntl(crash_info.prstatus_fd, F_SETFD, ret & ~FD_CLOEXEC);
if (ret < 0) {
- _E("fcntl(): %s", strerror(errno));
+ _E("fcntl(): %m");
goto close_fd;
}
ret = ftruncate(crash_info.prstatus_fd, sizeof(struct elf_prstatus));
if (ret < 0) {
- _E("ftruncate(): %s", strerror(errno));
+ _E("ftruncate(): %m");
goto close_fd;
}
if (!dump_core) {
int ret = -1;
int errno_unlink = 0;
+ char errno_buff[128];
+ char *err_str = NULL;
int dirfd = open(crash_info.pfx, O_DIRECTORY);
if (dirfd != -1) {
ret = unlinkat(dirfd, coredump_name, 0);
errno_unlink = errno;
close(dirfd);
}
+
+ if (ret != 0) {
+ err_str = strerror_r(errno_unlink, errno_buff, sizeof(errno_buff));
+ if (err_str == NULL)
+ _E("strerror_r() error: %m\n");
+ goto out;
+ }
+
_D("Saving core disabled - removing coredump %s/%s: %s", crash_info.pfx, coredump_name,
- ret == 0 ? "success" : strerror(errno_unlink));
+ ret == 0 ? "success" : err_str);
}
out:
/* print thread */
dir = opendir(task_path);
if (!dir) {
- _E("opendir(%s): %s", task_path, strerror(errno));
+ _E("opendir(%s): %m", task_path);
} else {
while ((dentry = readdir(dir))) {
if (strcmp(dentry->d_name, ".") == 0 ||
snprintf(file_path, PATH_MAX, "/proc/%d/maps", pid);
if ((fd = open(file_path, O_RDONLY)) < 0) {
- _E("open(%s): %s", file_path, strerror(errno));
+ _E("open(%s): %m", file_path);
} else {
/* parsing the maps to get code segment address*/
head = get_addr_list_from_maps(fd);
PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (t_node == NULL) {
- _E("mmap(): %s", strerror(errno));
+ _E("mmap(): %m");
return NULL;
}
memcpy(t_node->perm, perm, PERM_LEN+1);
fprintf(outputfile, "\nMemory information\n");
if ((fd = open("/proc/meminfo", O_RDONLY)) < 0) {
- _E("open(/proc/meminfo): %s", strerror(errno));
+ _E("open(/proc/meminfo): %m");
} else {
while (fgets_fd(linebuf, BUF_SIZE, fd) != NULL) {
sscanf(linebuf, "%16s %16s %*s", infoname, memsize);
snprintf(file_path, PATH_MAX, "/proc/%d/status", pid);
if ((fd = open(file_path, O_RDONLY)) < 0) {
- _E("open(%s): %s", file_path, strerror(errno));
+ _E("open(%s): %m", file_path);
} else {
while (fgets_fd(linebuf, BUF_SIZE, fd) != NULL) {
sscanf(linebuf, "%16s %16s %*s", infoname, memsize);
char buf[1024];
if (fseek(bufferfile, 0, SEEK_SET) < 0) {
- _E("fseek(): %s", strerror(errno));
+ _E("fseek(): %m");
return;
}
while (!(feof(bufferfile) || ferror(bufferfile)) && (cnt = fread(buf, sizeof(char), sizeof(buf), bufferfile)) != 0) {
mode_t oldmode = umask(0077);
if (mkstemp(bufferfile_path) < 0) {
- _E("mkstemp(%s): %s", bufferfile_path, strerror(errno));
+ _E("mkstemp(%s): %m", bufferfile_path);
return errno;
}
umask(oldmode);
if ((bufferfile = fopen(bufferfile_path, "w+")) == NULL) {
- _E("fopen(%s): %s", bufferfile_path, strerror(errno));
+ _E("fopen(%s): %m", bufferfile_path);
return errno;
}
unlink(bufferfile_path);
chunk->length = (size_t)end - (size_t)start;
rc = posix_memalign((void **)&chunk->data, align, chunk->length);
if (rc < 0) {
- int err = errno;
free(chunk);
- _E("posix_memalign:%s", strerror(err));
+ _E("posix_memalign:%m");
return NULL;
}
region->fd = open(region->path, O_RDONLY);
if (region->fd < 0) {
- int err = errno;
mem_region_print(region);
- _E("open(%s):%s", region->path, strerror(err));
+ _E("open(%s):%m", region->path);
return -1;
}
if (fstat(region->fd, &stat_buf) < 0) {
- int err = errno;
- _E("Unable to stat file %s: %s", region->path, strerror(err));
+ _E("Unable to stat file %s: %m", region->path);
return -1;
}
region->offset);
if (data == MAP_FAILED) {
- int err = errno;
- _E("Unable to mmap file %s (length 0x%zx, read, offset 0x%zx): %s",
- region->path, region->length, region->offset,
- strerror(err));
+ _E("Unable to mmap file %s (length 0x%zx, read, offset 0x%zx): %m",
+ region->path, region->length, region->offset);
return -1;
}
region->data_head = malloc(sizeof(struct mem_data_chunk));
if (region->data_head == NULL) {
- int err = errno;
- _E("Unable to allocate memory:%s", strerror(err));
+ _E("Unable to allocate memory:%m");
munmap(data, length);
return -1;
}
region->data_index = malloc(sizeof(struct mem_data_chunk**));
if (region->data_index == NULL){
- int err = errno;
- _E("Unable to allocate memory:%s", strerror(err));
+ _E("Unable to allocate memory:%m");
free(region->data_head);
munmap(data, length);
return -1;
region->data_index = malloc(sizeof(struct mem_data_chunk**));
if (region->data_index == NULL) {
- int err = errno;
- _E("Unable to allocate memory:%s", strerror(err));
+ _E("Unable to allocate memory:%m");
return -1;
}
*region->data_index = region->data_head;
{
region->data_head = malloc(sizeof(struct mem_data_chunk));
if (region->data_head == NULL) {
- int err = errno;
- _E("Unable to allocate memory:%s", strerror(err));
+ _E("Unable to allocate memory:%m");
return -1;
}
mem_data_chunk_init(region->data_head);
region->data_head->length = region->length;
region->data_index = malloc(sizeof(struct mem_data_chunk**));
if (region->data_index == NULL) {
- int err = errno;
- _E("Unable to allocate memory:%s", strerror(err));
+ _E("Unable to allocate memory:%m");
return -1;
}
*region->data_index = region->data_head;
snprintf(buf, sizeof(buf), "/proc/%d/status", pid);
if ((f = fopen(buf, "r")) == NULL) {
- _E("Cannot open %s: %s", buf, strerror(errno));
+ _E("Cannot open %s: %m", buf);
return -1;
}
capacity = 0x100000;
buf = calloc(1, capacity);
if (buf == NULL) {
- _E("Unable to allocate memory: %s", strerror(errno));
+ _E("Unable to allocate memory: %m");
return NULL;
}
snprintf(buf, capacity, "/proc/%d/maps", pid);
if ((f = fopen(buf, "r")) == NULL) {
- _E("Cannot open %s: %s", buf, strerror(errno));
+ _E("Cannot open %s: %m", buf);
goto create_maps_end;
}
map = malloc(sizeof(struct mem_map));
if (map == NULL){
- _E("Unable to allocate memory: %s", strerror(errno));
+ _E("Unable to allocate memory: %m");
goto create_maps_end;
}
mem_map_init(map);
capacity *= 2;
buf = realloc(buf, capacity);
if (buf == NULL) {
- _E("Unable to reallocate memory: %s", strerror(errno));
+ _E("Unable to reallocate memory: %m");
mem_map_destroy(map);
map = NULL;
goto create_maps_end;
region = malloc(sizeof(struct mem_region));
if (region == NULL) {
- _E("Unable to allocate memory: %s", strerror(errno));
+ _E("Unable to allocate memory: %m");
mem_map_destroy(map);
map = NULL;
break;
if (errno == ENOSYS)
rc = ENOSYS;
else
- _E("process_vm_readv: %s", strerror(errno));
+ _E("process_vm_readv: %m");
goto process_vm_readv_end;
}
snprintf(fname, sizeof(fname), "/proc/%d/mem", pid);
if ((fd = open(fname, O_RDONLY)) == -1) {
- _E("Cannot open %s: %s", fname, strerror(errno));
+ _E("Cannot open %s: %m", fname);
return -1;
}
ssize_t rd = pread(fd, to, count, from);
if (rd == -1) {
- _E("pread() at %s:0x%lx (#%d) failed: %s [%d]",
- fname, from, i, strerror(errno), errno);
+ _E("pread() at %s:0x%lx (#%d) failed: %m [%d]",
+ fname, from, i, errno);
goto proc_mem_end;
}
array->s_cap <<= 1;
new_data = malloc(sizeof(GElf_Sym) * array->s_cap);
if (new_data == NULL) {
- _E("malloc(): %s", strerror(errno));
+ _E("malloc(): %m");
return -1;
}
memcpy(new_data, array->s_data, sizeof(GElf_Sym) * (array->s_size-1));
long label;
if ((page = sysconf(_SC_PAGESIZE)) < 0) {
- _E("sysconf(_SC_PAGESIZE): %s", strerror(errno));
+ _E("sysconf(_SC_PAGESIZE): %m");
return NULL;
}
--page;