summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2011-03-09 18:58:14 (GMT)
committerChristian Pointner <equinox@helsinki.at>2011-03-09 18:58:14 (GMT)
commitc0479f190fd22d7e6a2fa81f9eda2bd79a4b87b6 (patch)
tree435d2de991643b72a10d27011e45193e348d840e
parent9f014d5b9735a63da0e7d783f4c67a984140f7ab (diff)
exit whole process is one of the threads terminates
-rw-r--r--nopsyncd/l_pipe.c3
-rw-r--r--nopsyncd/l_pipe.h2
-rw-r--r--nopsyncd/nopsyncd.c15
-rwxr-xr-xnopsyncd/qlistener.lua1
4 files changed, 10 insertions, 11 deletions
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 <lua.h>
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()