ttyprintk: Neaten and simplify printing
The code is a bit obscure. Simplify it by using a single routine to flush the tpk_buffer and emit the buffer prefixed with "[U] ". Signed-off-by: Joe Perches <joe@perches.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
ac182e8abc
commit
0b3191d4ea
@ -31,60 +31,53 @@ static struct ttyprintk_port tpk_port;
|
|||||||
* printk messages (also suitable for logging service):
|
* printk messages (also suitable for logging service):
|
||||||
* - any cr is replaced by nl
|
* - any cr is replaced by nl
|
||||||
* - adds a ttyprintk source tag in front of each line
|
* - adds a ttyprintk source tag in front of each line
|
||||||
* - too long message is fragmeted, with '\'nl between fragments
|
* - too long message is fragmented, with '\'nl between fragments
|
||||||
* - TPK_STR_SIZE isn't really the write_room limiting factor, bcause
|
* - TPK_STR_SIZE isn't really the write_room limiting factor, because
|
||||||
* it is emptied on the fly during preformatting.
|
* it is emptied on the fly during preformatting.
|
||||||
*/
|
*/
|
||||||
#define TPK_STR_SIZE 508 /* should be bigger then max expected line length */
|
#define TPK_STR_SIZE 508 /* should be bigger then max expected line length */
|
||||||
#define TPK_MAX_ROOM 4096 /* we could assume 4K for instance */
|
#define TPK_MAX_ROOM 4096 /* we could assume 4K for instance */
|
||||||
static const char *tpk_tag = "[U] "; /* U for User */
|
|
||||||
static int tpk_curr;
|
static int tpk_curr;
|
||||||
|
|
||||||
|
static char tpk_buffer[TPK_STR_SIZE + 4];
|
||||||
|
|
||||||
|
static void tpk_flush(void)
|
||||||
|
{
|
||||||
|
if (tpk_curr > 0) {
|
||||||
|
tpk_buffer[tpk_curr] = '\0';
|
||||||
|
pr_info("[U] %s\n", tpk_buffer);
|
||||||
|
tpk_curr = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int tpk_printk(const unsigned char *buf, int count)
|
static int tpk_printk(const unsigned char *buf, int count)
|
||||||
{
|
{
|
||||||
static char tmp[TPK_STR_SIZE + 4];
|
|
||||||
int i = tpk_curr;
|
int i = tpk_curr;
|
||||||
|
|
||||||
if (buf == NULL) {
|
if (buf == NULL) {
|
||||||
/* flush tmp[] */
|
tpk_flush();
|
||||||
if (tpk_curr > 0) {
|
|
||||||
/* non nl or cr terminated message - add nl */
|
|
||||||
tmp[tpk_curr + 0] = '\n';
|
|
||||||
tmp[tpk_curr + 1] = '\0';
|
|
||||||
printk(KERN_INFO "%s%s", tpk_tag, tmp);
|
|
||||||
tpk_curr = 0;
|
|
||||||
}
|
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
tmp[tpk_curr] = buf[i];
|
if (tpk_curr >= TPK_STR_SIZE) {
|
||||||
if (tpk_curr < TPK_STR_SIZE) {
|
|
||||||
switch (buf[i]) {
|
|
||||||
case '\r':
|
|
||||||
/* replace cr with nl */
|
|
||||||
tmp[tpk_curr + 0] = '\n';
|
|
||||||
tmp[tpk_curr + 1] = '\0';
|
|
||||||
printk(KERN_INFO "%s%s", tpk_tag, tmp);
|
|
||||||
tpk_curr = 0;
|
|
||||||
if ((i + 1) < count && buf[i + 1] == '\n')
|
|
||||||
i++;
|
|
||||||
break;
|
|
||||||
case '\n':
|
|
||||||
tmp[tpk_curr + 1] = '\0';
|
|
||||||
printk(KERN_INFO "%s%s", tpk_tag, tmp);
|
|
||||||
tpk_curr = 0;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
tpk_curr++;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
/* end of tmp buffer reached: cut the message in two */
|
/* end of tmp buffer reached: cut the message in two */
|
||||||
tmp[tpk_curr + 1] = '\\';
|
tpk_buffer[tpk_curr++] = '\\';
|
||||||
tmp[tpk_curr + 2] = '\n';
|
tpk_flush();
|
||||||
tmp[tpk_curr + 3] = '\0';
|
}
|
||||||
printk(KERN_INFO "%s%s", tpk_tag, tmp);
|
|
||||||
tpk_curr = 0;
|
switch (buf[i]) {
|
||||||
|
case '\r':
|
||||||
|
tpk_flush();
|
||||||
|
if ((i + 1) < count && buf[i + 1] == '\n')
|
||||||
|
i++;
|
||||||
|
break;
|
||||||
|
case '\n':
|
||||||
|
tpk_flush();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
tpk_buffer[tpk_curr++] = buf[i];
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user