summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMateusz Moscicki <m.moscicki2@partner.samsung.com>2018-08-28 12:35:24 +0200
committerKarol Lewandowski <k.lewandowsk@samsung.com>2018-08-28 15:58:05 +0200
commit2ef257d5011e852a9118f6039ccdde4e46c538f2 (patch)
treeb687599d4808e385ebe8b892e8c75b308d61a460
parent307f57188421fe18a6279b24d6fb70f8d2f72b81 (diff)
downloadcrash-worker-2ef257d5011e852a9118f6039ccdde4e46c538f2.tar.gz
crash-worker-2ef257d5011e852a9118f6039ccdde4e46c538f2.tar.bz2
crash-worker-2ef257d5011e852a9118f6039ccdde4e46c538f2.zip
Fix SVACE warnings
Warnings: 352484, 352485, 352486, 352488, 352489, 352490, 352491, 352492, 352493, 352494, 352495, 352496, 352497, 352498, 352501, 352502, 352487, 358117, 358162 Change-Id: I205ddaee97836c3146b25bbb380e11464713cb25
-rw-r--r--src/crash-manager/crash-manager.c29
-rw-r--r--src/crash-stack/crash-stack.c16
-rw-r--r--src/crash-stack/mem_map.c30
-rw-r--r--src/crash-stack/proc.c20
-rw-r--r--src/crash-stack/unwind.c4
5 files changed, 51 insertions, 48 deletions
diff --git a/src/crash-manager/crash-manager.c b/src/crash-manager/crash-manager.c
index eaafab9..3f3e089 100644
--- a/src/crash-manager/crash-manager.c
+++ b/src/crash-manager/crash-manager.c
@@ -275,6 +275,7 @@ static int get_config(void)
dictionary *ini = NULL;
char key[KEY_MAX];
int value;
+ int result = 1;
char *value_str;
system_max_use = SYSTEM_MAX_USE;
@@ -368,7 +369,8 @@ static int get_config(void)
crash_root_path = strdup(value_str);
if (crash_root_path == NULL) {
_E("strdup error: %m\n");
- return -1;
+ result = -1;
+ goto out;
}
}
@@ -388,8 +390,9 @@ static int get_config(void)
}
}
+out:
iniparser_freedict(ini);
- return 1;
+ return result;
}
static int make_dump_dir(void)
@@ -485,31 +488,31 @@ static int set_prstatus()
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;
}
@@ -837,14 +840,24 @@ static int execute_minicoredump(int argc, char *argv[])
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:
diff --git a/src/crash-stack/crash-stack.c b/src/crash-stack/crash-stack.c
index c4fdd03..5979c2f 100644
--- a/src/crash-stack/crash-stack.c
+++ b/src/crash-stack/crash-stack.c
@@ -304,7 +304,7 @@ static void __crash_stack_print_threads(FILE* outputfile, pid_t pid, pid_t tid)
/* 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 ||
@@ -335,7 +335,7 @@ static void __crash_stack_print_maps(FILE* outputfile, pid_t pid)
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);
@@ -398,7 +398,7 @@ static struct addr_node *get_addr_list_from_maps(int 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);
@@ -488,7 +488,7 @@ static void __crash_stack_print_meminfo(FILE* outputfile, pid_t pid)
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);
@@ -508,7 +508,7 @@ static void __crash_stack_print_meminfo(FILE* outputfile, pid_t pid)
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);
@@ -567,7 +567,7 @@ static void __print_buffer_info(FILE* bufferfile, FILE *outputfile)
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) {
@@ -632,13 +632,13 @@ int main(int argc, char **argv)
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);
diff --git a/src/crash-stack/mem_map.c b/src/crash-stack/mem_map.c
index f74bc23..3a0d463 100644
--- a/src/crash-stack/mem_map.c
+++ b/src/crash-stack/mem_map.c
@@ -195,9 +195,8 @@ static struct mem_data_chunk *mem_region_alloc_chunk(struct mem_region *region,
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;
}
@@ -336,15 +335,13 @@ static int mem_region_map_file(struct mem_region *region)
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;
}
@@ -363,17 +360,14 @@ static int mem_region_map_file(struct mem_region *region)
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;
}
@@ -384,8 +378,7 @@ static int mem_region_map_file(struct mem_region *region)
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;
@@ -410,8 +403,7 @@ static int mem_region_init_vdso(struct mem_region *region)
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;
@@ -426,8 +418,7 @@ static int mem_region_init_vsyscall(struct mem_region *region)
{
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);
@@ -436,8 +427,7 @@ static int mem_region_init_vsyscall(struct mem_region *region)
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;
diff --git a/src/crash-stack/proc.c b/src/crash-stack/proc.c
index f082440..fd346c6 100644
--- a/src/crash-stack/proc.c
+++ b/src/crash-stack/proc.c
@@ -95,7 +95,7 @@ int proc_state(int pid)
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;
}
@@ -127,18 +127,18 @@ struct mem_map *create_maps(int pid)
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);
@@ -160,7 +160,7 @@ struct mem_map *create_maps(int pid)
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;
@@ -196,7 +196,7 @@ struct mem_map *create_maps(int pid)
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;
@@ -411,7 +411,7 @@ static int copy_memory_process_vm_readv(int pid,
if (errno == ENOSYS)
rc = ENOSYS;
else
- _E("process_vm_readv: %s", strerror(errno));
+ _E("process_vm_readv: %m");
goto process_vm_readv_end;
}
@@ -459,7 +459,7 @@ static int copy_memory_proc_mem(int pid, struct mem_data_chunk **frames,
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;
}
@@ -472,8 +472,8 @@ static int copy_memory_proc_mem(int pid, struct mem_data_chunk **frames,
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;
}
diff --git a/src/crash-stack/unwind.c b/src/crash-stack/unwind.c
index c98433b..bce9ef8 100644
--- a/src/crash-stack/unwind.c
+++ b/src/crash-stack/unwind.c
@@ -331,7 +331,7 @@ static int push_symbol(struct symbols *array, const GElf_Sym *s)
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));
@@ -840,7 +840,7 @@ void *_TB_create (pid_t pid) {
long label;
if ((page = sysconf(_SC_PAGESIZE)) < 0) {
- _E("sysconf(_SC_PAGESIZE): %s", strerror(errno));
+ _E("sysconf(_SC_PAGESIZE): %m");
return NULL;
}
--page;