/rusxmms/librcc

To get this branch, use:
bzr branch http://suren.me/webbzr/rusxmms/librcc

« back to all changes in this revision

Viewing changes to external/rccexternal.c

  • Committer: Suren A. Chilingaryan
  • Date: 2005-08-11 01:06:56 UTC
  • Revision ID: Arch-1:ds@dside.dyndns.org--darksoft-2004%librcc--main--0.1--patch-30
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.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#include <stdio.h>
2
2
#include <stdlib.h>
3
3
#include <string.h>
 
4
#include <errno.h>
4
5
 
5
6
#include "../config.h"
6
7
 
24
25
#ifdef HAVE_SYS_UN_H
25
26
# include <sys/un.h>
26
27
#endif /* HAVE_SYS_UN_H */
 
28
#ifdef HAVE_SYS_TIME_H
 
29
# include <sys/time.h>
 
30
#endif /* JAVE_SYS_TIME_H */
 
31
 
 
32
#ifdef HAVE_SIGNAL_H
 
33
# include <signal.h>
 
34
#endif /* HAVE_SIGNAL_H */
27
35
 
28
36
#include <glib/gthread.h>
29
37
 
30
38
#include "../src/rccexternal.h"
31
39
#include "rcclibtranslate.h"
32
40
 
 
41
#define RCC_EXIT_CHECK_TIMEOUT 10 /* seconds */
 
42
 
33
43
 
34
44
int main() {
 
45
#ifdef HAVE_SIGNAL_H
 
46
    struct sigaction act;
 
47
#endif /* HAVE_PWD_H */
 
48
    int err;
 
49
    struct timeval tv;
 
50
    fd_set fdcon;
 
51
 
35
52
    int s, sd;
36
53
    char addr[376];
37
54
    const char *rcc_home_dir;
38
55
    struct sockaddr_un mysock, clisock;
39
56
    socklen_t socksize;
 
57
    
 
58
    pid_t parentpid;
40
59
    pid_t mypid;
41
60
    
42
61
    unsigned char loopflag = 1;
49
68
    struct passwd *pw;
50
69
#endif /* HAVE_PWD_H */
51
70
 
 
71
 
 
72
    parentpid = getppid();    
52
73
    mypid = getpid();
53
74
 
54
75
    rcc_home_dir = getenv ("HOME");
78
99
    mysock.sun_path[sizeof(mysock.sun_path)-1]=0;
79
100
 
80
101
    unlink(addr);
 
102
 
81
103
    if (bind(s,(struct sockaddr*)&mysock,sizeof(mysock))==-1) return -1;
82
104
    if (listen(s,1)<0) {
83
105
        unlink(addr);
84
106
        return -1;
85
107
    }
86
108
 
 
109
#ifdef HAVE_SIGNAL_H
 
110
    act.sa_handler = SIG_IGN;
 
111
    sigemptyset(&act.sa_mask);
 
112
    act.sa_flags = 0;
 
113
    sigaction(SIGPIPE,&act,NULL);
 
114
    sigaction(SIGINT,&act,NULL);
 
115
#endif /* HAVE_SIGNAL_H */
 
116
 
87
117
    while (loopflag) {
 
118
        tv.tv_sec = RCC_EXIT_CHECK_TIMEOUT;
 
119
        tv.tv_usec = 0;
 
120
 
 
121
        FD_ZERO(&fdcon);
 
122
        FD_SET(s, &fdcon);
 
123
        
 
124
        err = select(s+1, &fdcon, NULL, NULL, &tv);
 
125
        if (err<=0) {
 
126
            if (getppid() != parentpid) break;
 
127
            continue;
 
128
        }
 
129
 
88
130
        sd = accept(s,(struct sockaddr*)&clisock,&socksize);
89
131
        if (sd < 0) continue;
90
132