Browse code

UNIX Domain socket server, it allows more flexible communication between ser and SEMS or AA than the FIFO interface.

New variables in the script:
unix_sock -- It should be set to the name of the socket
unix_sock_children -- number of processes that will be listening on the socket.

Jan Janak authored on 02/03/2004 15:19:47
Showing 5 changed files
... ...
@@ -174,6 +174,8 @@ FIFO fifo
174 174
 FIFO_DIR  fifo_dir
175 175
 FIFO_MODE fifo_mode
176 176
 FIFO_DB_URL fifo_db_url
177
+UNIX_SOCK unix_sock
178
+UNIX_SOCK_CHILDREN unix_sock_children
177 179
 AVP_DB_URL  avp_db_url
178 180
 SERVER_SIGNATURE server_signature
179 181
 REPLY_TO_VIA reply_to_via
... ...
@@ -366,6 +368,8 @@ EAT_ABLE	[\ \t\b\r]
366 368
 <INITIAL>{FIFO_DIR}	{ count(); yylval.strval=yytext; return FIFO_DIR; }
367 369
 <INITIAL>{FIFO_DB_URL}	{ count(); yylval.strval=yytext; return FIFO_DB_URL; }
368 370
 <INITIAL>{FIFO_MODE}	{ count(); yylval.strval=yytext; return FIFO_MODE; }
371
+<INITIAL>{UNIX_SOCK} { count(); yylval.strval=yytext; return UNIX_SOCK; }
372
+<INITIAL>{UNIX_SOCK_CHILDREN} { count(); yylval.strval=yytext; return UNIX_SOCK_CHILDREN; }
369 373
 <INITIAL>{AVP_DB_URL}	{ count(); yylval.strval=yytext; return AVP_DB_URL; }
370 374
 <INITIAL>{SERVER_SIGNATURE}	{ count(); yylval.strval=yytext; return SERVER_SIGNATURE; }
371 375
 <INITIAL>{REPLY_TO_VIA}	{ count(); yylval.strval=yytext; return REPLY_TO_VIA; }
... ...
@@ -199,6 +199,8 @@ static struct id_list* mk_listen_id(char*, int, int);
199 199
 %token FIFO_DIR
200 200
 %token FIFO_MODE
201 201
 %token FIFO_DB_URL
202
+%token UNIX_SOCK
203
+%token UNIX_SOCK_CHILDREN
202 204
 %token AVP_DB_URL
203 205
 %token SERVER_SIGNATURE
204 206
 %token REPLY_TO_VIA
... ...
@@ -408,6 +410,10 @@ assign_stm:	DEBUG EQUAL NUMBER { debug=$3; }
408 410
 		| FIFO_MODE EQUAL error { yyerror("int value expected"); }
409 411
 		| FIFO_DB_URL EQUAL STRING { fifo_db_url=$3; }
410 412
 		| FIFO_DB_URL EQUAL error  { yyerror("string value expected"); }
413
+                | UNIX_SOCK EQUAL STRING { unixsock_name=$3; }
414
+                | UNIX_SOCK EQUAL error { yyerror("string value expected"); }
415
+                | UNIX_SOCK_CHILDREN EQUAL NUMBER { unixsock_children=$3; }
416
+                | UNIX_SOCK_CHILDREN EQUAL error { yyerror("int value expected\n"); }
411 417
 		| AVP_DB_URL EQUAL STRING { avp_db_url=$3; }
412 418
 		| AVP_DB_URL EQUAL error  { yyerror("string value expected"); }
413 419
 		| USER EQUAL STRING     { user=$3; }
... ...
@@ -107,6 +107,10 @@ extern int fifo_mode;
107 107
 char extern *fifo_dir; /* dir. where  reply fifos are allowed */
108 108
 extern char *fifo_db_url;  /* db url used by db_fifo interface */
109 109
 
110
+/* UNIX domain socket configuration */
111
+extern char *unixsock_name;   /* The name of the socket */
112
+extern int unixsock_children; /* The number of listening children */
113
+
110 114
 /* AVP configuration */
111 115
 extern char *avp_db_url;  /* db url used by user preferences (AVPs) */
112 116
 
... ...
@@ -94,6 +94,7 @@
94 94
 #include "parser/parse_hname2.h"
95 95
 #include "parser/digest/digest_parser.h"
96 96
 #include "fifo_server.h"
97
+#include "unixsock_server.h"
97 98
 #include "usr_avp.h"
98 99
 #include "name_alias.h"
99 100
 #include "hash_func.h"
... ...
@@ -231,7 +232,8 @@ Options:\n\
231 232
     -u uid       Change uid \n\
232 233
     -g gid       Change gid \n\
233 234
     -P file      Create a pid file\n\
234
-    -i fifo_path Create a fifo (usefull for monitoring " NAME ") \n"
235
+    -i fifo_path Create a fifo (usefull for monitoring " NAME ") \n\
236
+    -x socket    Create a unix domain socket \n"
235 237
 #ifdef STATS
236 238
 "    -s file     File to which statistics is dumped (disabled otherwise)\n"
237 239
 #endif
... ...
@@ -404,6 +406,7 @@ void cleanup(show_status)
404 406
 	destroy_tls();
405 407
 #endif
406 408
 	destroy_timer();
409
+	close_unixsock_server();
407 410
 	destroy_fifo();
408 411
 	destroy_script_cb();
409 412
 #ifdef PKG_MALLOC
... ...
@@ -830,6 +833,13 @@ int main_loop()
830 833
 			LOG(L_ERR, "opening fifo server failed\n");
831 834
 			goto error;
832 835
 		}
836
+
837
+		     /* Initialize Unix domain socket server */
838
+		if (init_unixsock_server()<0) {
839
+			LOG(L_ERR, "Error while initializing Unix domain socket server\n");
840
+			goto error;
841
+		}
842
+
833 843
 		/* main process, receive loop */
834 844
 		process_no=0; /*main process number*/
835 845
 		pt[process_no].pid=getpid();
... ...
@@ -973,6 +983,12 @@ int main_loop()
973 983
 		goto error;
974 984
 	}
975 985
 
986
+	     /* Initialize Unix domain socket server */
987
+	if (init_unixsock_server()<0) {
988
+		LOG(L_ERR, "Error while initializing Unix domain socket server\n");
989
+		goto error;
990
+	}
991
+
976 992
 #ifdef USE_TCP
977 993
 	/* if we are using tcp we always need the timer */
978 994
 	if ((!tcp_disable)||(timer_list))
... ...
@@ -1130,7 +1146,7 @@ int main(int argc, char** argv)
1130 1146
 #ifdef STATS
1131 1147
 	"s:"
1132 1148
 #endif
1133
-	"f:cp:m:b:l:n:N:rRvdDETVhw:t:u:g:P:i:";
1149
+	"f:cp:m:b:l:n:N:rRvdDETVhw:t:u:g:P:i:x";
1134 1150
 	
1135 1151
 	while((c=getopt(argc,argv,options))!=-1){
1136 1152
 		switch(c){
... ...
@@ -1256,6 +1272,9 @@ int main(int argc, char** argv)
1256 1272
 			case 'i':
1257 1273
 					fifo=optarg;
1258 1274
 					break;
1275
+		        case 'x':
1276
+				        unixsock_name=optarg;
1277
+					break;
1259 1278
 			case '?':
1260 1279
 					if (isprint(optopt))
1261 1280
 						fprintf(stderr, "Unknown option `-%c�.\n", optopt);
... ...
@@ -65,6 +65,7 @@ typedef enum {
65 65
 #define PROC_TIMER    -1  /* Timer attendant process */
66 66
 #define PROC_FIFO     -2  /* FIFO attendant process */
67 67
 #define PROC_TCP_MAIN -4  /* TCP main process */
68
+#define PROC_UNIXSOCK -5  /* Unix domain socket server processes */
68 69
 
69 70
 #define MODULE_VERSION char *module_version=VERSION;
70 71