From c0479f190fd22d7e6a2fa81f9eda2bd79a4b87b6 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Wed, 9 Mar 2011 18:58:14 +0000 Subject: exit whole process is one of the threads terminates diff --git a/nopsyncd/l_pipe.c b/nopsyncd/l_pipe.c index 6f5a17a..5a99809 100644 --- a/nopsyncd/l_pipe.c +++ b/nopsyncd/l_pipe.c @@ -35,11 +35,10 @@ int pipe_init() return pipe(pipefds_); } -int pipe_close() +void pipe_close() { close(pipefds_[0]); close(pipefds_[1]); - return 0; } static int l_pipe_signal(lua_State *L) diff --git a/nopsyncd/l_pipe.h b/nopsyncd/l_pipe.h index b09f33b..b67244b 100644 --- a/nopsyncd/l_pipe.h +++ b/nopsyncd/l_pipe.h @@ -25,7 +25,7 @@ #include int pipe_init(); -int pipe_close(); +void pipe_close(); #define LUA_PIPELIBNAME "pipe" LUALIB_API int luaopen_pipe(lua_State *L); diff --git a/nopsyncd/nopsyncd.c b/nopsyncd/nopsyncd.c index d478b18..f216d1e 100644 --- a/nopsyncd/nopsyncd.c +++ b/nopsyncd/nopsyncd.c @@ -121,6 +121,10 @@ void* main_loop(void* file) printf("%s returned with %d\n", (char*)file, ret); lua_close(L); + + /* this should bring down the other thread as well + at least this is true for the tcp-server thread */ + pipe_close(); pthread_exit(NULL); } @@ -142,6 +146,7 @@ int main(int argc, char* argv[]) fprintf(stderr, "Error creating qlistener thread (code: %d)\n", ret); return 1; } + pthread_detach(qlistener); /* can't kill this thread so don't join to it */ ret = pthread_create(&tcpserver, NULL, main_loop, "tcpserver.lua"); if(ret) { @@ -149,16 +154,10 @@ int main(int argc, char* argv[]) return 1; } - pthread_join(qlistener, NULL); +/* this thread can't be cancelled so don't wait for it */ +/* pthread_join(qlistener, NULL); */ pthread_join(tcpserver, NULL); - ret = pipe_close(); - if(ret) { - fprintf(stderr, "Error destroying pipe: %s\n", strerror(errno)); - return 1; - } - - printf("stopping nopsyncd.\n"); return 0; } diff --git a/nopsyncd/qlistener.lua b/nopsyncd/qlistener.lua index 7594d68..2ebf5be 100755 --- a/nopsyncd/qlistener.lua +++ b/nopsyncd/qlistener.lua @@ -37,6 +37,7 @@ function main_loop() os.exit(2) end + -- TODO: lookup info in Rivendell DB and insert into temporary storage print("received message '" .. msg .. "' with prio: " .. prio) pipe.signal() -- cgit v0.10.2