From: Masatake YAMATO Date: Thu, 22 Sep 2022 01:51:33 +0000 (+0900) Subject: tests: (mkfds) allow a factory to make a factory specific temporarily data X-Git-Tag: v2.39-rc1~505^2~14 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=67aab5a5daee7087a0a041f717e192f29e6d222d;p=thirdparty%2Futil-linux.git tests: (mkfds) allow a factory to make a factory specific temporarily data Signed-off-by: Masatake YAMATO --- diff --git a/tests/helpers/test_mkfds.c b/tests/helpers/test_mkfds.c index d716665e72..a16bea9e42 100644 --- a/tests/helpers/test_mkfds.c +++ b/tests/helpers/test_mkfds.c @@ -227,7 +227,8 @@ struct factory { #define MAX_N 5 int N; /* the number of fds this factory makes */ int EX_N; /* fds made optionally */ - void (*make)(const struct factory *, struct fdesc[], int, char **); + void *(*make)(const struct factory *, struct fdesc[], int, char **); + void (*free)(const struct factory *, void *); const struct parameter * params; }; @@ -236,8 +237,8 @@ static void close_fdesc(int fd, void *data _U_) close(fd); } -static void open_ro_regular_file(const struct factory *factory, struct fdesc fdescs[], - int argc, char ** argv) +static void *open_ro_regular_file(const struct factory *factory, struct fdesc fdescs[], + int argc, char ** argv) { struct arg file = decode_arg("file", factory->params, argc, argv); struct arg offset = decode_arg("offset", factory->params, argc, argv); @@ -272,10 +273,12 @@ static void open_ro_regular_file(const struct factory *factory, struct fdesc fde .close = close_fdesc, .data = NULL }; + + return NULL; } -static void make_pipe(const struct factory *factory, struct fdesc fdescs[], - int argc, char ** argv) +static void *make_pipe(const struct factory *factory, struct fdesc fdescs[], + int argc, char ** argv) { int pd[2]; int nonblock_flags[2] = {0, 0}; @@ -365,6 +368,8 @@ static void make_pipe(const struct factory *factory, struct fdesc fdescs[], }; } } + + return NULL; } static void close_dir(int fd, void *data) @@ -376,8 +381,8 @@ static void close_dir(int fd, void *data) close_fdesc(fd, NULL); } -static void open_directory(const struct factory *factory, struct fdesc fdescs[], - int argc, char ** argv) +static void *open_directory(const struct factory *factory, struct fdesc fdescs[], + int argc, char ** argv) { struct arg dir = decode_arg("dir", factory->params, argc, argv); struct arg dentries = decode_arg("dentries", factory->params, argc, argv); @@ -424,10 +429,12 @@ static void open_directory(const struct factory *factory, struct fdesc fdescs[], .close = close_dir, .data = dp }; + + return NULL; } -static void open_rw_chrdev(const struct factory *factory, struct fdesc fdescs[], - int argc, char ** argv) +static void *open_rw_chrdev(const struct factory *factory, struct fdesc fdescs[], + int argc, char ** argv) { struct arg chrdev = decode_arg("chrdev", factory->params, argc, argv); int fd = open(ARG_STRING(chrdev), O_RDWR); @@ -450,10 +457,12 @@ static void open_rw_chrdev(const struct factory *factory, struct fdesc fdescs[], .close = close_fdesc, .data = NULL }; + + return NULL; } -static void make_socketpair(const struct factory *factory, struct fdesc fdescs[], - int argc, char ** argv) +static void *make_socketpair(const struct factory *factory, struct fdesc fdescs[], + int argc, char ** argv) { int sd[2]; struct arg socktype = decode_arg("socktype", factory->params, argc, argv); @@ -491,10 +500,12 @@ static void make_socketpair(const struct factory *factory, struct fdesc fdescs[] .data = NULL }; } + + return NULL; } -static void open_with_opath(const struct factory *factory, struct fdesc fdescs[], - int argc, char ** argv) +static void *open_with_opath(const struct factory *factory, struct fdesc fdescs[], + int argc, char ** argv) { struct arg path = decode_arg("path", factory->params, argc, argv); int fd = open(ARG_STRING(path), O_PATH|O_NOFOLLOW); @@ -517,9 +528,11 @@ static void open_with_opath(const struct factory *factory, struct fdesc fdescs[] .close = close_fdesc, .data = NULL }; + + return NULL; } -static void open_ro_blkdev(const struct factory *factory, struct fdesc fdescs[], +static void *open_ro_blkdev(const struct factory *factory, struct fdesc fdescs[], int argc, char ** argv) { struct arg blkdev = decode_arg("blkdev", factory->params, argc, argv); @@ -543,6 +556,8 @@ static void open_ro_blkdev(const struct factory *factory, struct fdesc fdescs[], .close = close_fdesc, .data = NULL, }; + + return NULL; } static int make_packet_socket(int socktype, const char *interface) @@ -592,8 +607,8 @@ static void close_fdesc_after_munmap(int fd, void *data) close(fd); } -static void make_mmapped_packet_socket(const struct factory *factory, struct fdesc fdescs[], - int argc, char ** argv) +static void *make_mmapped_packet_socket(const struct factory *factory, struct fdesc fdescs[], + int argc, char ** argv) { int sd; struct arg socktype = decode_arg("socktype", factory->params, argc, argv); @@ -667,10 +682,12 @@ static void make_mmapped_packet_socket(const struct factory *factory, struct fde .close = close_fdesc_after_munmap, .data = munmap_data, }; + + return NULL; } -static void make_pidfd(const struct factory *factory, struct fdesc fdescs[], - int argc, char ** argv) +static void *make_pidfd(const struct factory *factory, struct fdesc fdescs[], + int argc, char ** argv) { struct arg target_pid = decode_arg("target-pid", factory->params, argc, argv); pid_t pid = ARG_INTEGER(target_pid); @@ -695,10 +712,12 @@ static void make_pidfd(const struct factory *factory, struct fdesc fdescs[], .close = close_fdesc, .data = NULL }; + + return NULL; } -static void make_inotify_fd(const struct factory *factory _U_, struct fdesc fdescs[], - int argc _U_, char ** argv _U_) +static void *make_inotify_fd(const struct factory *factory _U_, struct fdesc fdescs[], + int argc _U_, char ** argv _U_) { int fd = inotify_init(); if (fd < 0) @@ -719,6 +738,8 @@ static void make_inotify_fd(const struct factory *factory _U_, struct fdesc fdes .close = close_fdesc, .data = NULL }; + + return NULL; } #define PARAM_END { .name = NULL, } @@ -1007,6 +1028,7 @@ int main(int argc, char **argv) struct fdesc fdescs[MAX_N]; bool quiet = false; bool cont = false; + void *data; static const struct option longopts[] = { { "list", no_argument, NULL, 'l' }, @@ -1079,7 +1101,7 @@ int main(int argc, char **argv) } optind += factory->N; - factory->make(factory, fdescs, argc - optind, argv + optind); + data = factory->make(factory, fdescs, argc - optind, argv + optind); signal(SIGCONT, do_nothing); @@ -1096,5 +1118,8 @@ int main(int argc, char **argv) if (fdescs[i].fd >= 0) fdescs[i].close(fdescs[i].fd, fdescs[i].data); + if (factory->free) + factory->free (factory, data); + exit(EXIT_SUCCESS); }