This adds some functions to get_kernel_console_loglevel, inspired by
those in suspend.c. We could also move parts to a shared file, if
desired.
Also sets kernel_loglevel back to the original if there were no errors.
--- ../suspend-cvs-1/resume.c 2007-01-15 16:07:41.000000000 +0100
+++ resume.c 2007-01-15 16:47:56.000000000 +0100
@@ -715,12 +717,13 @@
return error;
}
-static void set_kernel_console_loglevel(int level)
+static FILE *printk_file;
+static int proc_mounted = 0;
+
+static inline void open_printk(void)
{
- FILE *file;
struct stat stat_buf;
char *procname = "/proc/sys/kernel/printk";
- int proc_mounted = 0;
if (stat(procname, &stat_buf) && errno == ENOENT) {
if (mount("none", "/proc", "proc", 0, NULL)) {
@@ -729,11 +732,36 @@
} else
proc_mounted = 1;
}
- file = fopen(procname, "w");
- if (file) {
- fprintf(file, "%d\n", level);
- fclose(file);
- }
+
+ printk_file = fopen(procname, "r+");
+}
+
+static inline int get_kernel_console_loglevel(void)
+{
+ int level = -1;
+
+ if (printk_file) {
+ rewind(printk_file);
+ fscanf(printk_file, "%d", &level);
+ }
+ return level;
+}
+
+static inline void set_kernel_console_loglevel(int level)
+{
+ if (printk_file) {
+ rewind(printk_file);
+ fprintf(printk_file, "%d\n", level);
+ fflush(printk_file);
+ }
+
+}
+
+static inline void close_printk(void)
+{
+ if (printk_file)
+ fclose(printk_file);
+
if (proc_mounted)
umount("/proc");
}
@@ -788,7 +816,7 @@
unsigned int mem_size;
struct stat stat_buf;
int dev;
- int n, error;
+ int n, error, orig_loglevel;
error = get_config(argc, argv);
if (error)
@@ -813,6 +841,10 @@
return error;
}
+ open_printk();
+ orig_loglevel = get_kernel_console_loglevel();
+ set_kernel_console_loglevel(suspend_loglevel);
+
while (stat(resume_dev_name, &stat_buf)) {
fprintf(stderr,
"resume: Could not stat the resume device file '%s'\n"
@@ -830,8 +862,6 @@
resume_dev_name[n] = '\0';
}
- set_kernel_console_loglevel(suspend_loglevel);
-
setvbuf(stdout, NULL, _IONBF, 0);
setvbuf(stderr, NULL, _IONBF, 0);
@@ -865,9 +895,14 @@
splash.finish();
Close:
close(dev);
-
- set_kernel_console_loglevel(max_loglevel);
Free:
+ if (error)
+ set_kernel_console_loglevel(max_loglevel);
+ else if (orig_loglevel >= 0)
+ set_kernel_console_loglevel(orig_loglevel);
+
+ close_printk();
+
free(mem_pool);
return error;
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Suspend-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/suspend-devel