From owner-freebsd-questions@FreeBSD.ORG Mon Mar 30 18:51:59 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 0E4AC746 for ; Mon, 30 Mar 2015 18:51:59 +0000 (UTC) Received: from mail-wi0-f181.google.com (mail-wi0-f181.google.com [209.85.212.181]) (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 975381BA for ; Mon, 30 Mar 2015 18:51:58 +0000 (UTC) Received: by wicne17 with SMTP id ne17so42111132wic.0 for ; Mon, 30 Mar 2015 11:51:56 -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=TlXl0RTyGPpQxBeFGsCBV+DUmHP+FvUIH9eSU58b0Bs=; b=Bly/17bvwXsuUlMiKB2TCvo3EKJ8cl/z8PRyRNG1rQM4u1iHMS15tOfZLYK8y1qwMu WzO8XYTBRAtsnwsQL7YAWyXaXE5QEFfVZC73vTdPTU/zIhB70uD+meiefOFvGWEs9HPk YlweC2hdYuNhU74qlaZCRrLbf2k0TF227GtGRjYMnuksxE2kyyDQJIP/dndWQRJrVVky WAHoFWwhFZlPCHyBW9Nayb5kOEShihv5FHpr4mIYEmEEXZ06ItGYspdmJdUEf2d1TczA CwEu5ydCpXlceIjd4lx0VgwxJdM2AWiCg7N6naK1cYqPZn6pcvOngg9Jqt6tXbixIUTr pddQ== X-Gm-Message-State: ALoCoQkCcLZLPFsAfG4SCboCnvktnslomN5RDkLyQw2NrTZaXlr36tywp+ZMswT1ZRAoBGz1Xefo X-Received: by 10.180.198.37 with SMTP id iz5mr24400408wic.95.1427741516381; Mon, 30 Mar 2015 11:51:56 -0700 (PDT) From: Sibananda Sahu MIME-Version: 1.0 X-Mailer: Microsoft Outlook 14.0 Thread-Index: AdBrGpon+ZjcttocQRymtQHcx4OxUQ== Date: Tue, 31 Mar 2015 00:22:01 +0530 Message-ID: <0a2b68c0f411b50a276ce00a8d8b15ee@mail.gmail.com> Subject: How to know the system state if the system is going for halt or poweroff or reboot in FreeBSD To: freebsd-questions@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-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 18:51:59 -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