Re: [PATCH] sysctl braindamage

From: Rusty Russell (rusty@linuxcare.com.au)
Date: Tue Mar 21 2000 - 21:09:35 EST


In message <20000321173157.I7767@dukat.scot.redhat.com> you write:
> Hi,
>
> On Sun, Mar 19, 2000 at 02:20:56PM +1100, Rusty Russell wrote:
> > The sysctl internal interface is horrible: if you don't #if
> > CONFIG_SYSCTL everywhere (yuk), you get much bloat, and *worse*,
> > register_sysctl_table() always "fails".
>
> Yes. Returning a null table if you try to register one is obviously the
> correct thing to do: the caller can then avoid trying to dereference the
> table if we aren't running with CONFIG_SYSCTL.

As it is, it makes it *look like* you can do:
================
int init()
{
        my_sysctl = register_sysctl_table(mytable, 0);
        if (!my_sysctl)
                return -ENOMEM;
        return 0;
}

void cleanup()
{
        unregister_sysctl_table(my_sysctl);
}
================

But you *cannot*. You need at least:

================
int init()
{
#ifdef CONFIG_SYSCTL
        my_sysctl = register_sysctl_table(mytable, 0);
        if (!my_sysctl)
                return -ENOMEM;
#endif
        return 0;
}

void cleanup()
{
        unregister_sysctl_table(my_sysctl);
}
================

So just get rid of the stupid functions altogether when
!CONFIG_SYSCTL, and accept that your code is going to be filled with
#ifdefs.

Not only is it unjustifiably ugly, but someone went out of their way
to try to trap other coders at runtime. That's either maliciousness,
or an attempt to raise idiocy to an art form.

So you prefer this patch?
Rusty.

diff -urN --minimal --exclude *.lds --exclude autoconf.h --exclude compile.h --exclude version.h --exclude .* --exclude *.[oa] --exclude *.orig --exclude config --exclude asm --exclude modules --exclude *.[Ss] --exclude System.map --exclude consolemap_deftbl.c --exclude *~ --exclude TAGS --exclude tags --exclude modversions.h --exclude install-kernel linux-2.3-official/include/linux/sysctl.h linux-2.3/include/linux/sysctl.h
--- linux-2.3-official/include/linux/sysctl.h Sat Mar 11 15:19:28 2000
+++ linux-2.3/include/linux/sysctl.h Wed Mar 22 12:26:51 2000
@@ -668,9 +668,12 @@
         struct list_head ctl_entry;
 };
 
+#include <linux/config.h>
+#ifdef CONFIG_SYSCTL
 struct ctl_table_header * register_sysctl_table(ctl_table * table,
                                                 int insert_at_head);
 void unregister_sysctl_table(struct ctl_table_header * table);
+#endif /* CONFIG_SYSCTL */
 
 #else /* __KERNEL__ */
 
diff -urN --minimal --exclude *.lds --exclude autoconf.h --exclude compile.h --exclude version.h --exclude .* --exclude *.[oa] --exclude *.orig --exclude config --exclude asm --exclude modules --exclude *.[Ss] --exclude System.map --exclude consolemap_deftbl.c --exclude *~ --exclude TAGS --exclude tags --exclude modversions.h --exclude install-kernel linux-2.3-official/kernel/ksyms.c linux-2.3/kernel/ksyms.c
--- linux-2.3-official/kernel/ksyms.c Sun Mar 19 14:42:15 2000
+++ linux-2.3/kernel/ksyms.c Wed Mar 22 12:27:16 2000
@@ -312,8 +312,10 @@
 EXPORT_SYMBOL(unregister_exec_domain);
 
 /* sysctl table registration */
+#ifdef CONFIG_SYSCTL
 EXPORT_SYMBOL(register_sysctl_table);
 EXPORT_SYMBOL(unregister_sysctl_table);
+#endif
 EXPORT_SYMBOL(sysctl_string);
 EXPORT_SYMBOL(sysctl_intvec);
 EXPORT_SYMBOL(proc_dostring);
diff -urN --minimal --exclude *.lds --exclude autoconf.h --exclude compile.h --exclude version.h --exclude .* --exclude *.[oa] --exclude *.orig --exclude config --exclude asm --exclude modules --exclude *.[Ss] --exclude System.map --exclude consolemap_deftbl.c --exclude *~ --exclude TAGS --exclude tags --exclude modversions.h --exclude install-kernel linux-2.3-official/net/econet/Makefile linux-2.3/net/econet/Makefile
--- linux-2.3-official/net/econet/Makefile Sat Mar 11 15:19:31 2000
+++ linux-2.3/net/econet/Makefile Wed Mar 22 12:53:04 2000
@@ -10,7 +10,10 @@
 O_TARGET := econet.o
 MOD_LIST_NAME := NET_MISC_MODULES
 
-O_OBJS := af_econet.o sysctl_net_ec.o
+O_OBJS := af_econet.o
+ifeq ($(CONFIG_SYSCTL),y)
+O_OBJS += sysctl_net_ec.o
+endif
 M_OBJS := $(O_TARGET)
 
 include $(TOPDIR)/Rules.make
diff -urN --minimal --exclude *.lds --exclude autoconf.h --exclude compile.h --exclude version.h --exclude .* --exclude *.[oa] --exclude *.orig --exclude config --exclude asm --exclude modules --exclude *.[Ss] --exclude System.map --exclude consolemap_deftbl.c --exclude *~ --exclude TAGS --exclude tags --exclude modversions.h --exclude install-kernel linux-2.3-official/net/ipv4/netfilter/ip_conntrack_core.c linux-2.3/net/ipv4/netfilter/ip_conntrack_core.c
--- linux-2.3-official/net/ipv4/netfilter/ip_conntrack_core.c Sun Mar 19 14:42:16 2000
+++ linux-2.3/net/ipv4/netfilter/ip_conntrack_core.c Wed Mar 22 12:48:12 2000
@@ -796,6 +796,7 @@
 #define NET_IP_CONNTRACK_MAX 2089
 #define NET_IP_CONNTRACK_MAX_NAME "ip_conntrack_max"
 
+#ifdef CONFIG_SYSCTL
 static struct ctl_table_header *ip_conntrack_sysctl_header;
 
 static ctl_table ip_conntrack_table[] = {
@@ -813,6 +814,7 @@
         {CTL_NET, "net", NULL, 0, 0555, ip_conntrack_dir_table, 0, 0, 0, 0, 0},
         { 0 }
 };
+#endif /*CONFIG_SYSCTL*/
 
 static int kill_all(const struct ip_conntrack *i, void *data)
 {
@@ -823,7 +825,9 @@
    supposed to kill the mall. */
 void ip_conntrack_cleanup(void)
 {
+#ifdef CONFIG_SYSCTL
         unregister_sysctl_table(ip_conntrack_sysctl_header);
+#endif
         ip_ct_selective_cleanup(kill_all, NULL);
         vfree(ip_conntrack_hash);
         nf_unregister_sockopt(&so_getorigdst);
@@ -881,7 +885,9 @@
 
         ret = ip_conntrack_protocol_tcp_init();
         if (ret != 0) {
+#ifdef CONFIG_SYSCTL
                 unregister_sysctl_table(ip_conntrack_sysctl_header);
+#endif /*CONFIG_SYSCTL*/
                 vfree(ip_conntrack_hash);
                 nf_unregister_sockopt(&so_getorigdst);
         }
diff -urN --minimal --exclude *.lds --exclude autoconf.h --exclude compile.h --exclude version.h --exclude .* --exclude *.[oa] --exclude *.orig --exclude config --exclude asm --exclude modules --exclude *.[Ss] --exclude System.map --exclude consolemap_deftbl.c --exclude *~ --exclude TAGS --exclude tags --exclude modversions.h --exclude install-kernel linux-2.3-official/net/ipv4/netfilter/ip_queue.c linux-2.3/net/ipv4/netfilter/ip_queue.c
--- linux-2.3-official/net/ipv4/netfilter/ip_queue.c Sun Mar 19 14:42:16 2000
+++ linux-2.3/net/ipv4/netfilter/ip_queue.c Wed Mar 22 12:55:43 2000
@@ -643,9 +642,9 @@
  * Sysctl - queue tuning.
  *
  ****************************************************************************/
-
 static int sysctl_maxlen = IPQ_QMAX_DEFAULT;
 
+#ifdef CONFIG_SYSCTL
 static struct ctl_table_header *ipq_sysctl_header;
 
 static ctl_table ipq_table[] = {
@@ -663,6 +662,7 @@
         {CTL_NET, "net", NULL, 0, 0555, ipq_dir_table, 0, 0, 0, 0, 0},
         { 0 }
 };
+#endif
 
 /****************************************************************************
  *
@@ -733,13 +733,17 @@
         }
         register_netdevice_notifier(&ipq_dev_notifier);
         proc_net_create(IPQ_PROC_FS_NAME, 0, ipq_get_info);
+#ifdef CONFIG_SYSCTL
         ipq_sysctl_header = register_sysctl_table(ipq_root_table, 0);
+#endif
         return status;
 }
 
 static void __exit fini(void)
 {
+#ifdef CONFIG_SYSCTL
         unregister_sysctl_table(ipq_sysctl_header);
+#endif
         proc_net_remove(IPQ_PROC_FS_NAME);
         unregister_netdevice_notifier(&ipq_dev_notifier);
         ipq_queue_destroy(nlq);
diff -urN --minimal --exclude *.lds --exclude autoconf.h --exclude compile.h --exclude version.h --exclude .* --exclude *.[oa] --exclude *.orig --exclude config --exclude asm --exclude modules --exclude *.[Ss] --exclude System.map --exclude consolemap_deftbl.c --exclude *~ --exclude TAGS --exclude tags --exclude modversions.h --exclude install-kernel linux-2.3-official/net/sunrpc/sysctl.c linux-2.3/net/sunrpc/sysctl.c
--- linux-2.3-official/net/sunrpc/sysctl.c Fri Feb 11 10:20:19 2000
+++ linux-2.3/net/sunrpc/sysctl.c Wed Mar 22 12:52:05 2000
@@ -39,7 +39,9 @@
 rpc_register_sysctl(void)
 {
         if (!sunrpc_table_header) {
+#ifdef CONFIG_SYSCTL
                 sunrpc_table_header = register_sysctl_table(sunrpc_table, 1);
+#endif
 #ifdef CONFIG_PROC_FS
                 if (sunrpc_table[0].de)
                         sunrpc_table[0].de->owner = THIS_MODULE;
@@ -51,10 +53,12 @@
 void
 rpc_unregister_sysctl(void)
 {
+#ifdef CONFIG_SYSCTL
         if (sunrpc_table_header) {
                 unregister_sysctl_table(sunrpc_table_header);
                 sunrpc_table_header = NULL;
         }
+#endif /*CONFIG_SYSCTL*/
 }
 
 int

--
Hacking time.

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Thu Mar 23 2000 - 21:00:35 EST