From: Bodo Eggert <7eggert@gmx.de>
To: Bodo Eggert <7eggert@gmx.de>
Cc: Michael Tokarev <mjt@tls.msk.ru>, linux-kernel@vger.kernel.org
Subject: [PATCH 2.6.11.2][1/2] printk with anti-cluttering-feature
Date: Sun, 20 Mar 2005 22:35:33 +0100 (CET) [thread overview]
Message-ID: <Pine.LNX.4.58.0503202232001.3051@be1.lrz> (raw)
In-Reply-To: <Pine.LNX.4.58.0503202151360.2869@be1.lrz>
Introduce printk_nospam, which will prevent duplicate and excessive
printing.
Signed-Off-By: Bodo Eggert <7eggert@gmx.de>
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);
/**
next prev parent reply other threads:[~2005-03-20 21:31 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-03-20 4:37 [PATCH 2.6.11.2][RFC] " Bodo Eggert
2005-03-20 4:40 ` Trond Myklebust
2005-03-20 11:49 ` Michael Tokarev
2005-03-20 13:50 ` Bodo Eggert
2005-03-20 21:29 ` [PATCH 2.6.11.2][0/2] " Bodo Eggert
2005-03-20 21:35 ` Bodo Eggert [this message]
2005-03-20 21:43 ` [PATCH 2.6.11.2][2/2] " Bodo Eggert
2005-03-21 8:25 ` Bodo Eggert
2005-03-25 0:45 ` Bodo Eggert
2005-03-20 21:45 ` [PATCH 2.6.11.2][SECURITY] " Bodo Eggert
2005-03-21 14:58 ` [PATCH 2.6.11.2][RFC] " Andi Kleen
2005-03-21 15:39 ` Hugh Dickins
2005-03-21 18:50 ` Bodo Eggert
2005-03-25 0:23 ` [PATCH 2.6.11.5] atkbd: suppress debug output (was: printk with anti-cluttering-feature) Bodo Eggert
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Pine.LNX.4.58.0503202232001.3051@be1.lrz \
--to=7eggert@gmx.de \
--cc=linux-kernel@vger.kernel.org \
--cc=mjt@tls.msk.ru \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®