mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Hrvoje Varga <hrvoje.varga@sartura.hr>
To: musl@lists.openwall.com
Subject: [PATCH] add SOCK_STREAM support for syslog
Date: Mon, 21 Aug 2017 12:47:40 +0200	[thread overview]
Message-ID: <20170821104740.10802-1-hrvoje.varga@sartura.hr> (raw)

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.

Signed-off-by: Hrvoje Varga <hrvoje.varga@sartura.hr>
---
 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)
-- 
2.14.1



             reply	other threads:[~2017-08-21 10:47 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-21 10:47 Hrvoje Varga [this message]
2018-04-12 13:04 ` Hrvoje Varga
2018-04-13  0:39   ` Rich Felker
2018-04-13  1:54     ` Laurent Bercot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170821104740.10802-1-hrvoje.varga@sartura.hr \
    --to=hrvoje.varga@sartura.hr \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).