From owner-freebsd-questions@FreeBSD.ORG Mon Mar 30 23:59:22 2015 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id D9603E30 for ; Mon, 30 Mar 2015 23:59:22 +0000 (UTC) Received: from be-well.ilk.org (be-well.ilk.org [23.30.133.173]) by mx1.freebsd.org (Postfix) with ESMTP id AEA33D55 for ; Mon, 30 Mar 2015 23:59:22 +0000 (UTC) Received: from lowell-desk.lan (lowell-desk.lan [172.30.250.41]) by be-well.ilk.org (Postfix) with ESMTP id 3374B33C46; Mon, 30 Mar 2015 19:59:16 -0400 (EDT) Received: by lowell-desk.lan (Postfix, from userid 1147) id 2962C3983C; Mon, 30 Mar 2015 19:59:14 -0400 (EDT) From: Lowell Gilbert To: Sibananda Sahu Subject: Re: How to know the system state if the system is going for halt or poweroff or reboot in FreeBSD References: <0a2b68c0f411b50a276ce00a8d8b15ee@mail.gmail.com> Reply-To: freebsd-questions@freebsd.org Date: Mon, 30 Mar 2015 19:59:13 -0400 In-Reply-To: <0a2b68c0f411b50a276ce00a8d8b15ee@mail.gmail.com> (Sibananda Sahu's message of "Tue, 31 Mar 2015 00:22:01 +0530") Message-ID: <444mp2avfy.fsf@lowell-desk.lan> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable Cc: freebsd-questions@freebsd.org X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 30 Mar 2015 23:59:22 -0000 Sibananda Sahu 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.