File: loglevel.c

package info (click to toggle)
uswsusp 1.0%2B20120915-6.2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,572 kB
  • sloc: ansic: 7,164; sh: 566; makefile: 223; perl: 65
file content (64 lines) | stat: -rw-r--r-- 1,280 bytes parent folder | download | duplicates (2)
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
55
56
57
58
59
60
61
62
63
64
/* loglevel.c - routines to modify kernel console loglevel
 *
 * Released under GPL v2.
 * (c) 2007 Tim Dijkstra
 */

#include "config.h"
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mount.h>


static FILE *printk_file;
static int proc_mounted = 0;

extern inline void open_printk(void)
{
	struct stat stat_buf;
	char *procname = "/proc/sys/kernel/printk";

	if (stat(procname, &stat_buf) && errno == ENOENT) {
		if (mount("none", "/proc", "proc", 0, NULL)) {
			fprintf(stderr, "resume: Could not mount proc\n");
			return;
		} else
			proc_mounted = 1;
	}

        printk_file = fopen(procname, "r+");
}

extern inline int get_kernel_console_loglevel(void)
{
        int level = -1;

        if (printk_file) {
                rewind(printk_file);
                fscanf(printk_file, "%d", &level);
        }
        return level;
}

extern inline void set_kernel_console_loglevel(int level)
{
        if (printk_file) {
                rewind(printk_file);
                fprintf(printk_file, "%d\n", level);
                fflush(printk_file);
        }

}

extern inline void close_printk(void)
{
        if (printk_file)
                fclose(printk_file);

	if (proc_mounted)
		umount("/proc");
}