diff --git a/ChangeLog b/ChangeLog index cc485ce..044f2e4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 0.3.2 ===== + 4-Apr-2003: - introduced config option 'silence_log' - this allows + to control how much logging is done to syslog - + logging can even completely be switched off... 1-Apr-2003: - should now be able to deal with an outbound interface that is "temporary" DOWN (dial up internet access) if outbounf IF is down, send back a response to @@ -10,8 +13,12 @@ - rtpproxy: prepared for proper thread termination on exit - introduced short term caching for get_ip_by_ifname - fixed in check for socket() return status + - fixed bug in RTP Proxy (timeout of inactive streams) + that produced a bunch of "ERROR:Error in close(0): Bad file + descriptor" errors each time a RTP stream timed out + - fixed daemonizing (libc5) - now it properly detaches 30-May-2003: - always log ERROR, WARNING and INFO to syslog (also - of not running as daemon) + if not running as daemon) - minor corrections on ERROR printouts 0.3.1 diff --git a/TODO b/TODO index 357a378..1330f75 100644 --- a/TODO +++ b/TODO @@ -1,6 +1,11 @@ TODOs, in random order: ======================= +- siproxd daemonized: looks like clashes between threads +- Daemonizing: daemon() f*** up a following pthread_create +- is select() really tread safe? libc bug? +- lost 200 ACK immediately before RTP starts... + - TERM handler - /var/run PID file diff --git a/doc/siproxd.conf.example b/doc/siproxd.conf.example index b7a3b76..fe6bc72 100644 --- a/doc/siproxd.conf.example +++ b/doc/siproxd.conf.example @@ -48,7 +48,17 @@ sip_listen_port = 5060 ###################################################################### # Shall we daemonize? # -daemonize = 0 +daemonize = 1 + +###################################################################### +# What shall I log to syslog? +# 0 - DEBUGs, INFOs, WARNINGs and ERRORs (this is the default) +# 1 - INFOs, WARNINGs and ERRORs +# 2 - WARNINGs and ERRORs +# 3 - only ERRORs +# 4 - absolutely nothing (be careful - you will have no way to +# see what siproxd is doing - or NOT doing) +silence_log = 0 ###################################################################### # Secure Enviroment settings: diff --git a/src/log.c b/src/log.c index 83c521b..b83dbd2 100644 --- a/src/log.c +++ b/src/log.c @@ -34,8 +34,17 @@ static char const ident[]="$Id: " __FILE__ ": " PACKAGE "-" VERSION "-"\ BUILDSTR " $"; -int log_to_syslog=0; -int debug_pattern=0; +static int log_to_syslog=0; +static int debug_pattern=0; +/* + * What shall I log to syslog? + * 0 - DEBUGs, INFOs, WARNINGs and ERRORs (this is the default) + * 1 - INFOs, WARNINGs and ERRORs + * 2 - WARNINGs and ERRORs + * 3 - only ERRORs + * 4 - absolutely nothing (be careful - you will have no way to + */ +static int silence_level=0; void log_set_pattern(int pattern) { @@ -50,6 +59,11 @@ void log_set_tosyslog(int tosyslog) { log_to_syslog=tosyslog; } +void log_set_silence(int level) { + silence_level=level; +} + + /* for all the LOGGING routines: They should figure out if we are running as a daemon, then write their stuff to syslog or something like that @@ -75,7 +89,7 @@ void log_debug(int class, char *file, int line, const char *format, ...) { tim->tm_min, tim->tm_sec, file, line); vfprintf(stderr, format, ap); fprintf(stderr,"\n"); - } else { + } else if (silence_level < 1) { /* running as daemon - log via SYSLOG facility */ vsnprintf(string, sizeof(string), format, ap); syslog(LOG_USER|LOG_DEBUG, "%s:%i %s", file, line, string); @@ -104,13 +118,11 @@ void log_error(char *file, int line, const char *format, ...) { tim->tm_min, tim->tm_sec, file, line); vfprintf(stderr, format, ap); fprintf(stderr,"\n"); -} -// always log INFO, WARN, ERROR to syslog -// } else { + } else if (silence_level < 4) { /* running as daemon - log via SYSLOG facility */ vsnprintf(string, sizeof(string), format, ap); syslog(LOG_USER|LOG_WARNING, "%s:%i ERROR:%s", file, line, string); -// } + } va_end(ap); fflush(stderr); @@ -135,13 +147,11 @@ void log_warn(char *file, int line, const char *format, ...) { tim->tm_min, tim->tm_sec,file,line); vfprintf(stderr, format, ap); fprintf(stderr,"\n"); -} -// always log INFO, WARN, ERROR to syslog -// } else { + } else if (silence_level < 3) { /* running as daemon - log via SYSLOG facility */ vsnprintf(string, sizeof(string), format, ap); syslog(LOG_USER|LOG_NOTICE, "%s:%i WARNING:%s", file, line, string); -// } + } va_end(ap); fflush(stderr); @@ -166,13 +176,11 @@ void log_info(char *file, int line, const char *format, ...) { tim->tm_min, tim->tm_sec,file,line); vfprintf(stderr, format, ap); fprintf(stderr,"\n"); -} -// always log INFO, WARN, ERROR to syslog -// } else { + } else if (silence_level < 2) { /* running as daemon - log via SYSLOG facility */ vsnprintf(string, sizeof(string), format, ap); syslog(LOG_USER|LOG_NOTICE, "%s:%i INFO:%s", file, line, string); -// } + } va_end(ap); fflush(stderr); @@ -190,11 +198,7 @@ void log_dump_buffer(int class, char *file, int line, if (log_to_syslog) return; fprintf(stderr,"---BUFFER DUMP follows---\n"); -/* - for (i=0;inumber, msg_getcall_id(request)->host); +#endif /* stop the RTP proxying stream */ rtp_stop_fwd(msg_getcall_id(request), 0); } diff --git a/src/readconf.c b/src/readconf.c index 75cf007..8221d8e 100644 --- a/src/readconf.c +++ b/src/readconf.c @@ -130,6 +130,7 @@ static int parse_config (FILE *configfile) { { "debug_level", TYP_INT4, &configuration.debuglevel }, { "sip_listen_port", TYP_INT4, &configuration.sip_listen_port }, { "daemonize", TYP_INT4, &configuration.daemonize }, + { "silence_log", TYP_INT4, &configuration.silence_log }, { "if_inbound", TYP_STRING, &configuration.inbound_if }, { "if_outbound", TYP_STRING, &configuration.outbound_if }, { "rtp_port_low", TYP_INT4, &configuration.rtp_port_low }, diff --git a/src/rtpproxy.c b/src/rtpproxy.c index 5ca7639..d5a41a0 100644 --- a/src/rtpproxy.c +++ b/src/rtpproxy.c @@ -72,8 +72,8 @@ struct { pthread_t rtpproxy_tid=0; /* master fd_set */ -fd_set master_fdset; -int master_fd_max; +static fd_set master_fdset; +static int master_fd_max; /* forward declarations */ void *rtpproxy_main(void *i); @@ -110,8 +110,8 @@ int rtpproxy_init( void ) { DEBUGC(DBCLASS_RTP,"created, sts=%i", sts); #if 0 /* don't detach */ - sts=pthread_detach(rtpproxy_tid); - DEBUGC(DBCLASS_RTP,"detached, sts=%i", sts); +// sts=pthread_detach(rtpproxy_tid); +// DEBUGC(DBCLASS_RTP,"detached, sts=%i", sts); #endif return STS_SUCCESS; @@ -173,8 +173,8 @@ void *rtpproxy_main(void *arg) { } /* for i */ - /* age and clean rtp_proxytable */ - if (t > (last_t+configuration.rtp_timeout) ) { + /* age and clean rtp_proxytable (check every 10 seconds)*/ + if (t > (last_t+10) ) { last_t = t; for (i=0;inumber, callid->host, media_stream_no); +#endif DEBUGC(DBCLASS_RTP,"starting RTP proxy stream for: %s@%s #=%i", callid->number, callid->host, media_stream_no); @@ -393,7 +402,7 @@ int rtp_stop_fwd (call_id_t *callid, int nolock) { int i, sts; int retsts=STS_SUCCESS; int got_match=0; - + if (configuration.rtp_proxy_enable == 0) return STS_SUCCESS; if (callid == NULL) { @@ -401,6 +410,10 @@ int rtp_stop_fwd (call_id_t *callid, int nolock) { return STS_FAILURE; } +#ifdef MODEDEBUG /*&&&&*/ +INFO("stopping RTP proxy stream for: %s@%s", + callid->number, callid->host); +#endif DEBUGC(DBCLASS_RTP,"stopping RTP proxy stream for: %s@%s", callid->number, callid->host); @@ -428,14 +441,18 @@ int rtp_stop_fwd (call_id_t *callid, int nolock) { * media strema active for the same callid (audio + video stream) */ for (i=0; inumber)==0) && + if ((callid->number==NULL) && (callid->host==NULL)) break; + if( rtp_proxytable[i].sock && + (strcmp(rtp_proxytable[i].callid_number, callid->number)==0) && (strcmp(rtp_proxytable[i].callid_host, callid->host)==0) ) { /* match: close socket and clean slot in rtp_proxytable */ sts = close(rtp_proxytable[i].sock); if (sts < 0) { - ERROR("Error in close(%i): %s\n", rtp_proxytable[i].sock, - strerror(errno)); + ERROR("Error in close(%i): %s nolock=%i %s:%s\n", + rtp_proxytable[i].sock, + strerror(errno), nolock, + callid->number, callid->host); } DEBUGC(DBCLASS_RTP,"closing socket %i for RTP stream " diff --git a/src/sip_utils.c b/src/sip_utils.c index 27f6076..1b8030b 100644 --- a/src/sip_utils.c +++ b/src/sip_utils.c @@ -256,9 +256,9 @@ int compare_url(url_t *url1, url_t *url2) { /* Broken(?) MSN messenger - does not supply a user name part. So we simply compare the host part then */ if ((url1->username == NULL) || (url2->username == NULL)) { -// let's be nice to Billy boy and don't complain evey time ;-) +/* let's be nice to Billy boy and don't complain evey time ;-) // WARN("compare_url: NULL username pointer: MSN messenger is known to " -// "trigger this one!"); +// "trigger this one!"); */ DEBUGC(DBCLASS_DNS, "comparing broken urls (no user): " "%s[%s] -> %s[%s]", url1->host, inet_ntoa(addr1), url2->host, inet_ntoa(addr2)); diff --git a/src/siproxd.c b/src/siproxd.c index 8cfeab6..b7f9ca8 100644 --- a/src/siproxd.c +++ b/src/siproxd.c @@ -130,9 +130,6 @@ int main (int argc, char *argv[]) * Init stuff */ - /* cancel RTP thread at exit */ - atexit(rtpproxy_kill); - /* read the config file */ if (read_config(configfile, config_search) == STS_FAILURE) exit(1); @@ -148,6 +145,36 @@ int main (int argc, char *argv[]) /* change user and group IDs */ secure_enviroment(); + /* daemonize if requested to */ + if (configuration.daemonize) { + DEBUGC(DBCLASS_CONFIG,"daemonizing"); +/* daemon() seems to be broken! starting the threads afterwards + with pthread_create will get stuck... */ +#if HAVE_DAEMONxxSICK + if (daemon(1,0) == -1) { + ERROR("unable to daemonize: %s", strerror(errno)); + }; +# else + if (fork()!=0) exit(0); + setsid(); + if (fork()!=0) exit(0); +#endif + log_set_tosyslog(1); + } +#ifdef MODEDEBUG /*&&&&*/ +INFO("daemonizing done (pid=%i)", getpid()); +#endif + + /* initialize the RTP proxy thread */ +#ifdef MODEDEBUG /*&&&&*/ +INFO("b4 rtpproxy_init"); +#endif + atexit(rtpproxy_kill); /* cancel RTP thread at exit */ + rtpproxy_init(); +#ifdef MODEDEBUG /*&&&&*/ +INFO("rtpproxy_init done"); +#endif + /* init the oSIP parser */ parser_init(); @@ -159,30 +186,18 @@ int main (int argc, char *argv[]) if (sts == STS_FAILURE) { /* failure to allocate SIP socket... */ ERROR("unable to bind to SIP listening socket - aborting"); - return 0; + exit(1); } - - /* initialize the RTP proxy thread */ - rtpproxy_init(); - - /* daemonize if requested to */ - if (configuration.daemonize) { - DEBUGC(DBCLASS_CONFIG,"daemonizing"); -#if HAVE_DAEMON - if (daemon(1,0) == -1) { - ERROR("unable to daemonize: %s", strerror(errno)); - }; -# else - - if (fork()!=0) exit(0); - /* close STDIN, STDOUT, STDERR */ - close(0);close(1);close(2); +#ifdef MODEDEBUG /*&&&&*/ +INFO("sipsock_listen done"); #endif - log_set_tosyslog(1); - } - INFO(PACKAGE"-"VERSION"-"BUILDSTR" ("LIBOSIPVER") started"); +/* + * silence the log - if so required... + */ + log_set_silence(configuration.silence_log); + /* * Main loop */ @@ -199,6 +214,12 @@ int main (int argc, char *argv[]) i=sipsock_read(&buff, sizeof(buff), &from); +#ifdef MODEDEBUG /*&&&&*/ +{char tmp[32]; +strncpy(tmp, buff, 30); +tmp[30]='\0'; +INFO("got packet from %s [%s]", inet_ntoa(from.sin_addr), tmp);} +#endif /* evaluate the access lists (IP based filter)*/ access=accesslist_check(from); if (access == 0) continue; /* there are no resources to free */ diff --git a/src/siproxd.h b/src/siproxd.h index 07c2f98..540b736 100644 --- a/src/siproxd.h +++ b/src/siproxd.h @@ -102,7 +102,7 @@ struct urlmap_s { /* - * configuration option table + * Array of strings - used withing configuration store */ #define CFG_STRARR_SIZE 128 typedef struct { @@ -110,12 +110,16 @@ typedef struct { char *string[CFG_STRARR_SIZE]; } stringa_t; +/* + * configuration option table + */ struct siproxd_config { int debuglevel; char *inbound_if; char *outbound_if; int sip_listen_port; int daemonize; + int silence_log; int rtp_port_low; int rtp_port_high; int rtp_timeout; @@ -177,3 +181,5 @@ struct siproxd_config { Port (!!!) are kept from the SIP address given by the user. This issue is fixed in linphone-0.9.1pre1 */ + +//#define MOREDEBUG