Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 304084
b: refs/heads/master
c: 7ff9554
h: refs/heads/master
v: v3
  • Loading branch information
Kay Sievers authored and Greg Kroah-Hartman committed May 7, 2012
1 parent e7bb096 commit 427704f
Show file tree
Hide file tree
Showing 4 changed files with 640 additions and 442 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 89528127fa5f4aca0483203c87c945555d057770
refs/heads/master: 7ff9554bb578ba02166071d2d487b7fc7d860d62
55 changes: 38 additions & 17 deletions trunk/drivers/char/mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -810,33 +810,54 @@ static const struct file_operations oldmem_fops = {
static ssize_t kmsg_writev(struct kiocb *iocb, const struct iovec *iv,
unsigned long count, loff_t pos)
{
char *line, *p;
char *buf, *line;
int i;
ssize_t ret = -EFAULT;
int level = default_message_loglevel;
int facility = 1; /* LOG_USER */
size_t len = iov_length(iv, count);
ssize_t ret = len;

line = kmalloc(len + 1, GFP_KERNEL);
if (line == NULL)
if (len > 1024)
return -EINVAL;
buf = kmalloc(len+1, GFP_KERNEL);
if (buf == NULL)
return -ENOMEM;

/*
* copy all vectors into a single string, to ensure we do
* not interleave our log line with other printk calls
*/
p = line;
line = buf;
for (i = 0; i < count; i++) {
if (copy_from_user(p, iv[i].iov_base, iv[i].iov_len))
if (copy_from_user(line, iv[i].iov_base, iv[i].iov_len))
goto out;
p += iv[i].iov_len;
line += iv[i].iov_len;
}

/*
* Extract and skip the syslog prefix <[0-9]*>. Coming from userspace
* the decimal value represents 32bit, the lower 3 bit are the log
* level, the rest are the log facility.
*
* If no prefix or no userspace facility is specified, we
* enforce LOG_USER, to be able to reliably distinguish
* kernel-generated messages from userspace-injected ones.
*/
line = buf;
if (line[0] == '<') {
char *endp = NULL;

i = simple_strtoul(line+1, &endp, 10);
if (endp && endp[0] == '>') {
level = i & 7;
if (i >> 3)
facility = i >> 3;
endp++;
len -= endp - line;
line = endp;
}
}
p[0] = '\0';
line[len] = '\0';

ret = printk("%s", line);
/* printk can add a prefix */
if (ret > len)
ret = len;
printk_emit(facility, level, NULL, 0, "%s", line);
out:
kfree(line);
kfree(buf);
return ret;
}

Expand Down
11 changes: 11 additions & 0 deletions trunk/include/linux/printk.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,19 @@ extern int printk_needs_cpu(int cpu);
extern void printk_tick(void);

#ifdef CONFIG_PRINTK
asmlinkage __printf(5, 0)
int vprintk_emit(int facility, int level,
const char *dict, size_t dictlen,
const char *fmt, va_list args);

asmlinkage __printf(1, 0)
int vprintk(const char *fmt, va_list args);

asmlinkage __printf(5, 6) __cold
asmlinkage int printk_emit(int facility, int level,
const char *dict, size_t dictlen,
const char *fmt, ...);

asmlinkage __printf(1, 2) __cold
int printk(const char *fmt, ...);

Expand Down
Loading

0 comments on commit 427704f

Please sign in to comment.