lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20081206070023.29149.92171.stgit@marcab.local.tull.net>
Date:	Sat, 06 Dec 2008 18:00:23 +1100
From:	Nick Andrew <nick@...k-andrew.net>
To:	Andrew Morton <akpm@...ux-foundation.org>,
	Linus Torvalds <torvalds@...ux-foundation.org>
Cc:	<linux-kernel@...r.kernel.org>
Subject: [RFC PATCH v1 3/3] Sample refactor of socket.c to use recursive printk

Sample refactor of socket.c to use recursive printk

Add a new function net_printk which takes a level argument
(kernel message level), format string and varargs and
calls printk with this format string and arguments:

    printk("%sNET: %v\n", level, fmt, args);

This is a proof of concept to show that recursive printk
works and is useful.

Signed-off-by: Nick Andrew <nick@...k-andrew.net>
---

 net/socket.c |   27 ++++++++++++++++++++-------
 1 files changed, 20 insertions(+), 7 deletions(-)


diff --git a/net/socket.c b/net/socket.c
index 92764d8..d2e0d67 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -171,6 +171,19 @@ static DEFINE_PER_CPU(int, sockets_in_use) = 0;
 					   :unix_mkname()).
 					 */
 
+/* printk for net subsystem.
+ * Prefixes every message with NET:
+ *
+ */
+
+void net_printk(char *level, char *fmt, ...) {
+	va_list	ap;
+	va_start(ap, fmt);
+
+	printk("%sNET: %v\n", level, fmt, ap);
+	va_end(ap);
+}
+
 /**
  *	move_addr_to_kernel	-	copy a socket address into kernel space
  *	@uaddr: Address in user space
@@ -535,7 +548,7 @@ void sock_release(struct socket *sock)
 	}
 
 	if (sock->fasync_list)
-		printk(KERN_ERR "sock_release: fasync list not empty!\n");
+		net_printk(KERN_ERR, "sock_release: fasync list not empty!");
 
 	get_cpu_var(sockets_in_use)--;
 	put_cpu_var(sockets_in_use);
@@ -987,7 +1000,7 @@ static int sock_close(struct inode *inode, struct file *filp)
 	 */
 
 	if (!inode) {
-		printk(KERN_DEBUG "sock_close: NULL inode\n");
+		net_printk(KERN_DEBUG, "sock_close: NULL inode");
 		return 0;
 	}
 	sock_release(SOCKET_I(inode));
@@ -1116,7 +1129,7 @@ static int __sock_create(struct net *net, int family, int type, int protocol,
 		static int warned;
 		if (!warned) {
 			warned = 1;
-			printk(KERN_INFO "%s uses obsolete (PF_INET,SOCK_PACKET)\n",
+			net_printk(KERN_INFO, "%s uses obsolete (PF_INET,SOCK_PACKET)",
 			       current->comm);
 		}
 		family = PF_PACKET;
@@ -1134,7 +1147,7 @@ static int __sock_create(struct net *net, int family, int type, int protocol,
 	sock = sock_alloc();
 	if (!sock) {
 		if (net_ratelimit())
-			printk(KERN_WARNING "socket: no more sockets\n");
+			net_printk(KERN_WARNING, "socket: no more sockets");
 		return -ENFILE;	/* Not exactly a match, but its the
 				   closest posix thing */
 	}
@@ -2162,7 +2175,7 @@ int sock_register(const struct net_proto_family *ops)
 	int err;
 
 	if (ops->family >= NPROTO) {
-		printk(KERN_CRIT "protocol %d >= NPROTO(%d)\n", ops->family,
+		net_printk(KERN_CRIT, "protocol %d >= NPROTO(%d)", ops->family,
 		       NPROTO);
 		return -ENOBUFS;
 	}
@@ -2176,7 +2189,7 @@ int sock_register(const struct net_proto_family *ops)
 	}
 	spin_unlock(&net_family_lock);
 
-	printk(KERN_INFO "NET: Registered protocol family %d\n", ops->family);
+	net_printk(KERN_INFO, "Registered protocol family %d", ops->family);
 	return err;
 }
 
@@ -2203,7 +2216,7 @@ void sock_unregister(int family)
 
 	synchronize_rcu();
 
-	printk(KERN_INFO "NET: Unregistered protocol family %d\n", family);
+	net_printk(KERN_INFO, "Unregistered protocol family %d", family);
 }
 
 static int __init sock_init(void)

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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ