From: Volker Lendecke Date: Sat, 13 Feb 2021 11:49:57 +0000 (+0100) Subject: lib: Make socket options output less chatty X-Git-Tag: tevent-0.11.0~1632 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=15dad4dba8581d8c4acc635c1f654cf15295a5e0;p=thirdparty%2Fsamba.git lib: Make socket options output less chatty All the socket options were a large block in debug output. Put them on one line. Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- diff --git a/lib/util/util_net.c b/lib/util/util_net.c index f97d4d43f3c..5e62fefa146 100644 --- a/lib/util/util_net.c +++ b/lib/util/util_net.c @@ -979,26 +979,48 @@ static const smb_socket_option socket_options[] = { static void print_socket_options(int s) { - int value; - socklen_t vlen = 4; + TALLOC_CTX *frame = NULL; const smb_socket_option *p = &socket_options[0]; + char *str = NULL; - /* wrapped in if statement to prevent streams - * leak in SCO Openserver 5.0 */ - /* reported on samba-technical --jerry */ - if ( DEBUGLEVEL >= 5 ) { - DEBUG(5,("Socket options:\n")); - for (; p->name != NULL; p++) { - if (getsockopt(s, p->level, p->option, - (void *)&value, &vlen) == -1) { - DEBUGADD(5,("\tCould not test socket option %s.\n", - p->name)); - } else { - DEBUGADD(5,("\t%s = %d\n", - p->name,value)); - } + if (DEBUGLEVEL < 5) { + return; + } + + frame = talloc_stackframe(); + + str = talloc_strdup(frame, ""); + if (str == NULL) { + DBG_WARNING("talloc failed\n"); + goto done; + } + + for (; p->name != NULL; p++) { + int ret, val; + socklen_t vlen = sizeof(val); + + ret = getsockopt(s, p->level, p->option, (void *)&val, &vlen); + if (ret == -1) { + DBG_INFO("Could not test socket option %s: %s.\n", + p->name, strerror(errno)); + continue; + } + + str = talloc_asprintf_append_buffer( + str, + "%s%s=%d", + str[0] != '\0' ? ", " : "", + p->name, + val); + if (str == NULL) { + DBG_WARNING("talloc_asprintf_append_buffer failed\n"); + goto done; } } + + DEBUG(5, ("socket options: %s\n", str)); +done: + TALLOC_FREE(frame); } /****************************************************************************