Browse code

- 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 authored on 20/02/2003 19:50:31
Showing 4 changed files
... ...
@@ -8,7 +8,7 @@
8 8
 VERSION = 0
9 9
 PATCHLEVEL = 8
10 10
 SUBLEVEL =   11
11
-EXTRAVERSION = pre6-tcp6-tm
11
+EXTRAVERSION = pre6-tcp7-tm
12 12
 
13 13
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
14 14
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")
... ...
@@ -531,7 +531,7 @@ LIBS= -lfl -ldl -lresolv
531 531
 #os specific stuff
532 532
 ifeq ($(OS), linux)
533 533
 	DEFS+=-DHAVE_GETHOSTBYNAME2 -DHAVE_UNION_SEMUN -DHAVE_SCHED_YIELD \
534
-			-DHAVE_MSG_NOSIGNAL
534
+			-DHAVE_MSG_NOSIGNAL -DHAVE_MSGHDR_MSG_CONTROL
535 535
 	ifneq ($(found_lock_method), yes)
536 536
 		DEFS+= -DUSE_SYSV_SEM  # try posix sems
537 537
 		found_lock_method=yes
... ...
@@ -564,7 +564,7 @@ endif
564 564
 
565 565
 ifeq ($(OS), freebsd)
566 566
 	DEFS+=-DHAVE_SOCKADDR_SA_LEN -DHAVE_GETHOSTBYNAME2 -DHAVE_UNION_SEMUN \
567
-		-DHAVE_SCHED_YIELD
567
+		-DHAVE_SCHED_YIELD -DHAVE_MSGHDR_MSG_CONTROL
568 568
 	ifneq ($(found_lock_method), yes)
569 569
 		DEFS+= -DUSE_PTHREAD_MUTEX  # try pthread sems
570 570
 		found_lock_method=yes
... ...
@@ -575,7 +575,7 @@ endif
575 575
 
576 576
 ifeq ($(OS), openbsd)
577 577
 	DEFS+=-DHAVE_SOCKADDR_SA_LEN -DDLSYM_PREFIX='"_"' -DHAVE_GETHOSTBYNAME2 \
578
-		-DHAVE_UNION_SEMUN
578
+		-DHAVE_UNION_SEMUN -DHAVE_MSGHDR_MSG_CONTROL
579 579
 	ifneq ($(found_lock_method), yes)
580 580
 		DEFS+= -DUSE_PTHREAD_MUTEX  # try pthread sems
581 581
 		found_lock_method=yes
... ...
@@ -588,7 +588,8 @@ ifeq ($(OS), openbsd)
588 588
 endif
589 589
 	
590 590
 ifeq ($(OS), netbsd)
591
-	DEFS+=-DHAVE_SOCKADDR_SA_LEN -DHAVE_GETHOSTBYNAME2 
591
+	DEFS+=-DHAVE_SOCKADDR_SA_LEN -DHAVE_GETHOSTBYNAME2 \
592
+		-DHAVE_MSGHDR_MSG_CONTROL
592 593
 	ifneq ($(found_lock_method), yes)
593 594
 		DEFS+= -DUSE_SYSV_SEM  # try pthread sems
594 595
 		found_lock_method=yes
... ...
@@ -24,6 +24,12 @@
24 24
  * along with this program; if not, write to the Free Software
25 25
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26 26
  */
27
+ /*
28
+  * History:
29
+  * --------
30
+  *  2002-11-29  created by andrei
31
+  *  2003-02-20  added solaris support (! HAVE_MSGHDR_MSG_CONTROL) (andrei)
32
+  */
27 33
 
28 34
 #ifdef USE_TCP
29 35
 
... ...
@@ -40,8 +46,9 @@ int send_fd(int unix_socket, void* data, int data_len, int fd)
40 40
 {
41 41
 	struct msghdr msg;
42 42
 	struct iovec iov[1];
43
-	struct cmsghdr* cmsg;
44 43
 	int ret;
44
+#ifdef HAVE_MSGHDR_MSG_CONTROL
45
+	struct cmsghdr* cmsg;
45 46
 	union {
46 47
 		struct cmsghdr cm;
47 48
 		char control[CMSG_SPACE(sizeof(fd))];
... ...
@@ -50,6 +57,17 @@ int send_fd(int unix_socket, void* data, int data_len, int fd)
50 50
 	msg.msg_control=control_un.control;
51 51
 	msg.msg_controllen=sizeof(control_un.control);
52 52
 	
53
+	cmsg=CMSG_FIRSTHDR(&msg);
54
+	cmsg->cmsg_level = SOL_SOCKET;
55
+	cmsg->cmsg_type = SCM_RIGHTS;
56
+	cmsg->cmsg_len = CMSG_LEN(sizeof(fd));
57
+	*(int*)CMSG_DATA(cmsg)=fd;
58
+	msg.msg_flags=0;
59
+#else
60
+	msg.msg_accrights=(caddr_t) &fd;
61
+	msg.msg_accrightslen=sizeof(fd);
62
+#endif
63
+	
53 64
 	msg.msg_name=0;
54 65
 	msg.msg_namelen=0;
55 66
 	
... ...
@@ -58,12 +76,6 @@ int send_fd(int unix_socket, void* data, int data_len, int fd)
58 58
 	msg.msg_iov=iov;
59 59
 	msg.msg_iovlen=1;
60 60
 	
61
-	cmsg=CMSG_FIRSTHDR(&msg);
62
-	cmsg->cmsg_level = SOL_SOCKET;
63
-	cmsg->cmsg_type = SCM_RIGHTS;
64
-	cmsg->cmsg_len = CMSG_LEN(sizeof(fd));
65
-	*(int*)CMSG_DATA(cmsg)=fd;
66
-	msg.msg_flags=0;
67 61
 	
68 62
 	ret=sendmsg(unix_socket, &msg, 0);
69 63
 	
... ...
@@ -76,9 +88,10 @@ int receive_fd(int unix_socket, void* data, int data_len, int* fd)
76 76
 {
77 77
 	struct msghdr msg;
78 78
 	struct iovec iov[1];
79
-	struct cmsghdr* cmsg;
80 79
 	int new_fd;
81 80
 	int ret;
81
+#ifdef HAVE_MSGHDR_MSG_CONTROL
82
+	struct cmsghdr* cmsg;
82 83
 	union{
83 84
 		struct cmsghdr cm;
84 85
 		char control[CMSG_SPACE(sizeof(new_fd))];
... ...
@@ -86,6 +99,10 @@ int receive_fd(int unix_socket, void* data, int data_len, int* fd)
86 86
 	
87 87
 	msg.msg_control=control_un.control;
88 88
 	msg.msg_controllen=sizeof(control_un.control);
89
+#else
90
+	msg.msg_accrights=(caddr_t) &new_fd;
91
+	msg.msg_accrightslen=sizeof(int);
92
+#endif
89 93
 	
90 94
 	msg.msg_name=0;
91 95
 	msg.msg_namelen=0;
... ...
@@ -98,6 +115,7 @@ int receive_fd(int unix_socket, void* data, int data_len, int* fd)
98 98
 	ret=recvmsg(unix_socket, &msg, 0);
99 99
 	if (ret<=0) goto error;
100 100
 	
101
+#ifdef HAVE_MSGHDR_MSG_CONTROL
101 102
 	cmsg=CMSG_FIRSTHDR(&msg);
102 103
 	if ((cmsg!=0) && (cmsg->cmsg_len==CMSG_LEN(sizeof(new_fd)))){
103 104
 		if (cmsg->cmsg_type!= SCM_RIGHTS){
... ...
@@ -117,6 +135,15 @@ int receive_fd(int unix_socket, void* data, int data_len, int* fd)
117 117
 		*fd=-1;
118 118
 		/* it's not really an error */
119 119
 	}
120
+#else
121
+	if (msg.msg_accrightslen==sizeof(int)){
122
+		*fd=new_fd;
123
+	}else{
124
+		LOG(L_ERR, "receive_fd: no descriptor passed, accrightslen=%d\n",
125
+				msg.msg_accrightslen);
126
+		*fd=-1;
127
+	}
128
+#endif
120 129
 	
121 130
 error:
122 131
 	return ret;
... ...
@@ -803,7 +803,7 @@ int tcp_init_children()
803 803
 	
804 804
 	/* fork children & create the socket pairs*/
805 805
 	for(r=0; r<tcp_children_no; r++){
806
-		if (socketpair(AF_LOCAL, SOCK_STREAM, 0, sockfd)<0){
806
+		if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockfd)<0){
807 807
 			LOG(L_ERR, "ERROR: tcp_main: socketpair failed: %s\n",
808 808
 					strerror(errno));
809 809
 			goto error;
... ...
@@ -44,6 +44,7 @@
44 44
 #include <sys/socket.h>
45 45
 
46 46
 #include <unistd.h>
47
+#include <stdlib.h> /* for abort() */
47 48
 
48 49
 
49 50
 #include "dprint.h"