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:
		
				
					committed by
					
						 Corinna Vinschen
						Corinna Vinschen
					
				
			
			
				
	
			
			
			
						parent
						
							138575c9b9
						
					
				
				
					commit
					8e782bbd94
				
			| @@ -68,7 +68,7 @@ adjust_socket_file_mode (mode_t mode) | |||||||
| } | } | ||||||
|  |  | ||||||
| /* cygwin internal: map sockaddr into internet domain address */ | /* cygwin internal: map sockaddr into internet domain address */ | ||||||
| static int | int | ||||||
| get_inet_addr_local (const struct sockaddr *in, int inlen, | get_inet_addr_local (const struct sockaddr *in, int inlen, | ||||||
| 	       struct sockaddr_storage *out, int *outlen, | 	       struct sockaddr_storage *out, int *outlen, | ||||||
| 	       int *type = NULL, int *secret = NULL) | 	       int *type = NULL, int *secret = NULL) | ||||||
|   | |||||||
| @@ -186,12 +186,17 @@ static enum { | |||||||
| static int syslogd_sock = -1; | static int syslogd_sock = -1; | ||||||
| extern "C" int cygwin_socket (int, int, int); | extern "C" int cygwin_socket (int, int, int); | ||||||
| extern "C" int cygwin_connect (int, const struct sockaddr *, 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 | static void | ||||||
| connect_syslogd () | connect_syslogd () | ||||||
| { | { | ||||||
|   int fd; |   int fd; | ||||||
|   struct sockaddr_un sun; |   struct sockaddr_un sun; | ||||||
|  |   struct sockaddr_storage sst; | ||||||
|  |   int len, type; | ||||||
|  |  | ||||||
|   if (syslogd_inited != not_inited && syslogd_sock >= 0) |   if (syslogd_inited != not_inited && syslogd_sock >= 0) | ||||||
|     close (syslogd_sock); |     close (syslogd_sock); | ||||||
| @@ -199,16 +204,14 @@ connect_syslogd () | |||||||
|   syslogd_sock = -1; |   syslogd_sock = -1; | ||||||
|   sun.sun_family = AF_LOCAL; |   sun.sun_family = AF_LOCAL; | ||||||
|   strncpy (sun.sun_path, _PATH_LOG, sizeof sun.sun_path); |   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; |     return; | ||||||
|   if (cygwin_connect (fd, (struct sockaddr *) &sun, sizeof sun) == 0) |   if (cygwin_connect (fd, (struct sockaddr *) &sun, sizeof sun) == 0) | ||||||
|     syslogd_inited = inited_stream; |  | ||||||
|   else |  | ||||||
|     { |     { | ||||||
|       close (fd); |       if (type == SOCK_DGRAM) | ||||||
|       if ((fd = cygwin_socket (AF_LOCAL, SOCK_DGRAM | SOCK_CLOEXEC, 0)) < 0) |  | ||||||
| 	return; |  | ||||||
|       if (cygwin_connect (fd, (struct sockaddr *) &sun, sizeof sun) == 0) |  | ||||||
| 	{ | 	{ | ||||||
| 	  /* | 	  /* | ||||||
| 	   * FIXME | 	   * FIXME | ||||||
| @@ -219,18 +222,10 @@ connect_syslogd () | |||||||
|  |  | ||||||
| 	  /* connect on a dgram socket always succeeds.  We still don't know | 	  /* connect on a dgram socket always succeeds.  We still don't know | ||||||
| 	     if syslogd is actually listening. */ | 	     if syslogd is actually listening. */ | ||||||
| 	  cygheap_fdget cfd (fd); |  | ||||||
| 	  fhandler_socket_local *const fh = (fhandler_socket_local *) |  | ||||||
| 					    cfd->is_socket (); |  | ||||||
| 	  tmp_pathbuf tp; | 	  tmp_pathbuf tp; | ||||||
| 	  PMIB_UDPTABLE tab = (PMIB_UDPTABLE) tp.w_get (); | 	  PMIB_UDPTABLE tab = (PMIB_UDPTABLE) tp.w_get (); | ||||||
| 	  DWORD size = 65536; | 	  DWORD size = 65536; | ||||||
| 	  bool found = false; | 	  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; | 	  struct sockaddr_in *sa = (struct sockaddr_in *) &sst; | ||||||
|  |  | ||||||
| 	  if (GetUdpTable (tab, &size, FALSE) == NO_ERROR) | 	  if (GetUdpTable (tab, &size, FALSE) == NO_ERROR) | ||||||
| @@ -249,10 +244,13 @@ connect_syslogd () | |||||||
| 		  return; | 		  return; | ||||||
| 		} | 		} | ||||||
| 	    } | 	    } | ||||||
| 	  syslogd_inited = inited_dgram; |  | ||||||
| 	} | 	} | ||||||
|       else |       syslogd_inited = type == SOCK_DGRAM ? inited_dgram : inited_stream; | ||||||
| 	close (fd); |     } | ||||||
|  |   else | ||||||
|  |     { | ||||||
|  |       close (fd); | ||||||
|  |       return; | ||||||
|     } |     } | ||||||
|   syslogd_sock = fd; |   syslogd_sock = fd; | ||||||
|   debug_printf ("found /dev/log, fd = %d, type = %s", |   debug_printf ("found /dev/log, fd = %d, type = %s", | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user