Module Name: src
Committed By: martin
Date: Mon Aug 13 08:07:03 UTC 2012
Modified Files:
src/tests/modules: t_modctl.c
Log Message:
Make use of the new MODCTL_EXISTS check to query kernel wether (and why
not) we can load modules.
To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/tests/modules/t_modctl.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/tests/modules/t_modctl.c
diff -u src/tests/modules/t_modctl.c:1.9 src/tests/modules/t_modctl.c:1.10
--- src/tests/modules/t_modctl.c:1.9 Tue Apr 17 06:23:52 2012
+++ src/tests/modules/t_modctl.c Mon Aug 13 08:07:03 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: t_modctl.c,v 1.9 2012/04/17 06:23:52 jruoho Exp $ */
+/* $NetBSD: t_modctl.c,v 1.10 2012/08/13 08:07:03 martin Exp $ */
/*
* Copyright (c) 2008 The NetBSD Foundation, Inc.
* All rights reserved.
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: t_modctl.c,v 1.9 2012/04/17 06:23:52 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: t_modctl.c,v 1.10 2012/08/13 08:07:03 martin Exp $");
#include <sys/module.h>
#include <sys/sysctl.h>
@@ -46,7 +46,7 @@ __KERNEL_RCSID(0, "$NetBSD: t_modctl.c,v
enum presence_check { both_checks, stat_check, sysctl_check };
-static bool skip_nonmodular(void);
+static void check_permission(void);
static bool get_modstat_info(const char *, modstat_t *);
static bool get_sysctl(const char *, void *buf, const size_t);
static bool k_helper_is_present_stat(void);
@@ -61,12 +61,20 @@ static void unload_cleanup(const char *)
/* --------------------------------------------------------------------- */
/*
- * A function that is called if the kernel is detected to be non-MODULAR.
+ * A function checking wether we are allowed to load modules currently
+ * (either the kernel is not modular, or securelevel may prevent it)
*/
-static bool
-skip_nonmodular(void)
+static void
+check_permission(void)
{
- atf_tc_skip("Kernel does not have 'options MODULAR'.");
+ int err;
+
+ err = modctl(MODCTL_EXISTS, 0);
+ if (err == ENOSYS)
+ atf_tc_skip("Kernel does not have 'options MODULAR'.");
+ else if (err == EPERM)
+ atf_tc_skip("Module loading administratively forbidden");
+ ATF_CHECK(err == 0);
}
static bool
@@ -77,6 +85,7 @@ get_modstat_info(const char *name, modst
struct iovec iov;
modstat_t *ms;
+ check_permission();
for (len = 4096; ;) {
iov.iov_base = malloc(len);
iov.iov_len = len;
@@ -84,10 +93,6 @@ get_modstat_info(const char *name, modst
errno = 0;
if (modctl(MODCTL_STAT, &iov) != 0) {
-
- if (errno == ENOSYS)
- skip_nonmodular();
-
int err = errno;
fprintf(stderr, "modctl(MODCTL_STAT) failed: %s\n",
strerror(err));
@@ -203,6 +208,7 @@ load(prop_dictionary_t props, bool fatal
char filename[MAXPATHLEN], *propsstr;
modctl_load_t ml;
+ check_permission();
if (props == NULL) {
props = prop_dictionary_create();
propsstr = prop_dictionary_externalize(props);
@@ -226,10 +232,6 @@ load(prop_dictionary_t props, bool fatal
errno = err = 0;
if (modctl(MODCTL_LOAD, &ml) == -1) {
-
- if (errno == ENOSYS)
- skip_nonmodular();
-
err = errno;
fprintf(stderr, "modctl(MODCTL_LOAD, %s), failed: %s\n",
filename, strerror(err));
@@ -251,14 +253,11 @@ unload(const char *name, bool fatal)
{
int err;
+ check_permission();
printf("Unloading module %s\n", name);
errno = err = 0;
if (modctl(MODCTL_UNLOAD, __UNCONST(name)) == -1) {
-
- if (errno == ENOSYS)
- skip_nonmodular();
-
err = errno;
fprintf(stderr, "modctl(MODCTL_UNLOAD, %s) failed: %s\n",
name, strerror(err));