=== modified file 'dracut-module/password-agent.c' --- dracut-module/password-agent.c 2019-08-03 11:39:38 +0000 +++ dracut-module/password-agent.c 2019-08-03 11:52:41 +0000 @@ -431,6 +431,7 @@ case EACCES: case ENAMETOOLONG: case ENOENT: + case ENOTDIR: return EX_OSFILE; default: return EX_OSERR; @@ -1018,7 +1019,8 @@ } if(inotify_add_watch(fd, dir, IN_CLOSE_WRITE | IN_MOVED_TO - | IN_MOVED_FROM| IN_DELETE | IN_EXCL_UNLINK) + | IN_MOVED_FROM| IN_DELETE | IN_EXCL_UNLINK + | IN_ONLYDIR) == -1){ error(0, errno, "Failed to create inotify watch on %s", dir); return false; @@ -3452,6 +3454,44 @@ g_assert_cmpuint((unsigned int)queue->length, ==, 0); } +static void test_add_inotify_dir_watch_nondir(__attribute__((unused)) + test_fixture *fixture, + __attribute__((unused)) + gconstpointer + user_data){ + __attribute__((cleanup(cleanup_close))) + const int epoll_fd = epoll_create1(EPOLL_CLOEXEC); + g_assert_cmpint(epoll_fd, >=, 0); + __attribute__((cleanup(cleanup_queue))) + task_queue *queue = create_queue(); + g_assert_nonnull(queue); + __attribute__((cleanup(string_set_clear))) + string_set cancelled_filenames = {}; + const mono_microsecs current_time = 0; + + bool quit_now = false; + buffer password = {}; + bool mandos_client_exited = false; + bool password_is_read = false; + + const char not_a_directory[] = "/dev/tty"; + + FILE *real_stderr = stderr; + FILE *devnull = fopen("/dev/null", "we"); + g_assert_nonnull(devnull); + stderr = devnull; + g_assert_false(add_inotify_dir_watch(queue, epoll_fd, &quit_now, + &password, not_a_directory, + &cancelled_filenames, + ¤t_time, + &mandos_client_exited, + &password_is_read)); + stderr = real_stderr; + g_assert_cmpint(fclose(devnull), ==, 0); + + g_assert_cmpuint((unsigned int)queue->length, ==, 0); +} + static void test_add_inotify_dir_watch_EAGAIN(__attribute__((unused)) test_fixture *fixture, __attribute__((unused)) @@ -7905,6 +7945,8 @@ test_add_inotify_dir_watch); test_add_st("/task-creators/add_inotify_dir_watch/fail", test_add_inotify_dir_watch_fail); + test_add_st("/task-creators/add_inotify_dir_watch/not-a-directory", + test_add_inotify_dir_watch_nondir); test_add_st("/task-creators/add_inotify_dir_watch/EAGAIN", test_add_inotify_dir_watch_EAGAIN); test_add_st("/task-creators/add_inotify_dir_watch/IN_CLOSE_WRITE",