Rebooting/Halting system from kernel module
geoffrey levand
geoffrey.levand at mail.ru
Mon Jan 23 07:16:12 UTC 2012
Thanks for the example.
regards
23 января 2012, 09:41 от "Daniel O'Connor" <doconnor at gsoft.com.au>:
>
> On 23/01/2012, at 13:33, Andrew Davis wrote:
>
> >> do you want to sync the disks first? of just hard reset?
> >
> > Why would anyone ever want to do that, you're a kernel mod, if you want to
> > do that just triple-fault.
>
> You can call cpu_reset().
>
> I wrote a KLD which did this because we had a driver issue where the system wouldn't reboot if you did shutdown -r (it would hang).
>
> ==== reset.c ====
> #include <sys/param.h>
> #include <sys/kernel.h>
> #include <sys/module.h>
> #include <sys/types.h>
> #include <sys/systm.h>
> #include <machine/cpu.h>
>
> static int reset_handler(module_t mod, int /*modeventtype_t*/ what,
> void *arg);
>
> static moduledata_t mod_data= {
> "reset",
> reset_handler,
> 0
> };
>
> MODULE_VERSION(reset, 1);
>
> DECLARE_MODULE(reset, mod_data, SI_SUB_EXEC, SI_ORDER_ANY);
>
> static int
> reset_handler(module_t mod, int /*modeventtype_t*/ what, void *arg) {
> switch (what) {
> case MOD_LOAD:
> printf("Forced reboot\n");
> DELAY(1000000); /* wait 1 sec for printf's to complete and be read */
> /* cpu_boot(howto); */ /* doesn't do anything at the moment */
> cpu_reset();
> printf("Reset failed!\n");
> /* NOTREACHED */ /* assuming reset worked */
> break;
>
> default:
> return(EOPNOTSUPP);
> break;
> }
>
> return(ENXIO);
> }
> ====
>
> ==== Makefile ====
> KMOD = reset
> SRCS = reset.c
>
> .include <bsd.kmod.mk>
> ====
>
> > On Sun, Jan 22, 2012 at 9:32 PM, Julian Elischer <julian at freebsd.org> wrote:
> >
> >> On 1/22/12 2:19 AM, geoffrey levand wrote:
> >>
> >>> Hi,
> >>>
> >>> how would i reboot/halt the system from a kernel module ?
> >>>
> >>
> >> the answer is "that depends"..
> >>
> >> do you want to sync the disks first? of just hard reset?
> >>
> >>
> >>
> >> ______________________________**_________________
> >> freebsd-hackers at freebsd.org mailing list
> >> http://lists.freebsd.org/**mailman/listinfo/freebsd-**hackers<http://lists.freebsd.org/mailman/listinfo/freebsd-hackers>
> >> To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@**
> >> freebsd.org <freebsd-hackers-unsubscribe at freebsd.org>"
> >>
> > _______________________________________________
> > freebsd-hackers at freebsd.org mailing list
> > http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
> > To unsubscribe, send any mail to "freebsd-hackers-unsubscribe at freebsd.org"
> >
>
> --
> Daniel O'Connor software and network engineer
> for Genesis Software - http://www.gsoft.com.au
> "The nice thing about standards is that there
> are so many of them to choose from."
> -- Andrew Tanenbaum
> GPG Fingerprint - 5596 B766 97C0 0E94 4347 295E E593 DC20 7B3F CE8C
>
> _______________________________________________
> freebsd-hackers at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
> To unsubscribe, send any mail to "freebsd-hackers-unsubscribe at freebsd.org"
>
More information about the freebsd-hackers
mailing list