diff options
author | Takashi Yano <takashi.yano@nifty.ne.jp> | 2018-07-05 23:46:34 +0900 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2018-07-06 10:41:21 +0200 |
commit | 8e782bbd9499356aa33667e19cb17ab2e6f39ce4 (patch) | |
tree | 3d3ff387f3de00fa9c5140ce31b285523dfdc38a | |
parent | 138575c9b939ea6673447073f89ab9ff773f3cd8 (diff) | |
download | newlib-8e782bbd9499356aa33667e19cb17ab2e6f39ce4.zip newlib-8e782bbd9499356aa33667e19cb17ab2e6f39ce4.tar.gz newlib-8e782bbd9499356aa33667e19cb17ab2e6f39ce4.tar.bz2 |
Fix a problem that connection to syslogd fails.
* fhandler_socket_local.cc (get_inet_addr_local): Change type from
'static int' to 'int' to be callable from syslog.cc.
* syslog.cc (connect_syslogd): Use get_inet_addr_local() instead of
getsockname() to retrieve name information of the syslogd socket.
-rw-r--r-- | winsup/cygwin/fhandler_socket_local.cc | 2 | ||||
-rw-r--r-- | winsup/cygwin/syslog.cc | 34 |
2 files changed, 17 insertions, 19 deletions
diff --git a/winsup/cygwin/fhandler_socket_local.cc b/winsup/cygwin/fhandler_socket_local.cc index 2705ecd..bffb112 100644 --- a/winsup/cygwin/fhandler_socket_local.cc +++ b/winsup/cygwin/fhandler_socket_local.cc @@ -68,7 +68,7 @@ adjust_socket_file_mode (mode_t mode) } /* cygwin internal: map sockaddr into internet domain address */ -static int +int get_inet_addr_local (const struct sockaddr *in, int inlen, struct sockaddr_storage *out, int *outlen, int *type = NULL, int *secret = NULL) diff --git a/winsup/cygwin/syslog.cc b/winsup/cygwin/syslog.cc index 36633a4..6a29550 100644 --- a/winsup/cygwin/syslog.cc +++ b/winsup/cygwin/syslog.cc @@ -186,12 +186,17 @@ static enum { static int syslogd_sock = -1; extern "C" int cygwin_socket (int, int, int); extern "C" int cygwin_connect (int, const struct sockaddr *, int); +extern int get_inet_addr_local (const struct sockaddr *, int, + struct sockaddr_storage *, int *, + int * = NULL, int * = NULL); static void connect_syslogd () { int fd; struct sockaddr_un sun; + struct sockaddr_storage sst; + int len, type; if (syslogd_inited != not_inited && syslogd_sock >= 0) close (syslogd_sock); @@ -199,16 +204,14 @@ connect_syslogd () syslogd_sock = -1; sun.sun_family = AF_LOCAL; strncpy (sun.sun_path, _PATH_LOG, sizeof sun.sun_path); - if ((fd = cygwin_socket (AF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0)) < 0) + if (get_inet_addr_local ((struct sockaddr *) &sun, sizeof sun, + &sst, &len, &type)) + return; + if ((fd = cygwin_socket (AF_LOCAL, type | SOCK_CLOEXEC, 0)) < 0) return; if (cygwin_connect (fd, (struct sockaddr *) &sun, sizeof sun) == 0) - syslogd_inited = inited_stream; - else { - close (fd); - if ((fd = cygwin_socket (AF_LOCAL, SOCK_DGRAM | SOCK_CLOEXEC, 0)) < 0) - return; - if (cygwin_connect (fd, (struct sockaddr *) &sun, sizeof sun) == 0) + if (type == SOCK_DGRAM) { /* * FIXME @@ -219,18 +222,10 @@ connect_syslogd () /* connect on a dgram socket always succeeds. We still don't know if syslogd is actually listening. */ - cygheap_fdget cfd (fd); - fhandler_socket_local *const fh = (fhandler_socket_local *) - cfd->is_socket (); tmp_pathbuf tp; PMIB_UDPTABLE tab = (PMIB_UDPTABLE) tp.w_get (); DWORD size = 65536; bool found = false; - struct sockaddr_storage sst; - int len; - - len = sizeof sst; - ::getsockname (fh->get_socket (), (struct sockaddr *) &sst, &len); struct sockaddr_in *sa = (struct sockaddr_in *) &sst; if (GetUdpTable (tab, &size, FALSE) == NO_ERROR) @@ -249,10 +244,13 @@ connect_syslogd () return; } } - syslogd_inited = inited_dgram; } - else - close (fd); + syslogd_inited = type == SOCK_DGRAM ? inited_dgram : inited_stream; + } + else + { + close (fd); + return; } syslogd_sock = fd; debug_printf ("found /dev/log, fd = %d, type = %s", |