File: xt_log.h

package info (click to toggle)
linux 3.16.7-ckt7-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 738,580 kB
  • ctags: 2,380,866
  • sloc: ansic: 12,216,621; asm: 277,336; perl: 53,978; xml: 47,771; makefile: 30,485; sh: 8,063; python: 6,597; cpp: 5,127; yacc: 4,254; lex: 2,215; awk: 741; pascal: 231; lisp: 218; sed: 30
file content (54 lines) | stat: -rw-r--r-- 1,004 bytes parent folder | download | duplicates (18)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#define S_SIZE (1024 - (sizeof(unsigned int) + 1))

struct sbuff {
	unsigned int	count;
	char		buf[S_SIZE + 1];
};
static struct sbuff emergency, *emergency_ptr = &emergency;

static __printf(2, 3) int sb_add(struct sbuff *m, const char *f, ...)
{
	va_list args;
	int len;

	if (likely(m->count < S_SIZE)) {
		va_start(args, f);
		len = vsnprintf(m->buf + m->count, S_SIZE - m->count, f, args);
		va_end(args);
		if (likely(m->count + len < S_SIZE)) {
			m->count += len;
			return 0;
		}
	}
	m->count = S_SIZE;
	printk_once(KERN_ERR KBUILD_MODNAME " please increase S_SIZE\n");
	return -1;
}

static struct sbuff *sb_open(void)
{
	struct sbuff *m = kmalloc(sizeof(*m), GFP_ATOMIC);

	if (unlikely(!m)) {
		local_bh_disable();
		do {
			m = xchg(&emergency_ptr, NULL);
		} while (!m);
	}
	m->count = 0;
	return m;
}

static void sb_close(struct sbuff *m)
{
	m->buf[m->count] = 0;
	printk("%s\n", m->buf);

	if (likely(m != &emergency))
		kfree(m);
	else {
		emergency_ptr = m;
		local_bh_enable();
	}
}