Use bool instead of int in remove.*() functions 38/230838/3
authorMateusz Moscicki <m.moscicki2@partner.samsung.com>
Tue, 14 Apr 2020 11:36:19 +0000 (13:36 +0200)
committerMateusz Moscicki <m.moscicki2@partner.samsung.com>
Wed, 15 Apr 2020 12:40:58 +0000 (14:40 +0200)
In the modified places the int type was used as a bool, so the function
signatures were changed.

Change-Id: Ic172432c33c06d40c1f71ca8137606d7ea102acf

src/crash-manager/crash-manager.c
src/shared/util.c
src/shared/util.h

index 8a9ec5a..b64908c 100644 (file)
@@ -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);
 }
index 9e90b64..667f28e 100644 (file)
@@ -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;
index a4325ba..3de0ce1 100644 (file)
@@ -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);