Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 30 Mar 2015 19:59:13 -0400
From:      Lowell Gilbert <freebsd-questions-local@be-well.ilk.org>
To:        Sibananda Sahu <sibananda.sahu@avagotech.com>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: How to know the system state if the system is going for halt or poweroff or reboot in FreeBSD
Message-ID:  <444mp2avfy.fsf@lowell-desk.lan>
In-Reply-To: <0a2b68c0f411b50a276ce00a8d8b15ee@mail.gmail.com> (Sibananda Sahu's message of "Tue, 31 Mar 2015 00:22:01 %2B0530")
References:  <0a2b68c0f411b50a276ce00a8d8b15ee@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
Sibananda Sahu <sibananda.sahu@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 =96h now, shutdown =96p now, poweroff, init 0, in=
it 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 =93rebooting=94 global variable used inside
> kern_reboot() function is set only while rebooting the system but after
> some exercises I realized that the global variable =93rebooting=94 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 =93howto=94 variable that is passe=
d 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.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?444mp2avfy.fsf>