if (readdir_r(d, &entry, &r_entry))
errx(1, "readdir_r failed");
if (r_entry == NULL)
if (readdir_r(d, &entry, &r_entry))
errx(1, "readdir_r failed");
if (r_entry == NULL)
if (strcmp(entry.d_name, ".") == 0 || strcmp(entry.d_name, "..") == 0)
continue;
char file_path[strlen(current_path) + 1 + strlen(entry.d_name) + 1];
if (strcmp(entry.d_name, ".") == 0 || strcmp(entry.d_name, "..") == 0)
continue;
char file_path[strlen(current_path) + 1 + strlen(entry.d_name) + 1];
strcpy(file_path, entry.d_name);
} else {
sprintf(file_path, "%s/%s", current_path, entry.d_name);
strcpy(file_path, entry.d_name);
} else {
sprintf(file_path, "%s/%s", current_path, entry.d_name);
// First recurse, then add the watch. This avoids spamming ourselves with irrelevant
// directory open events.
add_files_recursive(file_path);
// First recurse, then add the watch. This avoids spamming ourselves with irrelevant
// directory open events.
add_files_recursive(file_path);
inotify_fd = inotify_init1(IN_CLOEXEC | IN_NONBLOCK);
if (inotify_fd == -1)
err(1, "unable to open inotify fd");
inotify_fd = inotify_init1(IN_CLOEXEC | IN_NONBLOCK);
if (inotify_fd == -1)
err(1, "unable to open inotify fd");