Introduce printk_nospam, which will prevent duplicate and excessive 
printing.

Signed-Off-By: Bodo Eggert <[EMAIL PROTECTED]>

diff -purNXdontdiff linux-2.6.11/include/linux/kernel.h 
linux-2.6.11.new/include/linux/kernel.h
--- linux-2.6.11/include/linux/kernel.h 2005-03-03 15:42:13.000000000 +0100
+++ linux-2.6.11.new/include/linux/kernel.h     2005-03-20 21:15:23.000000000 
+0100
@@ -104,6 +104,12 @@ extern int session_of_pgrp(int pgrp);
 asmlinkage int vprintk(const char *fmt, va_list args);
 asmlinkage int printk(const char * fmt, ...)
        __attribute__ ((format (printf, 1, 2)));
+asmlinkage int printk_nospam(unsigned int magic, const char * fmt, ...)
+       __attribute__ ((format (printf, 2, 3)));
+/* Don't print the previously printed message had the same magic or the rate
+   limit would be exceeded.
+   Hint: Use a unique random value for the magic, e.g. the first value from
+   cksum on the file you're editing */
 
 unsigned long int_sqrt(unsigned long);
 
diff -purNXdontdiff linux-2.6.11/kernel/printk.c 
linux-2.6.11.new/kernel/printk.c
--- linux-2.6.11/kernel/printk.c        2005-03-18 21:54:35.000000000 +0100
+++ linux-2.6.11.new/kernel/printk.c    2005-03-20 21:15:14.000000000 +0100
@@ -115,6 +115,8 @@ static int preferred_console = -1;
 /* Flag: console code may call schedule() */
 static int console_may_schedule;
 
+static int antispam_magic;
+
 /*
  *     Setup a list of consoles. Called from init/main.c
  */
@@ -517,6 +519,26 @@ asmlinkage int printk(const char *fmt, .
        va_list args;
        int r;
 
+       antispam_magic = 0;
+
+       va_start(args, fmt);
+       r = vprintk(fmt, args);
+       va_end(args);
+
+       return r;
+}
+
+asmlinkage int printk_nospam(unsigned int magic, const char *fmt, ...)
+{
+       va_list args;
+       int r;
+       
+       if (magic == antispam_magic)
+               return 0;
+       if (!printk_ratelimit())
+               return 0;
+       antispam_magic = magic;
+
        va_start(args, fmt);
        r = vprintk(fmt, args);
        va_end(args);
@@ -591,6 +613,7 @@ out:
        return printed_len;
 }
 EXPORT_SYMBOL(printk);
+EXPORT_SYMBOL(printk_nospam);
 EXPORT_SYMBOL(vprintk);
 
 /**
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to