summaryrefslogtreecommitdiffstats
path: root/external
diff options
context:
space:
mode:
Diffstat (limited to 'external')
-rw-r--r--external/rccexternal.c42
1 files changed, 42 insertions, 0 deletions
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 <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <errno.h>
#include "../config.h"
@@ -24,19 +25,37 @@
#ifdef HAVE_SYS_UN_H
# include <sys/un.h>
#endif /* HAVE_SYS_UN_H */
+#ifdef HAVE_SYS_TIME_H
+# include <sys/time.h>
+#endif /* JAVE_SYS_TIME_H */
+
+#ifdef HAVE_SIGNAL_H
+# include <signal.h>
+#endif /* HAVE_SIGNAL_H */
#include <glib/gthread.h>
#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;