瀏覽代碼

- solaris fixes - ser + tcp compiles now on solaris
(on solaris the msghdr structure is "old style")
=> introduced a new define: HAVE_MSGHDR_MSG_CONTROL

Andrei Pelinescu-Onciul 22 年之前
父節點
當前提交
6c6659cb1a
共有 4 個文件被更改,包括 43 次插入14 次删除
  1. 6 5
      Makefile.defs
  2. 35 8
      pass_fd.c
  3. 1 1
      tcp_main.c
  4. 1 0
      tcp_read.c

+ 6 - 5
Makefile.defs

@@ -8,7 +8,7 @@
 VERSION = 0
 PATCHLEVEL = 8
 SUBLEVEL =   11
-EXTRAVERSION = pre6-tcp6-tm
+EXTRAVERSION = pre6-tcp7-tm
 
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")
@@ -531,7 +531,7 @@ LIBS= -lfl -ldl -lresolv
 #os specific stuff
 ifeq ($(OS), linux)
 	DEFS+=-DHAVE_GETHOSTBYNAME2 -DHAVE_UNION_SEMUN -DHAVE_SCHED_YIELD \
-			-DHAVE_MSG_NOSIGNAL
+			-DHAVE_MSG_NOSIGNAL -DHAVE_MSGHDR_MSG_CONTROL
 	ifneq ($(found_lock_method), yes)
 		DEFS+= -DUSE_SYSV_SEM  # try posix sems
 		found_lock_method=yes
@@ -564,7 +564,7 @@ endif
 
 ifeq ($(OS), freebsd)
 	DEFS+=-DHAVE_SOCKADDR_SA_LEN -DHAVE_GETHOSTBYNAME2 -DHAVE_UNION_SEMUN \
-		-DHAVE_SCHED_YIELD
+		-DHAVE_SCHED_YIELD -DHAVE_MSGHDR_MSG_CONTROL
 	ifneq ($(found_lock_method), yes)
 		DEFS+= -DUSE_PTHREAD_MUTEX  # try pthread sems
 		found_lock_method=yes
@@ -575,7 +575,7 @@ endif
 
 ifeq ($(OS), openbsd)
 	DEFS+=-DHAVE_SOCKADDR_SA_LEN -DDLSYM_PREFIX='"_"' -DHAVE_GETHOSTBYNAME2 \
-		-DHAVE_UNION_SEMUN
+		-DHAVE_UNION_SEMUN -DHAVE_MSGHDR_MSG_CONTROL
 	ifneq ($(found_lock_method), yes)
 		DEFS+= -DUSE_PTHREAD_MUTEX  # try pthread sems
 		found_lock_method=yes
@@ -588,7 +588,8 @@ ifeq ($(OS), openbsd)
 endif
 	
 ifeq ($(OS), netbsd)
-	DEFS+=-DHAVE_SOCKADDR_SA_LEN -DHAVE_GETHOSTBYNAME2 
+	DEFS+=-DHAVE_SOCKADDR_SA_LEN -DHAVE_GETHOSTBYNAME2 \
+		-DHAVE_MSGHDR_MSG_CONTROL
 	ifneq ($(found_lock_method), yes)
 		DEFS+= -DUSE_SYSV_SEM  # try pthread sems
 		found_lock_method=yes

+ 35 - 8
pass_fd.c

@@ -24,6 +24,12 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
+ /*
+  * History:
+  * --------
+  *  2002-11-29  created by andrei
+  *  2003-02-20  added solaris support (! HAVE_MSGHDR_MSG_CONTROL) (andrei)
+  */
 
 #ifdef USE_TCP
 
@@ -40,8 +46,9 @@ int send_fd(int unix_socket, void* data, int data_len, int fd)
 {
 	struct msghdr msg;
 	struct iovec iov[1];
-	struct cmsghdr* cmsg;
 	int ret;
+#ifdef HAVE_MSGHDR_MSG_CONTROL
+	struct cmsghdr* cmsg;
 	union {
 		struct cmsghdr cm;
 		char control[CMSG_SPACE(sizeof(fd))];
@@ -50,6 +57,17 @@ int send_fd(int unix_socket, void* data, int data_len, int fd)
 	msg.msg_control=control_un.control;
 	msg.msg_controllen=sizeof(control_un.control);
 	
+	cmsg=CMSG_FIRSTHDR(&msg);
+	cmsg->cmsg_level = SOL_SOCKET;
+	cmsg->cmsg_type = SCM_RIGHTS;
+	cmsg->cmsg_len = CMSG_LEN(sizeof(fd));
+	*(int*)CMSG_DATA(cmsg)=fd;
+	msg.msg_flags=0;
+#else
+	msg.msg_accrights=(caddr_t) &fd;
+	msg.msg_accrightslen=sizeof(fd);
+#endif
+	
 	msg.msg_name=0;
 	msg.msg_namelen=0;
 	
@@ -58,12 +76,6 @@ int send_fd(int unix_socket, void* data, int data_len, int fd)
 	msg.msg_iov=iov;
 	msg.msg_iovlen=1;
 	
-	cmsg=CMSG_FIRSTHDR(&msg);
-	cmsg->cmsg_level = SOL_SOCKET;
-	cmsg->cmsg_type = SCM_RIGHTS;
-	cmsg->cmsg_len = CMSG_LEN(sizeof(fd));
-	*(int*)CMSG_DATA(cmsg)=fd;
-	msg.msg_flags=0;
 	
 	ret=sendmsg(unix_socket, &msg, 0);
 	
@@ -76,9 +88,10 @@ int receive_fd(int unix_socket, void* data, int data_len, int* fd)
 {
 	struct msghdr msg;
 	struct iovec iov[1];
-	struct cmsghdr* cmsg;
 	int new_fd;
 	int ret;
+#ifdef HAVE_MSGHDR_MSG_CONTROL
+	struct cmsghdr* cmsg;
 	union{
 		struct cmsghdr cm;
 		char control[CMSG_SPACE(sizeof(new_fd))];
@@ -86,6 +99,10 @@ int receive_fd(int unix_socket, void* data, int data_len, int* fd)
 	
 	msg.msg_control=control_un.control;
 	msg.msg_controllen=sizeof(control_un.control);
+#else
+	msg.msg_accrights=(caddr_t) &new_fd;
+	msg.msg_accrightslen=sizeof(int);
+#endif
 	
 	msg.msg_name=0;
 	msg.msg_namelen=0;
@@ -98,6 +115,7 @@ int receive_fd(int unix_socket, void* data, int data_len, int* fd)
 	ret=recvmsg(unix_socket, &msg, 0);
 	if (ret<=0) goto error;
 	
+#ifdef HAVE_MSGHDR_MSG_CONTROL
 	cmsg=CMSG_FIRSTHDR(&msg);
 	if ((cmsg!=0) && (cmsg->cmsg_len==CMSG_LEN(sizeof(new_fd)))){
 		if (cmsg->cmsg_type!= SCM_RIGHTS){
@@ -117,6 +135,15 @@ int receive_fd(int unix_socket, void* data, int data_len, int* fd)
 		*fd=-1;
 		/* it's not really an error */
 	}
+#else
+	if (msg.msg_accrightslen==sizeof(int)){
+		*fd=new_fd;
+	}else{
+		LOG(L_ERR, "receive_fd: no descriptor passed, accrightslen=%d\n",
+				msg.msg_accrightslen);
+		*fd=-1;
+	}
+#endif
 	
 error:
 	return ret;

+ 1 - 1
tcp_main.c

@@ -803,7 +803,7 @@ int tcp_init_children()
 	
 	/* fork children & create the socket pairs*/
 	for(r=0; r<tcp_children_no; r++){
-		if (socketpair(AF_LOCAL, SOCK_STREAM, 0, sockfd)<0){
+		if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockfd)<0){
 			LOG(L_ERR, "ERROR: tcp_main: socketpair failed: %s\n",
 					strerror(errno));
 			goto error;

+ 1 - 0
tcp_read.c

@@ -44,6 +44,7 @@
 #include <sys/socket.h>
 
 #include <unistd.h>
+#include <stdlib.h> /* for abort() */
 
 
 #include "dprint.h"