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);
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;
/* 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);
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;
}
/* 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
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)
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;
}
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);
}
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) {
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;
}
}
}
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);
if (del_dir) {
if (rmdir(path)) {
_E("Couldn't rmdir %s: %d\n", path, errno);
- ret = -1;
+ ret = false;
}
}
return ret;