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: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-Id: <1184892158.26827.41.camel@localhost>
Date:	Thu, 19 Jul 2007 17:42:38 -0700
From:	Joe Perches <joe@...ches.com>
To:	linux-kernel@...r.kernel.org
Subject: RFC - pr_info,warn,dbg,err and PREFIX

A number of local #defines or functions exist which merely
add a constant prefix to printks.  Perhaps it is better
to have these functions standardized.

Thoughts?

A method to prefix pr_info messages with an arbitrary prefix
(#define PREFIX "foo") could be:

--------------------------------

#define PRINTK_stringify_1(x) #x
#define PRINTK_stringify(x) PRINTK_stringify_1(x)

#define PRINTK_USEPREFIX (strcmp(PRINTK_stringify(PREFIX), "PREFIX"))

#define PRINTK_PREFIX(PREFIX) \
({const char *p = PRINTK_USEPREFIX(PREFIX) ? PRINTK_stringify(PREFIX) + 1 : ""; p;})

#define PRINTK_PREFIXLEN(PREFIX) \
({int len = PRINTK_USEPREFIX(PREFIX) ? strlen(PRINTK_stringify(PREFIX)) - 2 : 0; len;})

#define PRINTK_PREFIXSEPARATOR(PREFIX) \
({const char *p = PRINTK_USEPREFIX(PREFIX) ? ": " : ""; p;})

#define PRINTK_PREFIXFMT "%.*s%s"
#define PRINTK_PREFIXARG PRINTK_PREFIXLEN(PREFIX), PRINTK_PREFIX(PREFIX), PRINTK_PREFIXSEPARATOR(PREFIX)

#define pr_info(fmt, arg...) printk(KERN_INFO PRINTK_PREFIXFMT fmt, PRINTK_PREFIXARG, ##arg)
#define pr_warn(fmt, arg...) printk(KERN_WARNING PRINTK_PREFIXFMT fmt, PRINTK_PREFIXARG, ##arg)
#define pr_err(fmt, arg...) printk(KERN_ERR PRINTK_PREFIXFMT fmt, PRINTK_PREFIXARG, ##arg)

---------------

With a #define of PREFIX:
	#define PREFIX "abc"
	pr_info("msg\n")
output:
	<6>abc: msg

without a #define of PREFIX:
	pr_info("msg\n")
output:
	<6>msg

---------------


-
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