Browse code

- added tcp init code for the unixsock_server (to be able to send messages over tcp from its processes) - fixed unixsock cmd. line param.

Andrei Pelinescu-Onciul authored on 03/03/2004 09:25:26
Showing 3 changed files
... ...
@@ -45,7 +45,7 @@ export makefile_defs
45 45
 VERSION = 0
46 46
 PATCHLEVEL = 8
47 47
 SUBLEVEL =   13
48
-EXTRAVERSION = -dev-24-unixsock
48
+EXTRAVERSION = -dev-25-unixsock
49 49
 
50 50
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
51 51
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")
... ...
@@ -1146,7 +1146,7 @@ int main(int argc, char** argv)
1146 1146
 #ifdef STATS
1147 1147
 	"s:"
1148 1148
 #endif
1149
-	"f:cp:m:b:l:n:N:rRvdDETVhw:t:u:g:P:i:x";
1149
+	"f:cp:m:b:l:n:N:rRvdDETVhw:t:u:g:P:i:x:";
1150 1150
 	
1151 1151
 	while((c=getopt(argc,argv,options))!=-1){
1152 1152
 		switch(c){
... ...
@@ -1272,8 +1272,8 @@ int main(int argc, char** argv)
1272 1272
 			case 'i':
1273 1273
 					fifo=optarg;
1274 1274
 					break;
1275
-		        case 'x':
1276
-				        unixsock_name=optarg;
1275
+			case 'x':
1276
+					unixsock_name=optarg;
1277 1277
 					break;
1278 1278
 			case '?':
1279 1279
 					if (isprint(optopt))
... ...
@@ -26,6 +26,10 @@
26 26
  * along with this program; if not, write to the Free Software 
27 27
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
28 28
  */
29
+/* History:
30
+ *              created by janakj
31
+ *  2004-03-03  added tcp init code (andrei)
32
+ */
29 33
 
30 34
 #include <unistd.h>
31 35
 #include <errno.h>
... ...
@@ -255,6 +259,10 @@ int init_unixsock_server(void)
255 259
 {
256 260
 	int ret, i;
257 261
 	pid_t pid;
262
+#ifdef USE_TCP
263
+	int sockfd[2];
264
+#endif
265
+	
258 266
 	
259 267
 	ret = create_unix_socket(unixsock_name);
260 268
 	if (ret < 0) {
... ...
@@ -267,6 +275,15 @@ int init_unixsock_server(void)
267 275
 
268 276
 	for(i = 0; i < unixsock_children; i++) {
269 277
 		process_no++;
278
+#ifdef USE_TCP
279
+		if(!tcp_disable){
280
+ 			if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockfd)<0){
281
+				LOG(L_ERR, "ERROR: init_unixsock_server: socketpair"
282
+						" failed: %s\n", strerror(errno));
283
+				return -1;
284
+			}
285
+		}
286
+#endif
270 287
 		pid = fork();
271 288
 		if (pid < 0) {
272 289
 			LOG(L_ERR, "init_unixsock_server: Unable to fork: %s\n",
... ...
@@ -274,6 +291,12 @@ int init_unixsock_server(void)
274 291
 			close(sock);
275 292
 			return -1;
276 293
 		} else if (pid == 0) { /* child */
294
+#ifdef USE_TCP
295
+			if (!tcp_disable){
296
+				close(sockfd[0]);
297
+				unix_tcp_sock=sockfd[1];
298
+			}
299
+#endif
277 300
 			if (init_child(PROC_UNIXSOCK) < 0) {
278 301
 				LOG(L_ERR, "init_unixsock_server: Error in "
279 302
 				    "init_child\n");
... ...
@@ -288,6 +311,15 @@ int init_unixsock_server(void)
288 311
 		pt[process_no].pid = pid;
289 312
 		strncpy(pt[process_no].desc, "unix domain socket server", 
290 313
 			MAX_PT_DESC);
314
+#ifdef USE_TCP
315
+		if (!tcp_disable){
316
+			close(sockfd[1]);
317
+			pt[process_no].unix_sock=sockfd[0];
318
+			pt[process_no].idx=-1; /* this is not a "tcp"
319
+									  process*/
320
+		}
321
+#endif
322
+
291 323
 	}
292 324
 	return 1;
293 325
 }