From 3736c5f3635863e54ab2cc47860628d26855c749 Mon Sep 17 00:00:00 2001 From: "Suren A. Chilingaryan" Date: Thu, 11 Aug 2005 01:06:56 +0000 Subject: Transliteration and Documentation Update - Fix: Autodetection of dissabled charsets. - Fix: Cleanely terminate external process if parrent thread terminated. - Transliteration for Russian, Ukrainian and using IConv. - Documentation Update. --- external/rccexternal.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'external/rccexternal.c') diff --git a/external/rccexternal.c b/external/rccexternal.c index 47f628a..292ee5d 100644 --- a/external/rccexternal.c +++ b/external/rccexternal.c @@ -1,6 +1,7 @@ #include #include #include +#include #include "../config.h" @@ -24,19 +25,37 @@ #ifdef HAVE_SYS_UN_H # include #endif /* HAVE_SYS_UN_H */ +#ifdef HAVE_SYS_TIME_H +# include +#endif /* JAVE_SYS_TIME_H */ + +#ifdef HAVE_SIGNAL_H +# include +#endif /* HAVE_SIGNAL_H */ #include #include "../src/rccexternal.h" #include "rcclibtranslate.h" +#define RCC_EXIT_CHECK_TIMEOUT 10 /* seconds */ + int main() { +#ifdef HAVE_SIGNAL_H + struct sigaction act; +#endif /* HAVE_PWD_H */ + int err; + struct timeval tv; + fd_set fdcon; + int s, sd; char addr[376]; const char *rcc_home_dir; struct sockaddr_un mysock, clisock; socklen_t socksize; + + pid_t parentpid; pid_t mypid; unsigned char loopflag = 1; @@ -49,6 +68,8 @@ int main() { struct passwd *pw; #endif /* HAVE_PWD_H */ + + parentpid = getppid(); mypid = getpid(); rcc_home_dir = getenv ("HOME"); @@ -78,13 +99,34 @@ int main() { mysock.sun_path[sizeof(mysock.sun_path)-1]=0; unlink(addr); + if (bind(s,(struct sockaddr*)&mysock,sizeof(mysock))==-1) return -1; if (listen(s,1)<0) { unlink(addr); return -1; } +#ifdef HAVE_SIGNAL_H + act.sa_handler = SIG_IGN; + sigemptyset(&act.sa_mask); + act.sa_flags = 0; + sigaction(SIGPIPE,&act,NULL); + sigaction(SIGINT,&act,NULL); +#endif /* HAVE_SIGNAL_H */ + while (loopflag) { + tv.tv_sec = RCC_EXIT_CHECK_TIMEOUT; + tv.tv_usec = 0; + + FD_ZERO(&fdcon); + FD_SET(s, &fdcon); + + err = select(s+1, &fdcon, NULL, NULL, &tv); + if (err<=0) { + if (getppid() != parentpid) break; + continue; + } + sd = accept(s,(struct sockaddr*)&clisock,&socksize); if (sd < 0) continue; -- cgit v1.2.3