finit_module(2) was added in Linux 3.8, and even CentOS 7.2 has 3.10, so we should be able to assume that now rather than working around its possible absence (especially in the *build* environment). I've left the runtime workaround for now, since we need that to support the stdin use case anyway.
Also add a missing error check for a failure to read, so we can give a more relevant error message (we can't use xreadfile() because we need to know the resulting size). --- toys/other/insmod.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-)
From 208d84a2e31a64a4f2b522ea544dfc24fa80a64c Mon Sep 17 00:00:00 2001 From: Elliott Hughes <e...@google.com> Date: Sat, 11 Sep 2021 11:17:04 -0700 Subject: [PATCH 1/2] insmod: tiny cleanup. finit_module(2) was added in Linux 3.8, and even CentOS 7.2 has 3.10, so we should be able to assume that now rather than working around its possible absence (especially in the *build* environment). I've left the runtime workaround for now, since we need that to support the stdin use case anyway. Also add a missing error check for a failure to read, so we can give a more relevant error message (we can't use xreadfile() because we need to know the resulting size). --- toys/other/insmod.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/toys/other/insmod.c b/toys/other/insmod.c index 9a3f5958..a052f5a0 100644 --- a/toys/other/insmod.c +++ b/toys/other/insmod.c @@ -8,7 +8,7 @@ config INSMOD bool "insmod" default y help - usage: insmod MODULE [MODULE_OPTIONS] + usage: insmod MODULE [OPTION...] Load the module named MODULE passing options if given. */ @@ -16,12 +16,6 @@ config INSMOD #include "toys.h" #include <sys/syscall.h> -#ifdef SYS_finit_module -#define finit_module(fd, opts, flags) syscall(SYS_finit_module, fd, opts, flags) -#else -#define finit_module(a, b, c) (errno = ENOSYS) -#endif -#define init_module(mod, len, opts) syscall(SYS_init_module, mod, len, opts) void insmod_main(void) { @@ -36,15 +30,15 @@ void insmod_main(void) strcat(toybuf, " "); } - // finit_module was new in Linux 3.8, and doesn't work on stdin, - // so we fall back to init_module if necessary. - rc = finit_module(fd, toybuf, 0); + // finit_module doesn't work on stdin, so we fall back to init_module... + rc = syscall(SYS_finit_module, fd, toybuf, 0); if (rc && (fd == 0 || errno == ENOSYS)) { off_t len = 0; char *path = !strcmp(*toys.optargs, "-") ? "/dev/stdin" : *toys.optargs; char *buf = readfileat(AT_FDCWD, path, NULL, &len); - rc = init_module(buf, len, toybuf); + if (!buf) perror_exit("couldn't read %s", path); + rc = syscall(SYS_init_module, buf, len, toybuf); if (CFG_TOYBOX_FREE) free(buf); } -- 2.33.0.309.g3052b89438-goog
_______________________________________________ Toybox mailing list Toybox@lists.landley.net http://lists.landley.net/listinfo.cgi/toybox-landley.net