LWN.net Logo

Toward more reliable logging

Toward more reliable logging

Posted Apr 15, 2012 0:40 UTC (Sun) by slashdot (guest, #22014)
In reply to: Toward more reliable logging by smurf
Parent article: Toward more reliable logging

You don't parse the colons...

The kernel sees "%[subsys]s" and adds the argument as the value of the "subsys" key, using the same format (or alternatively, just prints the unformatted format string, and userspace does the work).

This would make the API easy to use, compared to the patch which requires horrible code like this:

char* buf = kmalloc(64 + strlen(subsys_name) + strlen(dev_name));
sprintf(buf, "SUBSYS=%s\nDEVICE=%s\n", subsys_name, dev_name);
printk_emit(buf, strlen(buf), KERN_EMERG "%s: %s: device caught fire", subsys_name, dev_name);
kfree(buf);

Compare that to just:
printk(KERN_EMERG "%[subsys]s: %[device]s: device caught fire", subsys_name, dev_name);

It's clear that the API in the patch is totally inferior and that almost nobody will use it except dev_printk.


(Log in to post comments)

Toward more reliable logging

Posted Apr 15, 2012 14:56 UTC (Sun) by abacus (guest, #49001) [Link]

Does that mean that you're not familiar with kasprintf() ?

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds