From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/12711 Path: news.gmane.org!.POSTED!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: Re: [PATCH] add SOCK_STREAM support for syslog Date: Thu, 12 Apr 2018 20:39:40 -0400 Message-ID: <20180413003940.GR3094@brightrain.aerifal.cx> References: <20170821104740.10802-1-hrvoje.varga@sartura.hr> <20180412150431.1f754356d4360531017e8560@sartura.hr> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1523579875 3649 195.159.176.226 (13 Apr 2018 00:37:55 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 13 Apr 2018 00:37:55 +0000 (UTC) User-Agent: Mutt/1.5.21 (2010-09-15) To: musl@lists.openwall.com Original-X-From: musl-return-12727-gllmg-musl=m.gmane.org@lists.openwall.com Fri Apr 13 02:37:51 2018 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1f6mis-0000ob-Ki for gllmg-musl@m.gmane.org; Fri, 13 Apr 2018 02:37:50 +0200 Original-Received: (qmail 13683 invoked by uid 550); 13 Apr 2018 00:39:53 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 13628 invoked from network); 13 Apr 2018 00:39:52 -0000 Content-Disposition: inline In-Reply-To: <20180412150431.1f754356d4360531017e8560@sartura.hr> Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:12711 Archived-At: On Thu, Apr 12, 2018 at 03:04:31PM +0200, Hrvoje Varga wrote: > > To be consistent with glibc and uClibc since both glibc and uClibc > > have a support for connecting to SOCK_STREAM socket in case > > when connection to a SOCK_DGRAM is unsuccessful. This patch mimics the > > same behavior. > > > > There was a discussion whether the musl should support the SOCK_STREAM > > on musl mailing list http://www.openwall.com/lists/musl/2015/08/10/1. Yes, and it never really concluded. I think it's probably harmless to support SOCK_STREAM if users want it though. But the patch is probably insufficient. One question I had that never got answered: are SOCK_DGRAM and SOCK_STREAM unix socket addresses mutually exclusive, or can the same name be listening as both types? This affects how we handle certain error cases I think.. > > Signed-off-by: Hrvoje Varga > > --- > > src/misc/syslog.c | 18 ++++++++++++++++-- > > 1 file changed, 16 insertions(+), 2 deletions(-) > > > > diff --git a/src/misc/syslog.c b/src/misc/syslog.c > > index 9dd1ddb5..101847a4 100644 > > --- a/src/misc/syslog.c > > +++ b/src/misc/syslog.c > > @@ -48,8 +48,22 @@ void closelog(void) > > > > static void __openlog() > > { > > - log_fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0); > > - if (log_fd >= 0) connect(log_fd, (void *)&log_addr, sizeof log_addr); > > + int retry = 0; > > + int sock_type = SOCK_DGRAM; > > + while (retry < 2) { > > + retry++; > > + log_fd = socket(AF_UNIX, sock_type|SOCK_CLOEXEC, 0); > > + if (log_fd >= 0) { > > + if (connect(log_fd, (void *)&log_addr, sizeof log_addr) != -1) { > > + return; > > + } > > + if (errno == EPROTOTYPE) { > > + sock_type = SOCK_STREAM; > > + } > > + close(log_fd); > > + log_fd = -1; > > + } > > + } > > } > > > > void openlog(const char *ident, int opt, int facility) This only covers opening, not reconnection on loss, which happens in _vsyslog. The way reconnection would have to be handled for SOCK_STREAM is different and less robust, I think, so we probably can't just replace the existing code but would need a new code path for it. Rich