summaryrefslogtreecommitdiff
path: root/nopsyncd/nopsyncd.c
diff options
context:
space:
mode:
Diffstat (limited to 'nopsyncd/nopsyncd.c')
-rw-r--r--nopsyncd/nopsyncd.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/nopsyncd/nopsyncd.c b/nopsyncd/nopsyncd.c
index b8907ee..d478b18 100644
--- a/nopsyncd/nopsyncd.c
+++ b/nopsyncd/nopsyncd.c
@@ -22,12 +22,15 @@
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
+#include <string.h>
#include <pthread.h>
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
+#include "l_pipe.h"
+
#define LUA_MAIN_LOOP_FUNC "main_loop"
static const luaL_Reg nopsyncd_lualibs[] = {
@@ -36,6 +39,7 @@ static const luaL_Reg nopsyncd_lualibs[] = {
{LUA_TABLIBNAME, luaopen_table},
{LUA_STRLIBNAME, luaopen_string},
{LUA_MATHLIBNAME, luaopen_math},
+ {LUA_MATHLIBNAME, luaopen_pipe},
{NULL, NULL}
};
@@ -114,6 +118,8 @@ void* main_loop(void* file)
if(!ret)
ret = call_main_loop(L, (char*)file);
+ printf("%s returned with %d\n", (char*)file, ret);
+
lua_close(L);
pthread_exit(NULL);
@@ -125,7 +131,13 @@ int main(int argc, char* argv[])
pthread_t qlistener, tcpserver;
- int ret = pthread_create(&qlistener, NULL, main_loop, "qlistener.lua");
+ int ret = pipe_init();
+ if(ret) {
+ fprintf(stderr, "Error creating pipe: %s\n", strerror(errno));
+ return 1;
+ }
+
+ ret = pthread_create(&qlistener, NULL, main_loop, "qlistener.lua");
if(ret) {
fprintf(stderr, "Error creating qlistener thread (code: %d)\n", ret);
return 1;
@@ -140,6 +152,13 @@ int main(int argc, char* argv[])
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;
}