return 1;
}
-static int remove_dir_internal(int fd)
-{
- DIR *dir;
- struct dirent *de = NULL;
- int subfd, ret = 0;
-
- dir = fdopendir(fd);
- if (!dir)
- return -1;
- while (1) {
- de = readdir(dir);
- if (ret != 0 || de == NULL)
- break;
- if (de->d_type == DT_DIR) {
- if (!strncmp(de->d_name, ".", 2) || !strncmp(de->d_name, "..", 3))
- continue;
- subfd = openat(fd, de->d_name, O_RDONLY | O_DIRECTORY);
- if (subfd < 0) {
- _SE("Couldn't openat %s: %d\n", de->d_name, errno);
- ret = -1;
- continue;
- }
- if (remove_dir_internal(subfd))
- ret = -1;
-
- close(subfd);
- if (unlinkat(fd, de->d_name, AT_REMOVEDIR) < 0) {
- _SE("Couldn't unlinkat %s: %d\n", de->d_name, errno);
- ret = -1;
- }
- } else {
- if (unlinkat(fd, de->d_name, 0) < 0) {
- _SE("Couldn't unlinkat %s: %d\n", de->d_name, errno);
- ret = -1;
- }
- }
- }
- closedir(dir);
- return ret;
-}
-
-int remove_dir(const char *path, int del_dir)
-{
- int fd, ret = 0;
-
- if (!path)
- return -1;
- fd = open(path, O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_CLOEXEC | O_NOFOLLOW);
- if (fd < 0) {
- _SE("Couldn't opendir %s: %d\n", path, errno);
- return -errno;
- }
- ret = remove_dir_internal(fd);
- close(fd);
-
- if (del_dir) {
- if (rmdir(path)) {
- _SE("Couldn't rmdir %s: %d\n", path, errno);
- ret = -1;
- }
- }
- return ret;
-}
-
/*
* Helper function
* - Read from sysfs entry
int is_vip(int pid);
int is_app(pid_t pid);
int run_child(int argc, const char *argv[]);
-int remove_dir(const char *path, int del_dir);
int sys_check_node(char *path);
int sys_get_int(char *fname, int *val);
int sys_set_int(char *fname, int val);