Changeset 185

Show
Ignore:
Timestamp:
01/15/03 15:13:12 (6 years ago)
Author:
jajcus
Message:

- restart after jabber connection is broken

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/configure.ac

    r168 r185  
    11# Process this file with autoconf to produce a configure script. 
    2 AC_INIT([jabber-gg-transport], [1.2.3], [jajcus@pld.org.pl]) 
     2AC_INIT([jabber-gg-transport], [1.2.4-test1], [jajcus@pld.org.pl]) 
    33AC_CONFIG_SRCDIR([src/ggtrans.h]) 
    44AM_INIT_AUTOMAKE 
  • trunk/jggtrans.xml

    r120 r185  
    134134 <pidfile>/var/lib/jabber/ggtrans.pid</pidfile> 
    135135 
     136 <!-- How long to wait before restart, after jabber server connection is broken 
     137      negative value means, that jggtrans should terminate -->  
     138 <restart_timeout>60</restart_timeout> 
     139 
    136140</jggtrans> 
    137141<!-- 
  • trunk/jggtrans.xml.Pl

    r120 r185  
    141141 <pidfile>/var/lib/jabber/ggtrans.pid</pidfile> 
    142142 
     143 <!-- Ile czekać po przerwaniu połączenia z serwerem jabbera, zanim jggtrans 
     144      się zrestartuje. Wartoś ujemna oznacza, że jggtrans ma w takim przypadku 
     145      przerwać pracę. --> 
     146 <restart_timeout>60</restart_timeout> 
     147  
    143148</jggtrans> 
    144149<!-- 
  • trunk/src/ggtrans.h

    r82 r185  
    1 /* $Id: ggtrans.h,v 1.5 2002/02/02 19:49:54 jajcus Exp $ */ 
     1/* $Id: ggtrans.h,v 1.6 2003/01/15 14:13:12 jajcus Exp $ */ 
    22 
    33/* 
     
    2626 
    2727extern GMainLoop *main_loop; 
     28extern gboolean do_restart; 
    2829 
    2930#endif 
  • trunk/src/jabber.c

    r183 r185  
    1 /* $Id: jabber.c,v 1.17 2003/01/15 08:04:56 jajcus Exp $ */ 
     1/* $Id: jabber.c,v 1.18 2003/01/15 14:13:12 jajcus Exp $ */ 
    22 
    33/* 
     
    182182                }; 
    183183 
     184void jabber_stream_destroyed(struct stream_s *s){ 
     185 
     186        if (s==stream) stream=NULL; 
     187} 
     188 
    184189int jabber_done(){ 
    185190 
     
    192197        g_free(gateway_desc); 
    193198        g_free(gateway_prompt); 
     199        stream_del_destroy_handler(jabber_stream_destroyed); 
    194200        return 0; 
    195201} 
     
    201207xmlnode node; 
    202208 
     209        stream_add_destroy_handler(jabber_stream_destroyed); 
    203210        node=xmlnode_get_tag(config,"service"); 
    204211        if (!node) 
     
    213220                g_error("Jabberd server not found in config file"); 
    214221 
    215         port=config_load_int("connect/port"); 
     222        port=config_load_int("connect/port",0); 
    216223        if (port<=0) 
    217224                g_error("Connect port not found in config file"); 
  • trunk/src/main.c

    r183 r185  
    1 /* $Id: main.c,v 1.23 2003/01/15 08:04:56 jajcus Exp $ */ 
     1/* $Id: main.c,v 1.24 2003/01/15 14:13:12 jajcus Exp $ */ 
    22 
    33/* 
     
    4343static int signal_received=FALSE; 
    4444static gboolean the_end=FALSE; 
     45gboolean do_restart=TRUE; 
     46static int restart_timeout=60; 
    4547static gboolean foreground=TRUE; 
    4648static int debug_level=0; 
     
    9496 
    9597        switch(sig){ 
     98                case SIGHUP: 
     99                        restart_timeout=0; 
     100                        do_restart=TRUE; 
    96101                case SIGINT: 
    97102                case SIGTERM: 
    98103                        the_end=TRUE; 
    99104                        break; 
    100                 case SIGHUP: 
    101105                case SIGPIPE: 
    102106                        signal(sig,signal_handler); 
     
    298302struct group *grp; 
    299303char *user,*group; 
     304char saved_pwd_b[1024],*saved_pwd; 
     305const char *param_d,*param_D; 
     306int restarting=0; 
    300307FILE *f; 
    301308guint lh; 
     
    309316        newgid=0; user=NULL; group=NULL; 
    310317 
     318        saved_pwd=getcwd(saved_pwd_b,1024); 
    311319        opterr=0; 
    312  
    313         while ((c = getopt (argc, argv, "hfd:D:u:g:")) != -1){ 
     320        while ((c = getopt (argc, argv, "Rhfd:D:u:g:")) != -1){ 
    314321                switch(c){ 
     322                        case 'R': 
     323                                restarting=1; 
     324                                break; 
    315325                        case 'h': 
    316326                                usage(argv[0]); 
     
    320330                                break; 
    321331                        case 'd': 
     332                                param_d=optarg; 
    322333                                debug_level=atoi(optarg); 
    323334                                break; 
    324335                        case 'D': 
     336                                param_D=optarg; 
    325337                                gg_debug_level=atoi(optarg); 
    326338                                fg=TRUE; 
     
    366378                if (setuid(pwd->pw_uid)) g_error("Couldn't change user: %s",g_strerror(errno)); 
    367379        } 
    368         else if (uid==0) g_error("Refusing to run with uid=0"); 
     380        else if (uid==0 && !restarting) g_error("Refusing to run with uid=0"); 
    369381 
    370382        if (optind==argc-1) config_file=g_strdup(argv[optind]); 
     
    415427 
    416428        pid_filename=config_load_string("pidfile"); 
    417  
    418         if (pid_filename){ 
     429         
     430        restart_timeout=config_load_int("restart_timeout",restart_timeout); 
     431 
     432        if (pid_filename && !restarting){ 
    419433                f=fopen(pid_filename,"r"); 
    420434                if (f){ 
     
    443457        if (encoding_init()) return 1; 
    444458 
    445         if (!fg) daemonize(); 
     459        if (!fg && !restarting) daemonize(); 
    446460 
    447461        if (log_filename){ 
     
    480494        } 
    481495        xmlnode_free(config); 
     496         
     497        if (do_restart && restart_timeout>=0){ 
     498                fprintf(stderr,"Restarting in %i seconds.\n",restart_timeout); 
     499                if (restart_timeout>0) sleep(restart_timeout); 
     500                if (saved_pwd) chdir(saved_pwd); 
     501                execlp(argv[0],argv[0],"-R","-d",param_d,"-D",param_D,NULL); 
     502                perror("exec"); 
     503                return 1; 
     504        } 
    482505 
    483506        fprintf(stderr,"Exiting normally.\n"); 
  • trunk/src/sessions.c

    r183 r185  
    1 /* $Id: sessions.c,v 1.35 2003/01/15 08:04:56 jajcus Exp $ */ 
     1/* $Id: sessions.c,v 1.36 2003/01/15 14:13:12 jajcus Exp $ */ 
    22 
    33/* 
     
    4343GHashTable *sessions_jid; 
    4444 
     45static void session_stream_destroyed(gpointer key,gpointer value,gpointer user_data){ 
     46Session *s=(Session *)value; 
     47Stream *stream=(Stream *)user_data; 
     48 
     49        if (s->s==stream) s->s=NULL; 
     50} 
     51 
     52static void sessions_stream_destroyed(struct stream_s *stream){ 
     53 
     54        g_hash_table_foreach(sessions_jid,session_stream_destroyed,stream); 
     55} 
     56 
     57 
    4558int sessions_init(){ 
    4659char *proxy_ip; 
     
    5063 
    5164 
     65        stream_add_destroy_handler(sessions_stream_destroyed); 
     66 
    5267        sessions_jid=g_hash_table_new(g_str_hash,g_str_equal); 
    5368        if (!sessions_jid) return -1; 
    5469 
    55         i=config_load_int("conn_timeout"); 
     70        i=config_load_int("conn_timeout",0); 
    5671        if (i>0) conn_timeout=i; 
    57         i=config_load_int("pong_timeout"); 
     72        i=config_load_int("pong_timeout",0); 
    5873        if (i>0) pong_timeout=i; 
    59         i=config_load_int("ping_interval"); 
     74        i=config_load_int("ping_interval",0); 
    6075        if (i>0) ping_interval=i; 
    61         i=config_load_int("reconnect"); 
     76        i=config_load_int("reconnect",0); 
    6277        if (i>0) reconnect=i; 
    6378 
     
    6580        if (p && inet_aton(p,&gg_server)) 
    6681                gg_server_given=1; 
    67         i=config_load_int("gg_port"); 
     82        i=config_load_int("gg_port",0); 
    6883        if (i>0) gg_port=i; 
    6984 
    7085        proxy_ip=config_load_string("proxy/ip"); 
    7186        if (!proxy_ip) return 0; 
    72         port=config_load_int("proxy/port"); 
     87        port=config_load_int("proxy/port",0); 
    7388        if (port<=0) return 0; 
    7489 
     
    97112        g_hash_table_foreach_remove(sessions_jid,sessions_hash_remove_func,NULL); 
    98113        g_hash_table_destroy(sessions_jid); 
     114         
     115        stream_del_destroy_handler(sessions_stream_destroyed); 
     116 
    99117        return 0; 
    100118} 
     
    705723} 
    706724 
     725 
  • trunk/src/sessions.h

    r183 r185  
    1 /* $Id: sessions.h,v 1.13 2003/01/15 08:04:56 jajcus Exp $ */ 
     1/* $Id: sessions.h,v 1.14 2003/01/15 14:13:12 jajcus Exp $ */ 
    22 
    33/* 
     
    8181void session_print(Session *s,int indent); 
    8282void sessions_print_all(int indent); 
     83 
    8384int sessions_init(); 
    8485int sessions_done(); 
  • trunk/src/stream.c

    r183 r185  
    1 /* $Id: stream.c,v 1.13 2003/01/15 08:04:56 jajcus Exp $ */ 
     1/* $Id: stream.c,v 1.14 2003/01/15 14:13:12 jajcus Exp $ */ 
    22 
    33/* 
     
    3535#define MAX_READ_BUF 102400 
    3636 
     37GList* destroy_handlers; 
     38 
    3739int stream_io_error(GIOChannel *source,GIOCondition condition,gpointer data); 
    3840int stream_io_connect(GIOChannel *source,GIOCondition condition,gpointer data); 
     
    163165        else 
    164166                g_critical("Connection to jabber server broken"); 
     167        do_restart=TRUE; 
    165168        return FALSE; 
    166169} 
     
    201204        } 
    202205        err=g_io_channel_read(source,s->read_buf,s->read_buf_len,&br); 
    203         if (err==G_IO_ERROR_INVAL){ 
     206        if (err==G_IO_ERROR_INVAL || br<1){ 
    204207                s->read_watch=0; 
    205208                s->xs->f(XSTREAM_CLOSE,NULL,s); 
     
    313316 
    314317int stream_destroy(Stream *s){ 
     318GList *it; 
    315319 
    316320        g_assert(s!=NULL); 
     321        for(it=destroy_handlers;it;it=it->next){ 
     322                stream_destroy_handler_t h= 
     323                        (stream_destroy_handler_t)it->data;  
     324                h(s); 
     325        } 
    317326        if (!s->closing){ 
    318327                char goodbye[]="</stream:stream>"; 
     
    341350} 
    342351 
     352int stream_add_destroy_handler(stream_destroy_handler_t h){ 
     353         
     354        destroy_handlers=g_list_append(destroy_handlers,h); 
     355} 
     356 
     357int stream_del_destroy_handler(stream_destroy_handler_t h){ 
     358         
     359        destroy_handlers=g_list_remove(destroy_handlers,h); 
     360} 
  • trunk/src/stream.h

    r183 r185  
    1 /* $Id: stream.h,v 1.5 2003/01/15 08:04:56 jajcus Exp $ */ 
     1/* $Id: stream.h,v 1.6 2003/01/15 14:13:12 jajcus Exp $ */ 
    22 
    33/* 
     
    4848int stream_destroy(Stream *s); 
    4949 
     50typedef void (*stream_destroy_handler_t)(Stream *s); 
     51int stream_add_destroy_handler(stream_destroy_handler_t h); 
     52int stream_del_destroy_handler(stream_destroy_handler_t h); 
     53 
    5054#endif