[OpenSIPS-Devel] Improved socket error messages

Bogdan-Andrei Iancu bogdan at opensips.org
Mon Jan 28 15:23:19 CET 2013


Hi Michael,

See an improved version of your patch here on commit #9666 :
     http://opensips.svn.sourceforge.net/opensips/?rev=9666&view=rev

If you consider adding that extra info in other places, please provide a 
patch.

Thanks and regards,

Bogdan-Andrei Iancu
OpenSIPS Founder and Developer
http://www.opensips-solutions.com


On 01/27/2013 09:17 PM, Michael Schloh von Bennewitz wrote:
> Hello developers,
>
> While trying to debug a difficult to find problem (where ntop,
> tcpdump, and snoop were no help) I finally figured out where
> OpenSIPS was trying to send misdirected messages by hacking
> the sources. It might be useful to always accompany log text
> with network stack information. So instead of:
>
>    Jan 02 18:18:02 hostname<error>  opensips[1234]: ERROR:core:tcp_blocking_connect: failed to retrieve SO_ERROR (146) Connection refused
>
> ...we would see:
>
>    Jan 02 18:18:02 hostname<error>  opensips[1234]: ERROR:core:tcp_blocking_connect: addr (1.2.3.4) port (98765), failed to retrieve SO_ERROR (146) Connection refused
>
> ...which of course is much more useful.
>
> To integrate the improvement above, I hacked tcp_main.c like this:
>
>    $ sed -e 's;\(LM_ERR("\)\(failed to retrieve SO_ERROR (%d) %s\\n",\);\1addr (%s) port (%d), \2 inet_ntoa(((struct sockaddr_in *)servaddr)->sin_addr), ntohs(((struct sockaddr_in *)servaddr)->sin_port),;' tcp_main.c
>
> ...or if you prefer here's a unified diff that does the same thing:
>
> diff -Nau tcp_main.c.orig tcp_main.c
> --- tcp_main.c.orig	2012-10-17 00:09:05.000000000 +0200
> +++ tcp_main.c	2013-01-27 16:44:47.803235857 +0100
> @@ -340,7 +340,7 @@
>   			getsockopt(fd, SOL_SOCKET, SO_ERROR,&err,&err_len);
>   			if ((err==0)&&  (poll_err==0)) goto end;
>   			if (err!=EINPROGRESS&&  err!=EALREADY){
> -				LM_ERR("failed to retrieve SO_ERROR (%d) %s\n", err,
> +				LM_ERR("addr (%s) port (%d), failed to retrieve SO_ERROR (%d) %s\n", inet_ntoa(((struct sockaddr_in *)servaddr)->sin_addr), ntohs(((struct sockaddr_in *)servaddr)->sin_port), err,
>   						strerror(err));
>   				goto error;
>   			}
>
> This hack applies cleanly to OpenSIPS 1.7.2 and 1.8.2 although I've
> tested only on 1.7.2 (because of the database access bugs in 1.8.*.)
>
> Unfortunately there are other socket related operations which
> write unhelpful log text, so this is not a complete solution.
>
> Regards,
> Michael
>
> _______________________________________________
> Devel mailing list
> Devel at lists.opensips.org
> http://lists.opensips.org/cgi-bin/mailman/listinfo/devel
>



More information about the Devel mailing list