summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/haskell.yml21
-rw-r--r--src/Xmobar/Plugins/Monitors/Uptime.hs14
-rw-r--r--src/Xmobar/Plugins/Monitors/Uptime/FreeBSD.hsc52
-rw-r--r--src/Xmobar/Plugins/Monitors/Uptime/Linux.hs24
-rw-r--r--xmobar.cabal6
5 files changed, 108 insertions, 9 deletions
diff --git a/.github/workflows/haskell.yml b/.github/workflows/haskell.yml
index 6c1fd1f..8b195ab 100644
--- a/.github/workflows/haskell.yml
+++ b/.github/workflows/haskell.yml
@@ -7,7 +7,6 @@ on:
jobs:
build:
-
runs-on: ubuntu-latest
strategy:
matrix:
@@ -55,3 +54,23 @@ jobs:
sh ./travis.sh src
- name: Run tests
run: cabal test
+
+ # build-freebsd:
+ # runs-on: macos-latest
+ # env:
+ # CONFIG: "--enable-tests --enable-benchmarks -fwith_xft -fwith_mpd"
+
+ # steps:
+ # - uses: actions/checkout@v2
+
+ # - name: Install dependencies
+ # uses: vmactions/freebsd-vm@v0.1.5
+ # with:
+ # usesh: true
+ # prepare: pkg install -y ghc hs-hlint xorg-libraries hs-cabal-install git autoconf
+ # run: |
+ # cabal update
+ # cabal build --dependencies-only $CONFIG
+ # cabal build $CONFIG
+ # hlint
+ # cabal test
diff --git a/src/Xmobar/Plugins/Monitors/Uptime.hs b/src/Xmobar/Plugins/Monitors/Uptime.hs
index 235fc85..646edc8 100644
--- a/src/Xmobar/Plugins/Monitors/Uptime.hs
+++ b/src/Xmobar/Plugins/Monitors/Uptime.hs
@@ -1,3 +1,5 @@
+{-#LANGUAGE CPP #-}
+
------------------------------------------------------------------------------
-- |
-- Module : Plugins.Monitors.Uptime
@@ -19,22 +21,22 @@ module Xmobar.Plugins.Monitors.Uptime (uptimeConfig, runUptime) where
import Xmobar.Plugins.Monitors.Common
-import qualified Data.ByteString.Lazy.Char8 as B
+#if defined(freebsd_HOST_OS)
+import qualified Xmobar.Plugins.Monitors.Uptime.FreeBSD as MU
+#else
+import qualified Xmobar.Plugins.Monitors.Uptime.Linux as MU
+#endif
uptimeConfig :: IO MConfig
uptimeConfig = mkMConfig "Up <days>d <hours>h <minutes>m"
["days", "hours", "minutes", "seconds"]
-readUptime :: IO Float
-readUptime =
- fmap (read . B.unpack . head . B.words) (B.readFile "/proc/uptime")
-
secsPerDay :: Integer
secsPerDay = 24 * 3600
uptime :: Monitor [String]
uptime = do
- t <- io readUptime
+ t <- io MU.readUptime
u <- getConfigValue useSuffix
let tsecs = floor t
secs = tsecs `mod` secsPerDay
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 <sys/types.h>
+#include <sys/user.h>
+#include <sys/time.h>
+#include <sys/sysctl.h>
+
+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")
diff --git a/xmobar.cabal b/xmobar.cabal
index 5011a94..dadbe59 100644
--- a/xmobar.cabal
+++ b/xmobar.cabal
@@ -299,13 +299,15 @@ library
Xmobar.Plugins.Monitors.Cpu.FreeBSD,
Xmobar.Plugins.Monitors.Mem.FreeBSD,
Xmobar.Plugins.Monitors.Net.FreeBSD,
- Xmobar.Plugins.Monitors.Swap.FreeBSD
+ Xmobar.Plugins.Monitors.Swap.FreeBSD,
+ Xmobar.Plugins.Monitors.Uptime.FreeBSD
else
other-modules: Xmobar.Plugins.Monitors.Batt.Linux,
Xmobar.Plugins.Monitors.Cpu.Linux,
Xmobar.Plugins.Monitors.Mem.Linux,
Xmobar.Plugins.Monitors.Net.Linux,
- Xmobar.Plugins.Monitors.Swap.Linux
+ Xmobar.Plugins.Monitors.Swap.Linux,
+ Xmobar.Plugins.Monitors.Uptime.Linux
executable xmobar
default-language: Haskell2010