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 46
 {
41 47
 	struct msghdr msg;
42 48
 	struct iovec iov[1];
43
-	struct cmsghdr* cmsg;
44 49
 	int ret;
50
+#ifdef HAVE_MSGHDR_MSG_CONTROL
51
+	struct cmsghdr* cmsg;
45 52
 	union {
46 53
 		struct cmsghdr cm;
47 54
 		char control[CMSG_SPACE(sizeof(fd))];
... ...
@@ -50,6 +57,17 @@ int send_fd(int unix_socket, void* data, int data_len, int fd)
50 57
 	msg.msg_control=control_un.control;
51 58
 	msg.msg_controllen=sizeof(control_un.control);
52 59
 	
60
+	cmsg=CMSG_FIRSTHDR(&msg);
61
+	cmsg->cmsg_level = SOL_SOCKET;
62
+	cmsg->cmsg_type = SCM_RIGHTS;
63
+	cmsg->cmsg_len = CMSG_LEN(sizeof(fd));
64
+	*(int*)CMSG_DATA(cmsg)=fd;
65
+	msg.msg_flags=0;
66
+#else
67
+	msg.msg_accrights=(caddr_t) &fd;
68
+	msg.msg_accrightslen=sizeof(fd);
69
+#endif
70
+	
53 71
 	msg.msg_name=0;
54 72
 	msg.msg_namelen=0;
55 73
 	
... ...
@@ -58,12 +76,6 @@ int send_fd(int unix_socket, void* data, int data_len, int fd)
58 76
 	msg.msg_iov=iov;
59 77
 	msg.msg_iovlen=1;
60 78
 	
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 79
 	
68 80
 	ret=sendmsg(unix_socket, &msg, 0);
69 81
 	
... ...
@@ -76,9 +88,10 @@ int receive_fd(int unix_socket, void* data, int data_len, int* fd)
76 88
 {
77 89
 	struct msghdr msg;
78 90
 	struct iovec iov[1];
79
-	struct cmsghdr* cmsg;
80 91
 	int new_fd;
81 92
 	int ret;
93
+#ifdef HAVE_MSGHDR_MSG_CONTROL
94
+	struct cmsghdr* cmsg;
82 95
 	union{
83 96
 		struct cmsghdr cm;
84 97
 		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 99
 	
87 100
 	msg.msg_control=control_un.control;
88 101
 	msg.msg_controllen=sizeof(control_un.control);
102
+#else
103
+	msg.msg_accrights=(caddr_t) &new_fd;
104
+	msg.msg_accrightslen=sizeof(int);
105
+#endif
89 106
 	
90 107
 	msg.msg_name=0;
91 108
 	msg.msg_namelen=0;
... ...
@@ -98,6 +115,7 @@ int receive_fd(int unix_socket, void* data, int data_len, int* fd)
98 115
 	ret=recvmsg(unix_socket, &msg, 0);
99 116
 	if (ret<=0) goto error;
100 117
 	
118
+#ifdef HAVE_MSGHDR_MSG_CONTROL
101 119
 	cmsg=CMSG_FIRSTHDR(&msg);
102 120
 	if ((cmsg!=0) && (cmsg->cmsg_len==CMSG_LEN(sizeof(new_fd)))){
103 121
 		if (cmsg->cmsg_type!= SCM_RIGHTS){
... ...
@@ -117,6 +135,15 @@ int receive_fd(int unix_socket, void* data, int data_len, int* fd)
117 135
 		*fd=-1;
118 136
 		/* it's not really an error */
119 137
 	}
138
+#else
139
+	if (msg.msg_accrightslen==sizeof(int)){
140
+		*fd=new_fd;
141
+	}else{
142
+		LOG(L_ERR, "receive_fd: no descriptor passed, accrightslen=%d\n",
143
+				msg.msg_accrightslen);
144
+		*fd=-1;
145
+	}
146
+#endif
120 147
 	
121 148
 error:
122 149
 	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"