Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 23 Jan 2012 15:36:24 +1030
From:      "Daniel O'Connor" <doconnor@gsoft.com.au>
To:        Andrew Davis <glneolistmail@gmail.com>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: Rebooting/Halting system from kernel module
Message-ID:  <BE6C80B9-11B2-425A-9A70-0960F8B3F007@gsoft.com.au>
In-Reply-To: <CAHdBCVdAA%2Bi4je4o55TxCKW26cp8dO4W-fh2PYq5j0qco_Y-kA@mail.gmail.com>
References:  <E1RouW1-0003BY-9s.geoffrey-levand-mail-ru@f69.mail.ru> <4F1CC6A8.3010007@freebsd.org> <CAHdBCVdAA%2Bi4je4o55TxCKW26cp8dO4W-fh2PYq5j0qco_Y-kA@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help

On 23/01/2012, at 13:33, Andrew Davis wrote:

>> do you want to sync the disks first? of just hard reset?
>=20
> 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).

=3D=3D=3D=3D reset.c =3D=3D=3D=3D
#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=3D {
    "reset",
    reset_handler,
    0
};

MODULE_VERSION(reset, 1);

DECLARE_MODULE(reset, mod_data, SI_SUB_EXEC, SI_ORDER_ANY);

static int=20
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;
	   =20
	default:
	    return(EOPNOTSUPP);
	    break;
    }

    return(ENXIO);
}
=3D=3D=3D=3D

=3D=3D=3D=3D Makefile =3D=3D=3D=3D
KMOD	=3D reset
SRCS	=3D reset.c

.include <bsd.kmod.mk>
=3D=3D=3D=3D


> On Sun, Jan 22, 2012 at 9:32 PM, Julian Elischer <julian@freebsd.org> =
wrote:
>=20
>> On 1/22/12 2:19 AM, geoffrey levand wrote:
>>=20
>>> Hi,
>>>=20
>>> how would i reboot/halt the system from a kernel module ?
>>>=20
>>=20
>> the answer is "that depends"..
>>=20
>> do you want to sync the disks first? of just hard reset?
>>=20
>>=20
>>=20
>> ______________________________**_________________
>> freebsd-hackers@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@freebsd.org>"
>>=20
> _______________________________________________
> freebsd-hackers@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
> To unsubscribe, send any mail to =
"freebsd-hackers-unsubscribe@freebsd.org"
>=20

--
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









Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?BE6C80B9-11B2-425A-9A70-0960F8B3F007>