- /* find event associated with pid and delete it */
- udev_list_node_foreach(loop, &event_list) {
- struct udev_event *loop_event = node_to_event(loop);
-
- if (loop_event->pid == pid) {
- info(loop_event->udev, "seq %llu cleanup, pid [%d], status %i, %ld seconds old\n",
- udev_device_get_seqnum(loop_event->dev), loop_event->pid,
- exitstatus, time(NULL) - loop_event->queue_time);
- loop_event->exitstatus = exitstatus;
- if (debug_trace)
- fprintf(stderr, "exit %s (%llu)\n",
- udev_device_get_syspath(loop_event->dev),
- udev_device_get_seqnum(loop_event->dev));
- event_queue_delete(loop_event);
- childs--;
-
- /* there may be dependent events waiting */
- run_exec_q = 1;
- return;
+ for (dent = readdir(dir_from); dent != NULL; dent = readdir(dir_from)) {
+ struct stat stats;
+
+ if (dent->d_name[0] == '.')
+ continue;
+ if (fstatat(dirfd(dir_from), dent->d_name, &stats, AT_SYMLINK_NOFOLLOW) != 0)
+ continue;
+
+ if (S_ISBLK(stats.st_mode) || S_ISCHR(stats.st_mode)) {
+ udev_selinux_setfscreateconat(udev, dirfd(dir_to), dent->d_name, stats.st_mode & 0777);
+ if (mknodat(dirfd(dir_to), dent->d_name, stats.st_mode, stats.st_rdev) == 0) {
+ fchmodat(dirfd(dir_to), dent->d_name, stats.st_mode & 0777, 0);
+ fchownat(dirfd(dir_to), dent->d_name, stats.st_uid, stats.st_gid, 0);
+ } else {
+ utimensat(dirfd(dir_to), dent->d_name, NULL, 0);
+ }
+ udev_selinux_resetfscreatecon(udev);
+ } else if (S_ISLNK(stats.st_mode)) {
+ char target[UTIL_PATH_SIZE];
+ ssize_t len;
+
+ len = readlinkat(dirfd(dir_from), dent->d_name, target, sizeof(target));
+ if (len <= 0 || len == (ssize_t)sizeof(target))
+ continue;
+ target[len] = '\0';
+ udev_selinux_setfscreateconat(udev, dirfd(dir_to), dent->d_name, S_IFLNK);
+ if (symlinkat(target, dirfd(dir_to), dent->d_name) < 0 && errno == EEXIST)
+ utimensat(dirfd(dir_to), dent->d_name, NULL, AT_SYMLINK_NOFOLLOW);
+ udev_selinux_resetfscreatecon(udev);
+ } else if (S_ISDIR(stats.st_mode)) {
+ DIR *dir2_from, *dir2_to;
+
+ if (maxdepth == 0)
+ continue;
+
+ udev_selinux_setfscreateconat(udev, dirfd(dir_to), dent->d_name, S_IFDIR|0755);
+ mkdirat(dirfd(dir_to), dent->d_name, 0755);
+ udev_selinux_resetfscreatecon(udev);
+
+ dir2_to = fdopendir(openat(dirfd(dir_to), dent->d_name, O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC));
+ if (dir2_to == NULL)
+ continue;
+
+ dir2_from = fdopendir(openat(dirfd(dir_from), dent->d_name, O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC));
+ if (dir2_from == NULL) {
+ closedir(dir2_to);
+ continue;
+ }
+
+ copy_dev_dir(udev, dir2_from, dir2_to, maxdepth-1);
+
+ closedir(dir2_to);
+ closedir(dir2_from);