summaryrefslogtreecommitdiff
path: root/Presence/UTmp.hs
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2013-06-17 16:19:15 -0400
committerjoe <joe@jerkface.net>2013-06-17 16:19:15 -0400
commit7adaccbf993c602f09b2b9e7dea0360ac0dce93e (patch)
tree6c4b3aaa4c551ae8d8b897725d0cb5791836878c /Presence/UTmp.hs
parent5982df9112b7e5fe7bcab62434771f1ca979e14d (diff)
Switched UTmp.users to return ByteStrings instead of Strings.
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''