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.
This commit is contained in:
Takashi Yano 2018-07-05 23:46:34 +09:00 committed by Corinna Vinschen
parent 138575c9b9
commit 8e782bbd94
2 changed files with 17 additions and 19 deletions

View File

@ -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)

View File

@ -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;
}
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",