summaryrefslogtreecommitdiff
path: root/Presence/UTmp.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Presence/UTmp.hs')
-rw-r--r--Presence/UTmp.hs8
1 files changed, 6 insertions, 2 deletions
diff --git a/Presence/UTmp.hs b/Presence/UTmp.hs
index c2549a88..481612e3 100644
--- a/Presence/UTmp.hs
+++ b/Presence/UTmp.hs
@@ -1,9 +1,9 @@
1
2{-# LANGUAGE TemplateHaskell #-} 1{-# LANGUAGE TemplateHaskell #-}
3module UTmp (users, utmp_file) where 2module UTmp (users, utmp_file) where
4 3
5import qualified Data.ByteString as S 4import qualified Data.ByteString as S
6import qualified Data.ByteString.Char8 as C 5import qualified Data.ByteString.Char8 as C
6import qualified Data.ByteString.Lazy.Char8 as L
7import Data.BitSyntax 7import Data.BitSyntax
8import Data.Functor.Identity 8import Data.Functor.Identity
9import Data.Maybe 9import Data.Maybe
@@ -80,11 +80,15 @@ processAlive pid = do
80 catchError (do { signalProcess nullSignal pid ; return True }) 80 catchError (do { signalProcess nullSignal pid ; return True })
81 $ \e -> do { return (not ( isDoesNotExistError e)); } 81 $ \e -> do { return (not ( isDoesNotExistError e)); }
82 82
83type UserName = L.ByteString
84type Tty = L.ByteString
85
86users :: IO [(UserName, Tty, ProcessID)]
83users = do 87users = do
84 us <- utmp 88 us <- utmp
85 let us' = map interp_utmp_record us 89 let us' = map interp_utmp_record us
86 us'' = mapMaybe user_proc us' 90 us'' = mapMaybe user_proc us'
87 user_proc (u,tty,pid,USER_PROCESS) = Just (u,tty,pid) 91 user_proc (u,tty,pid,USER_PROCESS) = Just (L.pack u,L.pack tty,pid)
88 user_proc _ = Nothing 92 user_proc _ = Nothing
89 onThrd f (_,_,pid) = f pid 93 onThrd f (_,_,pid) = f pid
90 us3 <- filterM (onThrd processAlive) us'' 94 us3 <- filterM (onThrd processAlive) us''