Results 1 to 1 of 1
Hi, I have some units installed remotely and I want to be prevented to be informed if they are doing the auto reboot because a kernel panic (It have happened ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 08-09-2011 #1Just Joined!
- Join Date
- Jul 2011
- Posts
- 12
Need to Log a Kernel Panic (Module writed using panic_notifier)
Hi, I have some units installed remotely and I want to be prevented to be informed if they are doing the auto reboot because a kernel panic (It have happened before)
I have make a Kernel module which writes KERNEL PANIC in a file of the filesystem. It has worked in a precompiled kernel and filesystem during a forced kernel panic but not working today when I tried to applied it.
Here is my driver code, the panic event is received correctly (debugged with printk), and the write file functions works (tested calling the function from load function)
here is the actual panic.c kernel code on kernel panic from my actual kernel, "atomic_notifier_call_chain(&panic_notifier_li st, 0, buf);" is which calls my module.Code:#include <linux/kernel.h> #include <linux/init.h> #include <linux/notifier.h> #include <linux/module.h> #include <linux/syscalls.h> #include <linux/fs.h> #include <linux/fcntl.h> #include <asm/uaccess.h> #include <linux/file.h> char buf[100]; int i; int count; struct file *phMscd_Filp = NULL; mm_segment_t old_fs; // **************************************************************************** // Here is where i receive the panic notification (from panic.c) // **************************************************************************** static int panic_happened(struct notifier_block *n, unsigned long val, void *message) { for(i=0;i<100;i++) buf[i] = 0; buf[0] ='K'; buf[1] ='E'; buf[2] ='R'; buf[3] ='N'; buf[4] ='E'; buf[5] ='L'; buf[6] =' '; buf[7] ='P'; buf[8] ='A'; buf[9] ='N'; buf[10]='I'; buf[11]='C'; buf[12]=0x0A; // request file phMscd_Filp = filp_open("/etc/gs/logs/panic.log", O_RDWR | O_LARGEFILE | O_CREAT , 0); if (phMscd_Filp == NULL) printk(KERN_EMERG "filp_open error!!.\n"); // save actual space old_fs=get_fs(); // jump to other space set_fs(get_ds()); // write the file vfs_write(phMscd_Filp, buf, 13, &phMscd_Filp->f_pos); // close the file filp_close(phMscd_Filp,NULL); // back to old space set_fs(old_fs); return 0; } // **************************************************************************** // block // **************************************************************************** static struct notifier_block panic_notifier = { panic_happened, NULL, 1 }; // **************************************************************************** // load // **************************************************************************** static int __init register_my_panic(void) { atomic_notifier_chain_register(&panic_notifier_list, &panic_notifier); return 0; } // **************************************************************************** // unload // **************************************************************************** static void __exit unregister_my_panic(void) { atomic_notifier_chain_unregister(&panic_notifier_list, &panic_notifier); }
There is someting here than could be stopping my write file function?Code:NORET_TYPE void panic(const char * fmt, ...) { long i; static char buf[1024]; va_list args; #if defined(CONFIG_S390) unsigned long caller = (unsigned long) __builtin_return_address(0); #endif /* * It's possible to come here directly from a panic-assertion and not * have preempt disabled. Some functions called from here want * preempt to be disabled. No point enabling it later though... */ preempt_disable(); bust_spinlocks(1); va_start(args, fmt); vsnprintf(buf, sizeof(buf), fmt, args); va_end(args); printk(KERN_EMERG "Kernel panic - not syncing: %s\n",buf); bust_spinlocks(0); /* * If we have crashed and we have a crash kernel loaded let it handle * everything else. * Do we want to call this before we try to display a message? */ crash_kexec(NULL); #ifdef CONFIG_SMP /* * Note smp_send_stop is the usual smp shutdown function, which * unfortunately means it may not be hardened to work in a panic * situation. */ smp_send_stop(); #endif atomic_notifier_call_chain(&panic_notifier_list, 0, buf); if (!panic_blink) panic_blink = no_blink; if (panic_timeout > 0) { /* * Delay timeout seconds before rebooting the machine. * We can't use the "normal" timers since we just panicked.. */ printk(KERN_EMERG "Rebooting in %d seconds..",panic_timeout); for (i = 0; i < panic_timeout*1000; ) { touch_nmi_watchdog(); i += panic_blink(i); mdelay(1); i++; } /* This will not be a clean reboot, with everything * shutting down. But if there is a chance of * rebooting the system it will be rebooted. */ emergency_restart(); } ...


Reply With Quote
