diff options
Diffstat (limited to 'external')
-rw-r--r-- | external/Makefile.am | 5 | ||||
-rw-r--r-- | external/rccexternal.c | 44 | ||||
-rw-r--r-- | external/rcclibtranslate.c | 4 |
3 files changed, 31 insertions, 22 deletions
diff --git a/external/Makefile.am b/external/Makefile.am index 68d2988..51cbad9 100644 --- a/external/Makefile.am +++ b/external/Makefile.am @@ -6,7 +6,10 @@ bindir = $(pkgdatadir)/ rccexternal_SOURCES= rccexternal.c \ rcclibtranslate.c rcclibtranslate.h \ - ../src/rccdb4.c ../src/rccdb4.h + ../src/rccdb4.c ../src/rccdb4.h \ + ../src/rcchome.c ../src/rcchome.h \ + ../src/rcclock.c ../src/rcclock.h + rccexternal_LDADD= @GLIB2_LIBS@ @LIBTRANSLATE_LIBS@ @BDB_LIBS@ AM_CPPFLAGS = @GLIB2_CFLAGS@ @LIBTRANSLATE_CFLAGS@ @BDB_INCLUDES@ -I../src diff --git a/external/rccexternal.c b/external/rccexternal.c index b09623d..56c9882 100644 --- a/external/rccexternal.c +++ b/external/rccexternal.c @@ -35,12 +35,15 @@ #include <glib/gthread.h> +#include "../src/rcchome.h" #include "../src/rccexternal.h" #include "rcclibtranslate.h" #define RCC_EXIT_CHECK_TIMEOUT 10 /* seconds */ +char rcc_external_offline = 0; + int main() { #ifdef HAVE_SIGNAL_H struct sigaction act; @@ -51,7 +54,6 @@ int main() { int s, sd; char addr[376]; - const char *rcc_home_dir; struct sockaddr_un mysock, clisock; socklen_t socksize; @@ -61,29 +63,16 @@ int main() { unsigned char loopflag = 1; rcc_external_info info; + rcc_external_option option; + unsigned long option_value_long; + ssize_t readed; unsigned char cmd; -#ifdef HAVE_PWD_H - struct passwd *pw; -#endif /* HAVE_PWD_H */ - - parentpid = getppid(); mypid = getpid(); - - rcc_home_dir = getenv ("HOME"); -#ifdef HAVE_PWD_H - if (!rcc_home_dir) { - setpwent (); - pw = getpwuid(getuid ()); - endpwent (); - if ((pw)&&(pw->pw_dir)) rcc_home_dir = pw->pw_dir; - } -#endif /* HAVE_PWD_H */ - if (strlen(rcc_home_dir)>256) return -1; - if (!rcc_home_dir) rcc_home_dir = "/"; - + + rccHomeSet(); rccLibTranslateInit(rcc_home_dir); sprintf(addr,"%s/.rcc/comm/",rcc_home_dir); @@ -140,6 +129,20 @@ int main() { case RCC_EXTERNAL_MODULE_CONTROL: loopflag = 0; break; + case RCC_EXTERNAL_MODULE_OPTIONS: + readed = recv(sd,&option,sizeof(rcc_external_option),0); + if (readed < sizeof(rcc_external_option)) break; + switch(option) { + case RCC_EXTERNAL_OPTION_OFFLINE: + readed = recv (sd, &option_value_long, sizeof(unsigned long), 0); + if (readed < sizeof(unsigned long)) break; + puts("got an offline option"); + rcc_external_offline = option_value_long?1:0; + break; + default: + break; + } + break; case RCC_EXTERNAL_MODULE_LIBRTRANSLATE: info = (rcc_external_info)malloc(sizeof(rcc_external_info_s)); if (info) info->s = sd; @@ -154,6 +157,7 @@ int main() { unlink(addr); rccLibTranslateFree(); - + rccHomeFree(); + return 0; } diff --git a/external/rcclibtranslate.c b/external/rcclibtranslate.c index 24f44a2..c64020c 100644 --- a/external/rcclibtranslate.c +++ b/external/rcclibtranslate.c @@ -35,6 +35,7 @@ static GCond *cond = NULL; static GQueue *queue = NULL; static GThread *thread = NULL; +extern char rcc_external_offline; static char *rccCreateKey(const char *from, const char *to, const char *data, size_t *keysize) { char *res; @@ -78,7 +79,7 @@ static void *rccLibPostponed(void *info) { to[2] = 0; g_mutex_lock(mutex); - while (!exitflag) { + while ((!exitflag)||(rcc_external_offline)) { data = (char*)g_queue_pop_head(queue); if (data) { g_mutex_unlock(mutex); @@ -103,6 +104,7 @@ static void *rccLibPostponed(void *info) { free(data); g_mutex_lock(mutex); } else { + if (exitflag) break; g_cond_wait(cond, mutex); } } |