[netfilter-cvslog] r4119 - in trunk/nfsim: core tools

rusty at netfilter.org rusty at netfilter.org
Sun Jul 17 23:11:15 CEST 2005


Author: rusty at netfilter.org
Date: 2005-07-17 23:11:11 +0200 (Sun, 17 Jul 2005)
New Revision: 4119

Modified:
   trunk/nfsim/core/core.c
   trunk/nfsim/core/failtest.c
   trunk/nfsim/tools/module.c
Log:
Report entire path when warning about ignored failures, so it can be reproduced under gdb.
Fix --failtest bogus "not clever enough" message now we no longer use stdin.
Fix --failtest taking forever on insmod -a: differentiate dependency failures and actual failure for module to initialize.



Modified: trunk/nfsim/core/core.c
===================================================================
--- trunk/nfsim/core/core.c	2005-07-17 20:34:07 UTC (rev 4118)
+++ trunk/nfsim/core/core.c	2005-07-17 21:11:11 UTC (rev 4119)
@@ -435,7 +435,8 @@
 		if (input_fd < 0)
 			barf_perror("Opening %s", argv[optind]);
 		nfsim_testname = argv[optind];
-	}
+	} else if (get_failtest())
+		barf("Not clever enough to use --failtest interactively");
 
 	/* Hack to make users' lives easier: set LD_LIBRARY_PATH for
 	 * fakesockopt.so, based on where we are. */

Modified: trunk/nfsim/core/failtest.c
===================================================================
--- trunk/nfsim/core/failtest.c	2005-07-17 20:34:07 UTC (rev 4118)
+++ trunk/nfsim/core/failtest.c	2005-07-17 21:11:11 UTC (rev 4119)
@@ -163,14 +163,26 @@
 	return ret;
 }
 
+static char *failpath_string(void)
+{
+	char *ret = NULL;
+	struct fail_decision *i;
+
+	list_for_each_entry(i, &decisions, list)
+		ret = talloc_asprintf_append(ret, "[%s]:%i:%c",
+					     i->location, i->tui_line,
+					     i->failed ? 'F' : 'S');
+	return ret;
+}
+
 static void warn_failure(void)
 {
 	char *warning;
 	struct fail_decision *i;
 	int last_warning = 0;
 
-	nfsim_log(LOG_ALWAYS, "WARNING: test %s ignores failures",
-		  nfsim_testname ?: "");
+	nfsim_log(LOG_ALWAYS, "WARNING: test %s ignores failures at %s",
+		  nfsim_testname ?: "", failpath_string());
 
 	list_for_each_entry(i, &decisions, list) {
 		if (i->failed && i->tui_line > last_warning) {
@@ -183,18 +195,6 @@
 	}
 }
 
-static char *failpath_string(void)
-{
-	char *ret = NULL;
-	struct fail_decision *i;
-
-	list_for_each_entry(i, &decisions, list)
-		ret = talloc_asprintf_append(ret, "[%s]:%i:%c",
-					     i->location, i->tui_line,
-					     i->failed ? 'F' : 'S');
-	return ret;
-}
-
 /* Should I fail at this point?  Once only: it would be too expensive
  * to fail at every possible call. */
 bool should_i_fail_once(const char *location)
@@ -295,12 +295,3 @@
 	}
 	exit(EXIT_SILENT);
 }
-
-/* Need to wait until after parsing to test stdin. */
-static void test_failtest_file(void)
-{
-	if (failtest && isatty(STDIN_FILENO))
-		barf("Not clever enough to use --failtest interactively");
-}
-
-init_call(test_failtest_file);

Modified: trunk/nfsim/tools/module.c
===================================================================
--- trunk/nfsim/tools/module.c	2005-07-17 20:34:07 UTC (rev 4118)
+++ trunk/nfsim/tools/module.c	2005-07-17 21:11:11 UTC (rev 4119)
@@ -163,44 +163,45 @@
 */
 }
 
-/* Returns null or error string. */
-static const char *load_mod(const char *name)
+static int destroy_mod(void *_mod)
 {
+	struct nfsim_module *mod = _mod;
+	dlclose(mod->handle);
+	list_del(&mod->list);
+	return 0;
+}
+
+static int no_init(void)
+{
+	return 0;
+}
+
+/* Returns module. */
+static struct nfsim_module *load_mod(const char *name, bool report)
+{
 	struct nfsim_module *mod;
 	char *path;
-	static char message[512];
 
-	if (find_module(name)) {
-		nfsim_log(LOG_UI, "Module %s already loaded.", name);
-		return false;
-	}
-
 	mod = talloc(NULL, struct nfsim_module);
 	path = talloc_asprintf(mod, "%s/%s.so", module_path, name);
 
 	mod->handle = dlopen(path, RTLD_NOW|RTLD_GLOBAL);
 	if (!mod->handle) {
 		talloc_free(mod);
-		return dlerror();
+		if (report)
+			nfsim_log(LOG_UI, "%s", dlerror());
+		return NULL;
 	}
 
 	mod->name = talloc_strdup(mod, name);
 	mod->use = 0;
 	mod->init = dlsym(mod->handle, "__module_init");
+	if (!mod->init)
+		mod->init = no_init;
 	mod->fini = dlsym(mod->handle, "__module_exit");
-
-	if (mod->init) {
-		int ret = mod->init();
-		if (ret != 0) {
-			dlclose(mod->handle);
-			talloc_free(mod);
-			sprintf(message, "Module %s loading failed: %i", 
-				name, ret);
-			return message;
-		}
-	}
 	list_add(&mod->list, &modules);
-	return NULL;
+	talloc_set_destructor(mod, destroy_mod);
+	return mod;
 }
 
 bool load_all_modules(void)
@@ -221,15 +222,31 @@
        do {
 	       num_succeeded = num_tried = 0;
 	       while ((d = readdir(dir)) != NULL) {
-		       if (strends(d->d_name, ".so")) {
-			       char name[strlen(d->d_name)];
-			       memcpy(name, d->d_name, strlen(d->d_name) - 3);
-			       name[strlen(d->d_name) - 3] = '\0';
-			       if (!find_module(name)) {
-				       num_tried++;
-				       num_succeeded += (load_mod(name)==NULL);
-			       }
+		       struct nfsim_module *mod;
+		       int ret;
+		       char name[strlen(d->d_name)];
+
+		       if (!strends(d->d_name, ".so"))
+			       continue;
+
+		       memcpy(name, d->d_name, strlen(d->d_name) - 3);
+		       name[strlen(d->d_name) - 3] = '\0';
+		       if (find_module(name))
+			       continue;
+
+		       num_tried++;
+		       mod = load_mod(name, false);
+		       if (!mod)
+			       continue;
+
+		       ret = mod->init();
+		       if (ret != 0) {
+			       talloc_free(mod);
+			       nfsim_log(LOG_UI, "Module %s init failed: %i",
+					 name, ret);
+			       return false;
 		       }
+		       num_succeeded++;
 	       }
 	       rewinddir(dir);
        } while (num_succeeded != 0);
@@ -239,7 +256,8 @@
 
 static bool insmod(int argc, char *argv[])
 {
-	const char *msg;
+	struct nfsim_module *mod;
+	int ret;
 
 	if (argc != 2) {
 		insmod_help(argc, argv);
@@ -249,11 +267,21 @@
 	if (streq(argv[1], "-a"))
 		return load_all_modules();
 
-	msg = load_mod(argv[1]);
-	if (msg) {
-		nfsim_log(LOG_UI, "%s", msg);
+	if (find_module(argv[1])) {
+		nfsim_log(LOG_UI, "Module %s already loaded.", argv[1]);
 		return false;
 	}
+
+	mod = load_mod(argv[1], true);
+	if (!mod)
+		return false;
+
+	ret = mod->init();
+	if (ret != 0) {
+		talloc_free(mod);
+		nfsim_log(LOG_UI, "Module %s init failed: %i", argv[1], ret);
+		return false;
+	}
 	return true;
 }
 
@@ -286,8 +314,6 @@
 	do_running_timers();
 	if (mod->fini)
 		mod->fini();
-	list_del(&mod->list);
-	dlclose(mod->handle);
 	talloc_free(mod);
 }
 




More information about the netfilter-cvslog mailing list