diff options
author | Mateusz Moscicki <m.moscicki2@partner.samsung.com> | 2020-04-14 13:36:19 +0200 |
---|---|---|
committer | Mateusz Moscicki <m.moscicki2@partner.samsung.com> | 2020-04-15 14:40:58 +0200 |
commit | 7f9dfb70a115d383d3a20d0a17cc0dcbd2c2c67e (patch) | |
tree | e94df52d1abcc14339237d55d9eea986a8e64df8 | |
parent | 9274c50f31c9fde4b0bcb297271b49680e24548b (diff) | |
download | crash-worker-7f9dfb70a115d383d3a20d0a17cc0dcbd2c2c67e.tar.gz crash-worker-7f9dfb70a115d383d3a20d0a17cc0dcbd2c2c67e.tar.bz2 crash-worker-7f9dfb70a115d383d3a20d0a17cc0dcbd2c2c67e.zip |
Use bool instead of int in remove.*() functions
In the modified places the int type was used as a bool, so the function
signatures were changed.
Change-Id: Ic172432c33c06d40c1f71ca8137606d7ea102acf
-rw-r--r-- | src/crash-manager/crash-manager.c | 24 | ||||
-rw-r--r-- | src/shared/util.c | 28 | ||||
-rw-r--r-- | src/shared/util.h | 2 |
3 files changed, 28 insertions, 26 deletions
diff --git a/src/crash-manager/crash-manager.c b/src/crash-manager/crash-manager.c index 8a9ec5a..b64908c 100644 --- a/src/crash-manager/crash-manager.c +++ b/src/crash-manager/crash-manager.c @@ -430,7 +430,7 @@ static bool clean_temp(const char *temp_dir) if (is_locked(dir_name)) _D("Temporary directory %s is locked", dir_name); - else if (remove_dir(dir_name, 1) == -1) + else if (!remove_dir(dir_name, true)) _W("Can not remove temporary directory: %s", dir_name); else _D("Temporary directory %s removed", dir_name); @@ -494,7 +494,7 @@ bool set_crash_info(struct crash_info *cinfo) out_rm_temp: unlock_dir(cinfo->lock_fd); - remove_dir(cinfo->temp_dir, 1); + remove_dir(cinfo->temp_dir, true); clean_temp(crash_temp_path); return false; @@ -539,9 +539,9 @@ static void save_so_info(const struct crash_info *cinfo) /* remove a file whose name begins with 'beggining_of_name'. This is needed * when we don't want to include coredump in report, but we only know the * beginning of the coredump file name. */ -static int remove_file_in_dir(const char *directory, const char *beginning_of_name) +static bool remove_file_in_dir(const char *directory, const char *beginning_of_name) { - int ret = -1; + bool ret = false; int errno_unlink = 0; DIR *dir = opendir(directory); @@ -557,7 +557,7 @@ static int remove_file_in_dir(const char *directory, const char *beginning_of_na struct dirent* file_info; while ((file_info = readdir(dir)) != NULL) { if (strstr(file_info->d_name, beginning_of_name) == file_info->d_name) { - ret = unlinkat(dir_fd, file_info->d_name, 0); + ret = unlinkat(dir_fd, file_info->d_name, 0) != -1; errno_unlink = errno; break; } @@ -680,7 +680,7 @@ static bool execute_minicoredump(struct crash_info *cinfo, int *exit_code) /* Minicoredumper must be executed to dump at least PRSTATUS for other tools, coredump, however, might have been disabled. */ if (!config.dump_core && file_exists_in_dir(cinfo->pfx, coredump_name)) { - if (remove_file_in_dir(cinfo->pfx, coredump_name) != 0) + if (!remove_file_in_dir(cinfo->pfx, coredump_name)) _E("Saving core disabled - removing coredump %s/%s failed: %m", cinfo->pfx, coredump_name); else @@ -1006,12 +1006,12 @@ static int check_disk_available(const char *path, int check_size) return 0; } -static int remove_file_info(struct file_info file) +static bool remove_file_info(struct file_info file) { if (file.isdir) - return remove_dir(file.path, 1); + return remove_dir(file.path, true); else - return unlink(file.path); + return unlink(file.path) != -1; } static void clean_dump(void) @@ -1068,7 +1068,7 @@ static void clean_dump(void) if (!remove_flag) continue; - if (remove_file_info(dump_list[i]) < 0) { + if (!remove_file_info(dump_list[i])) { _E("Failed to remove %s", dump_list[i].path); continue; } @@ -1298,8 +1298,8 @@ static void crash_manager_cleanup(struct crash_info *cinfo) assert(cinfo); unlock_dir(cinfo->lock_fd); - if (remove_dir(cinfo->temp_dir, 1) < 0) - _E("Failed to delete temp directory"); + if (!remove_dir(cinfo->temp_dir, true)) + _E("Failed to delete temp directory: %s", cinfo->temp_dir); clean_temp(crash_temp_path); } diff --git a/src/shared/util.c b/src/shared/util.c index 9e90b64..667f28e 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -205,15 +205,16 @@ int make_dir(const char *path, const char *name, int mode) return r == 0 || (r == -1 && errno == EEXIST) ? 0 : -1; } -static int remove_dir_internal(int fd) +static bool remove_dir_internal(int fd) { DIR *dir; struct dirent *de; - int subfd, ret = 0; + bool ret = true; + int subfd = 0; dir = fdopendir(fd); if (!dir) - return -1; + return false; while ((de = readdir(dir))) { if (de->d_type == DT_DIR) { @@ -222,20 +223,20 @@ static int remove_dir_internal(int fd) subfd = openat(fd, de->d_name, O_RDONLY | O_DIRECTORY); if (subfd < 0) { _E("Couldn't openat %s: %d\n", de->d_name, errno); - ret = -1; + ret = false; continue; } - if (remove_dir_internal(subfd)) - ret = -1; + if (!remove_dir_internal(subfd)) + ret = false; close(subfd); if (unlinkat(fd, de->d_name, AT_REMOVEDIR) < 0) { _E("Couldn't unlinkat %s: %d\n", de->d_name, errno); - ret = -1; + ret = false; } } else { if (unlinkat(fd, de->d_name, 0) < 0) { _E("Couldn't unlinkat %s: %d\n", de->d_name, errno); - ret = -1; + ret = false; } } } @@ -243,16 +244,17 @@ static int remove_dir_internal(int fd) return ret; } -int remove_dir(const char *path, int del_dir) +bool remove_dir(const char *path, bool del_dir) { - int fd, ret = 0; + bool ret = true; + int fd = 0; if (!path) - return -1; + return false; fd = open(path, O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_CLOEXEC | O_NOFOLLOW); if (fd < 0) { _E("Couldn't opendir %s: %d\n", path, errno); - return -errno; + return false; } ret = remove_dir_internal(fd); close(fd); @@ -260,7 +262,7 @@ int remove_dir(const char *path, int del_dir) if (del_dir) { if (rmdir(path)) { _E("Couldn't rmdir %s: %d\n", path, errno); - ret = -1; + ret = false; } } return ret; diff --git a/src/shared/util.h b/src/shared/util.h index a4325ba..3de0ce1 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -46,7 +46,7 @@ int fsync_path(char *const path); int make_dir(const char *path, const char *name, int mode); -int remove_dir(const char *path, int del_dir); +bool remove_dir(const char *path, bool del_dir); int get_exec_pid(const char *execpath); |