From owner-freebsd-bugs@FreeBSD.ORG Wed Mar 25 20:24:49 2015 Return-Path: Delivered-To: freebsd-bugs@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 AB514AA9 for ; Wed, 25 Mar 2015 20:24:49 +0000 (UTC) Received: from mail-wi0-f173.google.com (mail-wi0-f173.google.com [209.85.212.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 47B8FD88 for ; Wed, 25 Mar 2015 20:24:48 +0000 (UTC) Received: by wibgn9 with SMTP id gn9so56127058wib.1 for ; Wed, 25 Mar 2015 13:24:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:mime-version:thread-index:date:message-id :subject:to:content-type; bh=qp6MaJnlE3+qf+4d1cPkQ0OkRAYe82PrIgFpZs+pl1k=; b=IK9n6CmhxWP/tRjtR2BG+9S8aRZSEWdwJW4uCGsM/Fo3NgDTa5a5hMjnCreA4b2SMv GOTNz9RN4TtFQmS1UgV8O/f/6pw0ossj5z+o7oHRP/Cg1SY2VbgflodLTvYCGLKkzRON 8e86CmMNEtRJ+RaqUjHczP5Xe7j+NQsmwtcsp1aQ9MmrPNDUxbL/cAey1ZzEz61qdx3/ nf0cXOVesfwM8QnJnskF29L1Qz/hfSo8ef5FPzer5ko+MvT4/FNF+oqUKzMCk3urHFrQ 4/S1l6Nwo+ksATIzfV6qA/o2JFDas0w6PkIk/eSTXt0uPHBle12KIrA4MT/6iCOo6Kki f2PA== X-Gm-Message-State: ALoCoQn3upQy9NkHWZ4IrhKTKtPWuw7p2mmNw+f4IHvFi09/lK7BNHZJFnzHUN+WESm0rfyppB6Q X-Received: by 10.180.219.102 with SMTP id pn6mr40343582wic.50.1427315087269; Wed, 25 Mar 2015 13:24:47 -0700 (PDT) From: Sibananda Sahu MIME-Version: 1.0 X-Mailer: Microsoft Outlook 14.0 Thread-Index: AdBnObpm90nfoYHoSI+IAig7U+/Fpw== Date: Thu, 26 Mar 2015 01:54:45 +0530 Message-ID: Subject: How to know the system state if the system is going for halt or poweroff or reboot in FreeBSD To: freebsd-acpi@freebsd.org, freebsd-bugs@freebsd.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.18-1 X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 25 Mar 2015 20:24:49 -0000 Hi All, 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 =E2=80=93h now, shutdown =E2=80=93p 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 =E2=80=9Crebooting=E2=80=9D global variable used in= side kern_reboot() function is set only while rebooting the system but after some exercises I realized that the global variable =E2=80=9Crebooting=E2=80= =9D 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 =E2=80=9Chowto=E2=80=9D variable tha= t is passed to the kern_reboot() function call, but this variable is local to kern_reboot() only. SO IS THERE ANY OTHER WAY TO GET THE SYSTEM STATE IN FREEBSD??? Thanks, _Sibananda Sahu