How to know the system state if the system is going for halt or poweroff or reboot in FreeBSD
Lowell Gilbert
freebsd-questions-local at be-well.ilk.org
Mon Mar 30 23:59:22 UTC 2015
Sibananda Sahu <sibananda.sahu at avagotech.com> writes:
> Linux has an enum system_state the denotes about the current system state.
>
> These values are set in the system_state global variable according to the
> current system state of either restart, booting or power off etc.
>
>
>
> See the below link for the header:
>
> http://lxr.free-electrons.com/source/include/linux/kernel.h#L450
>
>
>
> I want the similar implementation in FreeBSD.
>
> For the same I searched the source code and following are my observations:
>
> - For shutdown –h now, shutdown –p now, poweroff, init 0, init 6
> and reboot sys_reboot() is called.
>
> - Sys_reboot() will call kern_reboot() which inturn endup calling
> EVENTHANDLER_INVOKE(shutdown_final, howto);
>
> - Based on the howto variable passed to the kern_reboot() call,
> corresponding event handlers will be invoked.
>
> - For a reboot request shutdown_reset(), or for a halt request
> shutdown_halt() and so on.
>
>
>
> Initially I thought the “rebooting” global variable used inside
> kern_reboot() function is set only while rebooting the system but after
> some exercises I realized that the global variable “rebooting” is set to 1
> for halt, poweroff and reboot. I mean if the system is powering off then
> also the rebooting value is set to 1, which was really confusing for me.
>
>
>
> My requirement is to know the exact reason of shutdown, whether is it a
> power-off or a reboot call.
That's not really a requirement. It's a method you plan to use to meet
your requirement, but we can only guess at what useful functionality you
are making these changes to achieve.
> And I can get the information from the “howto” variable that is passed to
> the kern_reboot() function call, but this variable is local to
> kern_reboot() only.
I suspect that you're looking at this much later in the process than I
would recommend. You probably should be doing something with this
information (logging it?) when the reboot_args struct is being set up.
> SO IS THERE ANY OTHER WAY TO GET THE SYSTEM STATE IN FREEBSD???
Please don't shout.
More information about the freebsd-questions
mailing list