PERFORCE change 174840 for review

Peter Wemm peter at FreeBSD.org
Fri Feb 19 00:26:01 UTC 2010


http://p4web.freebsd.org/chv.cgi?CH=174840

Change 174840 by peter at peter_daintree on 2010/02/19 00:25:45

	Replace a fragile, abi-sensative chunk of needlessly complicated
	code with the two syscalls that it should be making.
	
	Bonus: works in 32 bit environments on 64 bit hosts now.

Affected files ...

.. //depot/projects/hammer/lib/libutil/kld.c#3 edit

Differences ...

==== //depot/projects/hammer/lib/libutil/kld.c#3 (text) ====

@@ -38,32 +38,8 @@
 int
 kld_isloaded(const char *name)
 {
-	struct kld_file_stat fstat;
-	struct module_stat mstat;
-	const char *ko;
-	int fid, mid;
-
-	for (fid = kldnext(0); fid > 0; fid = kldnext(fid)) {
-		fstat.version = sizeof(fstat);
-		if (kldstat(fid, &fstat) != 0)
-			continue;
-		/* check if the file name matches the supplied name */
-		if (strcmp(fstat.name, name) == 0)
-			return (1);
-		/* strip .ko and try again */
-		if ((ko = strstr(fstat.name, ".ko")) != NULL &&
-		    strlen(name) == (size_t)(ko - fstat.name) &&
-		    strncmp(fstat.name, name, ko - fstat.name) == 0)
-			return (1);
-		/* look for a matching module within the file */
-		for (mid = kldfirstmod(fid); mid > 0; mid = modfnext(mid)) {
-			mstat.version = sizeof(mstat);
-			if (modstat(mid, &mstat) != 0)
-				continue;
-			if (strcmp(mstat.name, name) == 0)
-				return (1);
-		}
-	}
+	if (modstat(name) != -1 || kldfind(name) != -1)
+		return (1);
 	return (0);
 }
 


More information about the p4-projects mailing list