Changeset 185
- Timestamp:
- 01/15/03 15:13:12 (6 years ago)
- Files:
-
- trunk/configure.ac (modified) (1 diff)
- trunk/jggtrans.xml (modified) (1 diff)
- trunk/jggtrans.xml.Pl (modified) (1 diff)
- trunk/src/ggtrans.h (modified) (2 diffs)
- trunk/src/jabber.c (modified) (5 diffs)
- trunk/src/main.c (modified) (10 diffs)
- trunk/src/sessions.c (modified) (6 diffs)
- trunk/src/sessions.h (modified) (2 diffs)
- trunk/src/stream.c (modified) (6 diffs)
- trunk/src/stream.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/configure.ac
r168 r185 1 1 # Process this file with autoconf to produce a configure script. 2 AC_INIT([jabber-gg-transport], [1.2. 3], [jajcus@pld.org.pl])2 AC_INIT([jabber-gg-transport], [1.2.4-test1], [jajcus@pld.org.pl]) 3 3 AC_CONFIG_SRCDIR([src/ggtrans.h]) 4 4 AM_INIT_AUTOMAKE trunk/jggtrans.xml
r120 r185 134 134 <pidfile>/var/lib/jabber/ggtrans.pid</pidfile> 135 135 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 136 140 </jggtrans> 137 141 <!-- trunk/jggtrans.xml.Pl
r120 r185 141 141 <pidfile>/var/lib/jabber/ggtrans.pid</pidfile> 142 142 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 143 148 </jggtrans> 144 149 <!-- trunk/src/ggtrans.h
r82 r185 1 /* $Id: ggtrans.h,v 1. 5 2002/02/02 19:49:54jajcus Exp $ */1 /* $Id: ggtrans.h,v 1.6 2003/01/15 14:13:12 jajcus Exp $ */ 2 2 3 3 /* … … 26 26 27 27 extern GMainLoop *main_loop; 28 extern gboolean do_restart; 28 29 29 30 #endif trunk/src/jabber.c
r183 r185 1 /* $Id: jabber.c,v 1.1 7 2003/01/15 08:04:56jajcus Exp $ */1 /* $Id: jabber.c,v 1.18 2003/01/15 14:13:12 jajcus Exp $ */ 2 2 3 3 /* … … 182 182 }; 183 183 184 void jabber_stream_destroyed(struct stream_s *s){ 185 186 if (s==stream) stream=NULL; 187 } 188 184 189 int jabber_done(){ 185 190 … … 192 197 g_free(gateway_desc); 193 198 g_free(gateway_prompt); 199 stream_del_destroy_handler(jabber_stream_destroyed); 194 200 return 0; 195 201 } … … 201 207 xmlnode node; 202 208 209 stream_add_destroy_handler(jabber_stream_destroyed); 203 210 node=xmlnode_get_tag(config,"service"); 204 211 if (!node) … … 213 220 g_error("Jabberd server not found in config file"); 214 221 215 port=config_load_int("connect/port" );222 port=config_load_int("connect/port",0); 216 223 if (port<=0) 217 224 g_error("Connect port not found in config file"); trunk/src/main.c
r183 r185 1 /* $Id: main.c,v 1.2 3 2003/01/15 08:04:56jajcus Exp $ */1 /* $Id: main.c,v 1.24 2003/01/15 14:13:12 jajcus Exp $ */ 2 2 3 3 /* … … 43 43 static int signal_received=FALSE; 44 44 static gboolean the_end=FALSE; 45 gboolean do_restart=TRUE; 46 static int restart_timeout=60; 45 47 static gboolean foreground=TRUE; 46 48 static int debug_level=0; … … 94 96 95 97 switch(sig){ 98 case SIGHUP: 99 restart_timeout=0; 100 do_restart=TRUE; 96 101 case SIGINT: 97 102 case SIGTERM: 98 103 the_end=TRUE; 99 104 break; 100 case SIGHUP:101 105 case SIGPIPE: 102 106 signal(sig,signal_handler); … … 298 302 struct group *grp; 299 303 char *user,*group; 304 char saved_pwd_b[1024],*saved_pwd; 305 const char *param_d,*param_D; 306 int restarting=0; 300 307 FILE *f; 301 308 guint lh; … … 309 316 newgid=0; user=NULL; group=NULL; 310 317 318 saved_pwd=getcwd(saved_pwd_b,1024); 311 319 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){ 314 321 switch(c){ 322 case 'R': 323 restarting=1; 324 break; 315 325 case 'h': 316 326 usage(argv[0]); … … 320 330 break; 321 331 case 'd': 332 param_d=optarg; 322 333 debug_level=atoi(optarg); 323 334 break; 324 335 case 'D': 336 param_D=optarg; 325 337 gg_debug_level=atoi(optarg); 326 338 fg=TRUE; … … 366 378 if (setuid(pwd->pw_uid)) g_error("Couldn't change user: %s",g_strerror(errno)); 367 379 } 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"); 369 381 370 382 if (optind==argc-1) config_file=g_strdup(argv[optind]); … … 415 427 416 428 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){ 419 433 f=fopen(pid_filename,"r"); 420 434 if (f){ … … 443 457 if (encoding_init()) return 1; 444 458 445 if (!fg ) daemonize();459 if (!fg && !restarting) daemonize(); 446 460 447 461 if (log_filename){ … … 480 494 } 481 495 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 } 482 505 483 506 fprintf(stderr,"Exiting normally.\n"); trunk/src/sessions.c
r183 r185 1 /* $Id: sessions.c,v 1.3 5 2003/01/15 08:04:56jajcus Exp $ */1 /* $Id: sessions.c,v 1.36 2003/01/15 14:13:12 jajcus Exp $ */ 2 2 3 3 /* … … 43 43 GHashTable *sessions_jid; 44 44 45 static void session_stream_destroyed(gpointer key,gpointer value,gpointer user_data){ 46 Session *s=(Session *)value; 47 Stream *stream=(Stream *)user_data; 48 49 if (s->s==stream) s->s=NULL; 50 } 51 52 static void sessions_stream_destroyed(struct stream_s *stream){ 53 54 g_hash_table_foreach(sessions_jid,session_stream_destroyed,stream); 55 } 56 57 45 58 int sessions_init(){ 46 59 char *proxy_ip; … … 50 63 51 64 65 stream_add_destroy_handler(sessions_stream_destroyed); 66 52 67 sessions_jid=g_hash_table_new(g_str_hash,g_str_equal); 53 68 if (!sessions_jid) return -1; 54 69 55 i=config_load_int("conn_timeout" );70 i=config_load_int("conn_timeout",0); 56 71 if (i>0) conn_timeout=i; 57 i=config_load_int("pong_timeout" );72 i=config_load_int("pong_timeout",0); 58 73 if (i>0) pong_timeout=i; 59 i=config_load_int("ping_interval" );74 i=config_load_int("ping_interval",0); 60 75 if (i>0) ping_interval=i; 61 i=config_load_int("reconnect" );76 i=config_load_int("reconnect",0); 62 77 if (i>0) reconnect=i; 63 78 … … 65 80 if (p && inet_aton(p,&gg_server)) 66 81 gg_server_given=1; 67 i=config_load_int("gg_port" );82 i=config_load_int("gg_port",0); 68 83 if (i>0) gg_port=i; 69 84 70 85 proxy_ip=config_load_string("proxy/ip"); 71 86 if (!proxy_ip) return 0; 72 port=config_load_int("proxy/port" );87 port=config_load_int("proxy/port",0); 73 88 if (port<=0) return 0; 74 89 … … 97 112 g_hash_table_foreach_remove(sessions_jid,sessions_hash_remove_func,NULL); 98 113 g_hash_table_destroy(sessions_jid); 114 115 stream_del_destroy_handler(sessions_stream_destroyed); 116 99 117 return 0; 100 118 } … … 705 723 } 706 724 725 trunk/src/sessions.h
r183 r185 1 /* $Id: sessions.h,v 1.1 3 2003/01/15 08:04:56jajcus Exp $ */1 /* $Id: sessions.h,v 1.14 2003/01/15 14:13:12 jajcus Exp $ */ 2 2 3 3 /* … … 81 81 void session_print(Session *s,int indent); 82 82 void sessions_print_all(int indent); 83 83 84 int sessions_init(); 84 85 int sessions_done(); trunk/src/stream.c
r183 r185 1 /* $Id: stream.c,v 1.1 3 2003/01/15 08:04:56jajcus Exp $ */1 /* $Id: stream.c,v 1.14 2003/01/15 14:13:12 jajcus Exp $ */ 2 2 3 3 /* … … 35 35 #define MAX_READ_BUF 102400 36 36 37 GList* destroy_handlers; 38 37 39 int stream_io_error(GIOChannel *source,GIOCondition condition,gpointer data); 38 40 int stream_io_connect(GIOChannel *source,GIOCondition condition,gpointer data); … … 163 165 else 164 166 g_critical("Connection to jabber server broken"); 167 do_restart=TRUE; 165 168 return FALSE; 166 169 } … … 201 204 } 202 205 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){ 204 207 s->read_watch=0; 205 208 s->xs->f(XSTREAM_CLOSE,NULL,s); … … 313 316 314 317 int stream_destroy(Stream *s){ 318 GList *it; 315 319 316 320 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 } 317 326 if (!s->closing){ 318 327 char goodbye[]="</stream:stream>"; … … 341 350 } 342 351 352 int stream_add_destroy_handler(stream_destroy_handler_t h){ 353 354 destroy_handlers=g_list_append(destroy_handlers,h); 355 } 356 357 int 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:56jajcus Exp $ */1 /* $Id: stream.h,v 1.6 2003/01/15 14:13:12 jajcus Exp $ */ 2 2 3 3 /* … … 48 48 int stream_destroy(Stream *s); 49 49 50 typedef void (*stream_destroy_handler_t)(Stream *s); 51 int stream_add_destroy_handler(stream_destroy_handler_t h); 52 int stream_del_destroy_handler(stream_destroy_handler_t h); 53 50 54 #endif
