diff options
author | joe <joe@jerkface.net> | 2013-06-17 18:03:50 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2013-06-17 18:03:50 -0400 |
commit | 7e8af335398be37523ff19244225b84d48e027ff (patch) | |
tree | a934d4e9230432480a392c0ef56d1b47bdb94118 /Presence | |
parent | 6f87525d0b6c6ce3ae397b84bc237de92c805b33 (diff) |
cleaner debug output
Diffstat (limited to 'Presence')
-rw-r--r-- | Presence/Server.hs | 18 | ||||
-rw-r--r-- | Presence/main.hs | 19 | ||||
-rw-r--r-- | Presence/monitortty.c | 10 |
3 files changed, 30 insertions, 17 deletions
diff --git a/Presence/Server.hs b/Presence/Server.hs index adc3de84..deab779b 100644 --- a/Presence/Server.hs +++ b/Presence/Server.hs | |||
@@ -24,6 +24,8 @@ import Control.Exception (handle,SomeException(..)) | |||
24 | import Data.HList | 24 | import Data.HList |
25 | import Data.HList.TypeEqGeneric1() | 25 | import Data.HList.TypeEqGeneric1() |
26 | import Data.HList.TypeCastGeneric1() | 26 | import Data.HList.TypeCastGeneric1() |
27 | import System.IO.Error | ||
28 | import ByteStringOperators | ||
27 | 29 | ||
28 | 30 | ||
29 | newtype ConnId = ConnId Int | 31 | newtype ConnId = ConnId Int |
@@ -50,9 +52,6 @@ doServer port g startCon = runServer2 port (runConn2 g) | |||
50 | hSetBuffering h NoBuffering | 52 | hSetBuffering h NoBuffering |
51 | st'' <- startCon sock (h .*. st) | 53 | st'' <- startCon sock (h .*. st) |
52 | let doException (SomeException e) = Prelude.putStrLn ("\n\nexception: " ++ show e ++ "\n\n") | 54 | let doException (SomeException e) = Prelude.putStrLn ("\n\nexception: " ++ show e ++ "\n\n") |
53 | handle doException $ do | ||
54 | -- PEER CRED: (0,4294967295,4294967295) | ||
55 | -- PEER NAME: 127.0.0.1:37253 | ||
56 | handle doException $ fix $ \loop -> do | 55 | handle doException $ fix $ \loop -> do |
57 | let continue () = hIsEOF h >>= flip when loop . not | 56 | let continue () = hIsEOF h >>= flip when loop . not |
58 | packet <- getPacket h | 57 | packet <- getPacket h |
@@ -73,12 +72,19 @@ doServer port g startCon = runServer2 port (runConn2 g) | |||
73 | listen sock 2 | 72 | listen sock 2 |
74 | forkIO $ do | 73 | forkIO $ do |
75 | mainLoop sock (ConnId 0) go | 74 | mainLoop sock (ConnId 0) go |
76 | L.putStrLn $ "quit accept loop" | 75 | -- L.putStrLn $ "quit accept loop" |
77 | return sock | 76 | return sock |
78 | where | 77 | where |
79 | mainLoop sock idnum@(ConnId n) go = do | 78 | mainLoop sock idnum@(ConnId n) go = do |
80 | let doException (SomeException e) = do | 79 | let doException ioerror = do |
81 | Prelude.putStrLn ("\n\naccept-loop exception: " ++ show e ++ "\n\n") | 80 | let typ = ioeGetErrorType ioerror |
81 | if -- typ == InvalidArgument | ||
82 | -- but the symbol is not exported :/ | ||
83 | bshow typ=="invalid argument" | ||
84 | then do | ||
85 | L.putStrLn $ "quit accept-loop." | ||
86 | else do | ||
87 | L.putStrLn ("accept-loop exception: " <++> bshow ioerror <++> "\n") | ||
82 | return Nothing | 88 | return Nothing |
83 | mcon <- handle doException $ fix $ \loop -> do | 89 | mcon <- handle doException $ fix $ \loop -> do |
84 | con <- accept sock | 90 | con <- accept sock |
diff --git a/Presence/main.hs b/Presence/main.hs index dd6bfb2e..36796b6e 100644 --- a/Presence/main.hs +++ b/Presence/main.hs | |||
@@ -30,7 +30,7 @@ import Control.Exception | |||
30 | import LocalPeerCred | 30 | import LocalPeerCred |
31 | import System.Posix.User | 31 | import System.Posix.User |
32 | import qualified Data.Set as Set | 32 | import qualified Data.Set as Set |
33 | import Data.Set (Set) | 33 | import Data.Set as Set (Set,(\\)) |
34 | 34 | ||
35 | import ByteStringOperators | 35 | import ByteStringOperators |
36 | import qualified Data.ByteString.Lazy.Char8 as L | 36 | import qualified Data.ByteString.Lazy.Char8 as L |
@@ -48,15 +48,21 @@ toJabberId host (user,tty,_) = | |||
48 | 48 | ||
49 | track_login :: IORef (Set L.ByteString) -> t -> IO () | 49 | track_login :: IORef (Set L.ByteString) -> t -> IO () |
50 | track_login tracked e = do | 50 | track_login tracked e = do |
51 | -- print e | ||
52 | putStrLn "---" | ||
53 | #ifndef NOUTMP | 51 | #ifndef NOUTMP |
54 | us <- users | 52 | us <- users |
55 | #else | 53 | #else |
56 | let us = [] | 54 | let us = [] |
57 | #endif | 55 | #endif |
58 | let ids = mapMaybe (toJabberId "localhost") us | 56 | let ids = Set.fromList $ mapMaybe (toJabberId "localhost") us |
59 | forM_ ids L.putStrLn | 57 | -- forM_ ids L.putStrLn |
58 | state <- readIORef tracked | ||
59 | let arrivals = ids \\ state | ||
60 | departures = state \\ ids | ||
61 | forM_ (Set.toList departures) $ \id -> do | ||
62 | putStrLn $ id <++> " logged out." | ||
63 | forM_ (Set.toList arrivals) $ \id -> do | ||
64 | putStrLn $ id <++> " logged in." | ||
65 | writeIORef tracked ids | ||
60 | 66 | ||
61 | data UnixSession = UnixSession { | 67 | data UnixSession = UnixSession { |
62 | unix_uid :: (IORef (Maybe UserID)), | 68 | unix_uid :: (IORef (Maybe UserID)), |
@@ -101,19 +107,18 @@ start = do | |||
101 | tracked <- newIORef Set.empty | 107 | tracked <- newIORef Set.empty |
102 | let dologin e = track_login tracked e | 108 | let dologin e = track_login tracked e |
103 | dologin :: t -> IO () | 109 | dologin :: t -> IO () |
110 | dologin () | ||
104 | #ifndef NOUTMP | 111 | #ifndef NOUTMP |
105 | installHandler sigUSR1 (Catch (dologin (userError "signaled"))) Nothing | 112 | installHandler sigUSR1 (Catch (dologin (userError "signaled"))) Nothing |
106 | #endif | 113 | #endif |
107 | -- installHandler sigTERM (CatchOnce (dologin (userError "term signaled"))) Nothing | 114 | -- installHandler sigTERM (CatchOnce (dologin (userError "term signaled"))) Nothing |
108 | inotify <- initINotify | 115 | inotify <- initINotify |
109 | print inotify | ||
110 | #ifndef NOUTMP | 116 | #ifndef NOUTMP |
111 | wd <- addWatch | 117 | wd <- addWatch |
112 | inotify | 118 | inotify |
113 | [CloseWrite] -- [Open,Close,Access,Modify,Move] | 119 | [CloseWrite] -- [Open,Close,Access,Modify,Move] |
114 | utmp_file | 120 | utmp_file |
115 | dologin | 121 | dologin |
116 | print wd | ||
117 | #endif | 122 | #endif |
118 | mtty <- monitorTTY on_chvt | 123 | mtty <- monitorTTY on_chvt |
119 | sock <- listenForXmppClients UnixSessions 5222 HNil | 124 | sock <- listenForXmppClients UnixSessions 5222 HNil |
diff --git a/Presence/monitortty.c b/Presence/monitortty.c index 7b5dc82c..675abe5c 100644 --- a/Presence/monitortty.c +++ b/Presence/monitortty.c | |||
@@ -110,7 +110,7 @@ int tty = -1; | |||
110 | 110 | ||
111 | void *write_vtch(void *pfd) { | 111 | void *write_vtch(void *pfd) { |
112 | int fd = (int)(intptr_t)pfd; | 112 | int fd = (int)(intptr_t)pfd; |
113 | printf("START write_vtch fd=%i\n",fd); | 113 | printf("started VT_WAITEVENT loop fd=%i\n",fd); |
114 | pthread_mutex_lock(&mu); | 114 | pthread_mutex_lock(&mu); |
115 | tty = ttyfd(); | 115 | tty = ttyfd(); |
116 | pthread_mutex_unlock(&mu); | 116 | pthread_mutex_unlock(&mu); |
@@ -131,6 +131,7 @@ void *write_vtch(void *pfd) { | |||
131 | } | 131 | } |
132 | do { | 132 | do { |
133 | vt_wait(tty); | 133 | vt_wait(tty); |
134 | // printf("vt_wait() finished. tty=%d fd=%d\n",tty,fd); | ||
134 | active_tty = get_active(tty); | 135 | active_tty = get_active(tty); |
135 | } while (active_tty==reported_tty); | 136 | } while (active_tty==reported_tty); |
136 | } | 137 | } |
@@ -138,7 +139,7 @@ void *write_vtch(void *pfd) { | |||
138 | // TODO: | 139 | // TODO: |
139 | // use VT_GETSTATE | 140 | // use VT_GETSTATE |
140 | // use VT_WAITEVENT | 141 | // use VT_WAITEVENT |
141 | printf("QUIT write_vtch\n"); | 142 | printf("stopped VT_WAITEVENT loop\n"); |
142 | tty = -1; | 143 | tty = -1; |
143 | pthread_mutex_destroy(&mu); | 144 | pthread_mutex_destroy(&mu); |
144 | return NULL; | 145 | return NULL; |
@@ -147,7 +148,7 @@ void *write_vtch(void *pfd) { | |||
147 | 148 | ||
148 | void monitorTTY(int fd) { | 149 | void monitorTTY(int fd) { |
149 | pthread_mutex_init(&mu,NULL); | 150 | pthread_mutex_init(&mu,NULL); |
150 | printf ("Hello world.\n"); | 151 | // printf ("Hello world.\n"); |
151 | pthread_create (&mt, NULL, write_vtch, (void*)(intptr_t)fd); | 152 | pthread_create (&mt, NULL, write_vtch, (void*)(intptr_t)fd); |
152 | } | 153 | } |
153 | 154 | ||
@@ -158,8 +159,9 @@ void closeTTY() { | |||
158 | active = get_active(tty); | 159 | active = get_active(tty); |
159 | fd = tty; | 160 | fd = tty; |
160 | pthread_mutex_unlock(&mu); | 161 | pthread_mutex_unlock(&mu); |
161 | pthread_cancel(mt); | 162 | // pthread_cancel(mt); |
162 | char cmd[40]; cmd[39] = '\0'; | 163 | char cmd[40]; cmd[39] = '\0'; |
164 | // Hack to wake up from VT_WAITEVENT ioctl | ||
163 | snprintf(cmd,39,"chvt %i;chvt %i",active+1,active); | 165 | snprintf(cmd,39,"chvt %i;chvt %i",active+1,active); |
164 | system(cmd); | 166 | system(cmd); |
165 | pthread_join(mt,NULL); | 167 | pthread_join(mt,NULL); |