From 3d469771a549062be70f4e316680dac00a68d1d2 Mon Sep 17 00:00:00 2001 From: Michal Zielonka Date: Fri, 8 Oct 2021 14:42:51 +0200 Subject: try to add build action for freebsd + uptime plugin split --- src/Xmobar/Plugins/Monitors/Uptime/FreeBSD.hsc | 52 ++++++++++++++++++++++++++ src/Xmobar/Plugins/Monitors/Uptime/Linux.hs | 24 ++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 src/Xmobar/Plugins/Monitors/Uptime/FreeBSD.hsc create mode 100644 src/Xmobar/Plugins/Monitors/Uptime/Linux.hs (limited to 'src/Xmobar/Plugins/Monitors/Uptime') diff --git a/src/Xmobar/Plugins/Monitors/Uptime/FreeBSD.hsc b/src/Xmobar/Plugins/Monitors/Uptime/FreeBSD.hsc new file mode 100644 index 0000000..e6323e1 --- /dev/null +++ b/src/Xmobar/Plugins/Monitors/Uptime/FreeBSD.hsc @@ -0,0 +1,52 @@ +------------------------------------------------------------------------------ +-- | +-- Module : Plugins.Monitors.Uptime.FreeBSD +-- Copyright : (c) 2010 Jose Antonio Ortega Ruiz +-- License : BSD3-style (see LICENSE) +-- +-- Maintainer : jao@gnu.org +-- Stability : unstable +-- Portability : unportable +-- Created: Sun Dec 12, 2010 20:26 +-- +-- +-- Uptime +-- +------------------------------------------------------------------------------ + + +module Xmobar.Plugins.Monitors.Uptime.FreeBSD (readUptime) where + +import Data.Time.Clock.POSIX (getPOSIXTime) +import System.BSD.Sysctl +import Data.Int +import Foreign.C +import Foreign.Storable + +#include +#include +#include +#include + +data TimeVal = TimeVal {sec:: CTime} + +instance Storable TimeVal where + sizeOf _ = #{size struct timeval} + alignment _ = alignment (undefined::CTime) + peek ptr = do cSec <- #{peek struct timeval, tv_sec} ptr + return (TimeVal cSec) + poke _ _ = pure () + +now :: IO Int64 +now = do + posix <- getPOSIXTime + return $ round posix + +readUptime :: IO Float +readUptime = do + tv <- sysctlPeek "kern.boottime" :: IO TimeVal + nowSec <- now + return $ fromInteger $ toInteger $ (nowSec - (secInt $ sec tv)) + where + secInt :: CTime -> Int64 + secInt (CTime cSec) = cSec diff --git a/src/Xmobar/Plugins/Monitors/Uptime/Linux.hs b/src/Xmobar/Plugins/Monitors/Uptime/Linux.hs new file mode 100644 index 0000000..46ba1a1 --- /dev/null +++ b/src/Xmobar/Plugins/Monitors/Uptime/Linux.hs @@ -0,0 +1,24 @@ +------------------------------------------------------------------------------ +-- | +-- Module : Plugins.Monitors.Uptime.Linux +-- Copyright : (c) 2010 Jose Antonio Ortega Ruiz +-- License : BSD3-style (see LICENSE) +-- +-- Maintainer : jao@gnu.org +-- Stability : unstable +-- Portability : unportable +-- Created: Sun Dec 12, 2010 20:26 +-- +-- +-- Uptime +-- +------------------------------------------------------------------------------ + + +module Xmobar.Plugins.Monitors.Uptime.Linux (readUptime) where + +import qualified Data.ByteString.Lazy.Char8 as B + +readUptime :: IO Float +readUptime = + fmap (read . B.unpack . head . B.words) (B.readFile "/proc/uptime") -- cgit v1.2.3