From: Masatake YAMATO Date: Fri, 2 Sep 2022 20:30:23 +0000 (+0900) Subject: tests: (mkfds) add a factory for making an inotify fd X-Git-Tag: v2.39-rc1~527^2~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4d51adc5965a0a9718ed792cb1df06f6deb2cf1b;p=thirdparty%2Futil-linux.git tests: (mkfds) add a factory for making an inotify fd Signed-off-by: Masatake YAMATO --- diff --git a/tests/helpers/test_mkfds.c b/tests/helpers/test_mkfds.c index 261704ddb2..b0a9d8af3c 100644 --- a/tests/helpers/test_mkfds.c +++ b/tests/helpers/test_mkfds.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -697,6 +698,30 @@ static void make_pidfd(const struct factory *factory, struct fdesc fdescs[], pid }; } +static void make_inotify_fd(const struct factory *factory _U_, struct fdesc fdescs[], pid_t * child _U_, + int argc _U_, char ** argv _U_) +{ + int fd = inotify_init(); + if (fd < 0) + err(EXIT_FAILURE, "failed in inotify_init()"); + + if (fd != fdescs[0].fd) { + if (dup2(fd, fdescs[0].fd) < 0) { + int e = errno; + close(fd); + errno = e; + err(EXIT_FAILURE, "failed to dup %d -> %d", fd, fdescs[0].fd); + } + close(fd); + } + + fdescs[0] = (struct fdesc){ + .fd = fdescs[0].fd, + .close = close_fdesc, + .data = NULL + }; +} + #define PARAM_END { .name = NULL, } static const struct factory factories[] = { { @@ -891,6 +916,18 @@ static const struct factory factories[] = { PARAM_END }, }, + { + .name = "inotify", + .desc = "inotify fd returned from inotify_init(2)", + .priv = false, + .N = 1, + .EX_N = 0, + .fork = false, + .make = make_inotify_fd, + .params = (struct parameter []) { + PARAM_END + }, + }, }; static int count_parameters(const struct factory *factory)