| 3047 | | if (si->fd == -1) { |
| 3048 | | if ((si->fd = _fd(open(which_path, O_EVTONLY|O_NOCTTY))) == -1) { |
| 3049 | | which_path = parentdir_path; |
| 3050 | | si->fd = _fd(open(which_path, O_EVTONLY|O_NOCTTY)); |
| 3051 | | } |
| 3052 | | } |
| 3053 | | |
| 3054 | | if (si->fd == -1) { |
| 3055 | | return job_log_error(j, LOG_ERR, "Watchpath monitoring failed on \"%s\"", which_path); |
| 3056 | | } |
| 3057 | | |
| 3058 | | job_log(j, LOG_DEBUG, "Watching Vnode: %d", si->fd); |
| 3059 | | if (!job_assumes(j, kevent_mod(si->fd, EVFILT_VNODE, EV_ADD, fflags, 0, j) != -1)) { |
| 3060 | | /* Extra logging for 5321044 */ |
| 3061 | | job_log(j, LOG_ERR, "Bug (5321044): si->why == %u si->fd == %d fflags = 0x%x j == %p", si->why, si->fd, fflags, j); |
| 3062 | | } |
| | 3047 | do { |
| | 3048 | if (si->fd == -1) { |
| | 3049 | if ((si->fd = _fd(open(which_path, O_EVTONLY|O_NOCTTY))) == -1) { |
| | 3050 | which_path = parentdir_path; |
| | 3051 | si->fd = _fd(open(which_path, O_EVTONLY|O_NOCTTY)); |
| | 3052 | } |
| | 3053 | } |
| | 3054 | |
| | 3055 | if (si->fd == -1) { |
| | 3056 | return job_log_error(j, LOG_ERR, "Watchpath monitoring failed on \"%s\"", which_path); |
| | 3057 | } |
| | 3058 | |
| | 3059 | job_log(j, LOG_DEBUG, "Watching Vnode: %d", si->fd); |
| | 3060 | |
| | 3061 | if (kevent_mod(si->fd, EVFILT_VNODE, EV_ADD, fflags, 0, j) == -1) { |
| | 3062 | /* |
| | 3063 | * The FD can be revoked between the open() and kevent(). |
| | 3064 | * This is similar to the inability for kevents to be |
| | 3065 | * attached to short lived zombie processes after fork() |
| | 3066 | * but before kevent(). |
| | 3067 | */ |
| | 3068 | job_assumes(j, runtime_close(si->fd) == 0); |
| | 3069 | si->fd = -1; |
| | 3070 | } |
| | 3071 | } while (si->fd == -1); |