code cleanup

Hello, everybody

Some code cleanup in sys/jail.h and lib/libkvm/kvm_proc.c can be done.

Problem:

sys/jail.h defines struct prison, which depends on sys/_lock.h, sys/_mutex.h, sys/_task.h, sys/queue.h. These dependencies are protected by _KERNEL, but the struct prison itself is given away to those, defining either _KERNEL or _WANT_PRISON. So, if one includes sys/jail.h from userland (having defined _WANT_PRISON), it gets underdefined struct prison and has to include it's dependencies, which is counterincapsulative.

Impact:

struct prison is included from userland (with _WANT_PRISON) only in lib/libkvm/kvm_proc.c, which also includes struct prison's dependencies.

Solution:

1. sys/jail.c : Move includes for sys/_mutex.h, sys/_lock.h, sys/_task.h, sys/queue.h closer to struct prison (under _WANT_PRISON).
2. lib/libkvm/kvm_proc.c: Remove includes for sys/_mutex, sys/_lock.h, sys/_task.h completely.

Since lib/libkvm/kvm_proc.c has parts, dependent on sys/queue.h include for it should not be removed.


Here is the patch (cd SRCROOT/..; patch <patchfile):
Code:
---------------cut here------------------------
diff -uBrN src/lib/libkvm/kvm_proc.c src.modified/lib/libkvm/kvm_proc.c
--- src/lib/libkvm/kvm_proc.c	2008-11-29 17:32:14.000000000 +0300
+++ src.modified/lib/libkvm/kvm_proc.c	2009-05-06 23:42:42.000000000 +0400
@@ -51,9 +51,6 @@
 #define	_WANT_UCRED	/* make ucred.h give us 'struct ucred' */
 #include <sys/ucred.h>
 #include <sys/queue.h>
-#include <sys/_lock.h>
-#include <sys/_mutex.h>
-#include <sys/_task.h>
 #include <sys/cpuset.h>
 #include <sys/user.h>
 #include <sys/proc.h>
diff -uBrN src/sys/sys/jail.h src.modified/sys/sys/jail.h
--- src/sys/sys/jail.h	2009-05-05 09:49:08.000000000 +0400
+++ src.modified/sys/sys/jail.h	2009-05-06 23:35:00.000000000 +0400
@@ -120,11 +120,7 @@
 
 #else /* _KERNEL */
 
-#include <sys/queue.h>
 #include <sys/sysctl.h>
-#include <sys/_lock.h>
-#include <sys/_mutex.h>
-#include <sys/_task.h>
 
 #define JAIL_MAX	999999
 
@@ -135,7 +131,11 @@
 
 #if defined(_KERNEL) || defined(_WANT_PRISON)
 
+#include <sys/queue.h>
 #include <sys/osd.h>
+#include <sys/_lock.h>
+#include <sys/_mutex.h>
+#include <sys/_task.h>
 
 struct cpuset;
---------------end of patch-------------------
 
Back
Top