Re: printk

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Kevin Wojtysiak wrote:
> 
> printk insists on dumping the kernel priority level WITH the message if a
> newline isn't included in the printk string.
> 
> While trying to print out a list of bytes via a for loop of this type:
> for (loop through char [] 0 to i)
> {
> printk (KERN_INFO "char[i]");
> }
> printk("\n");
> 
> I end up with something like this: <6>1<6>1<6>0<6>1<6>1<6>1<6>0<6>1<6>1<6>0
> 
> Surely there must be some way to avoid this stupid behavior.

The value in <> at the start of a line is used as the priority for that
line.  Otherwise, how would you print a string containing "<3>" (where
you want to see "<3>")?

Note that KERN_INFO expands to "<6>" so the compiler sees:
 printk( "<6>" "%d", char[i] );
(KERN_INFO isn't a separate argument as far as the compiler is
concerned, just part of the string constant.)
So pull the KERN_INFO outside of the loop.
Note that calling multiple printk's might allow another kernel message
to interrupt yours.  If you want to be sure it is on one line, build the
full message and then print it in one printk.

HTH,

Eli
--------------------.     Real Users find the one combination of bizarre
Eli Carter           \ input values that shuts down the system for days.
eli.carter(a)inet.com `-------------------------------------------------
-
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
IRC Channel:   irc.openprojects.net / #kernelnewbies
Web Page:      http://www.kernelnewbies.org/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux