How to know the system state if the system is going for halt or poweroff or reboot in FreeBSD
sibananda.sahu at avagotech.com
Mon Mar 30 18:51:59 UTC 2015
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:
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
- 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.
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
SO IS THERE ANY OTHER WAY TO GET THE SYSTEM STATE IN FREEBSD???
More information about the freebsd-questions