Browse code

- updated module to make use of module interface for properly creating additional processes

git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@2623 689a6050-402a-0410-94f2-e92a70836424

Bogdan-Andrei Iancu authored on 21/08/2007 16:08:32
Showing 2 changed files
... ...
@@ -75,7 +75,6 @@ static char *DB_URL        = 0;  /* database url */
75 75
 static char *DB_TABLE      = 0;  /* */
76 76
 static char *dtd_file      = 0;  /* name of the DTD file for CPL parser */
77 77
 static char *lookup_domain = 0;
78
-static pid_t aux_process   = 0;  /* pid of the private aux. process */
79 78
 static char *timer_avp     = 0;  /* name of variable timer AVP */
80 79
 
81 80
 
... ...
@@ -110,6 +109,16 @@ static int cpl_init(void);
110 109
 static int mi_child_init();
111 110
 static int cpl_child_init(int rank);
112 111
 static int cpl_exit(void);
112
+static void cpl_process(int rank);
113
+
114
+
115
+/*
116
+ * Exported processes
117
+ */
118
+static proc_export_t cpl_procs[] = {
119
+	{"CPL Aux",  0,  0,  cpl_process, 1 },
120
+	{0,0,0}
121
+};
113 122
 
114 123
 
115 124
 /*
... ...
@@ -171,7 +180,7 @@ struct module_exports exports = {
171 180
 	0,        /* exported statistics */
172 181
 	mi_cmds,  /* exported MI functions */
173 182
 	0,        /* exported pseudo-variables */
174
-	0,        /* extra processes */
183
+	cpl_procs,/* extra processes */
175 184
 	cpl_init, /* Module initialization function */
176 185
 	(response_function) 0,
177 186
 	(destroy_function) cpl_exit,
... ...
@@ -407,32 +416,7 @@ error:
407 416
 
408 417
 static int cpl_child_init(int rank)
409 418
 {
410
-	pid_t pid;
411
-
412
-	/* don't do anything for non-worker process */
413
-	if (rank<1)
414
-		return 0;
415
-
416
-	/* only child 1 will fork the aux process */
417
-	if (rank==1) {
418
-		pid = fork();
419
-		if (pid==-1) {
420
-			LOG(L_CRIT,"ERROR:cpl_child_init(%d): cannot fork: %s!\n",
421
-				rank, strerror(errno));
422
-			goto error;
423
-		} else if (pid==0) {
424
-			/* I'm the child */
425
-			cpl_aux_process( cpl_env.cmd_pipe[0], cpl_env.log_dir);
426
-		} else {
427
-			LOG(L_INFO,"INFO:cpl_child_init(%d): child created\n",rank);
428
-			/* I'm the parent -> remember the pid */
429
-			aux_process = pid;
430
-		}
431
-	}
432
-
433 419
 	return cpl_db_init(DB_URL, DB_TABLE);
434
-error:
435
-	return -1;
436 420
 }
437 421
 
438 422
 
... ...
@@ -442,31 +426,19 @@ static int mi_child_init()
442 426
 }
443 427
 
444 428
 
429
+static void cpl_process(int rank)
430
+{
431
+	cpl_aux_process( cpl_env.cmd_pipe[0], cpl_env.log_dir);
432
+	exit(-1);
433
+}
434
+
435
+
445 436
 static int cpl_exit(void)
446 437
 {
447 438
 	/* free the TZ orig */
448 439
 	if (cpl_env.orig_tz.s)
449 440
 		shm_free(cpl_env.orig_tz.s);
450 441
 
451
-	/* if still running, stop the aux process */
452
-	if (!aux_process) {
453
-		LOG(L_INFO,"INFO:cpl_c:cpl_exit: aux process hasn't been created -> "
454
-			"nothing to kill\n");
455
-	} else {
456
-		/* kill the auxiliary process */
457
-		if (kill( aux_process, SIGKILL)!=0) {
458
-			if (errno==ESRCH) {
459
-				LOG(L_INFO,"INFO:cpl_c:cpl_exit: seems that my child is "
460
-					"already dead!\n");
461
-			} else {
462
-				LOG(L_ERR,"ERROR:cpl_c:cpl_exit: killing the aux. process "
463
-					"failed! error from kill: %s\n",strerror(errno));
464
-				return -1;
465
-			}
466
-		} else {
467
-			LOG(L_INFO,"INFO:cl_c:cpl_exit: killed my child!\n");
468
-		}
469
-	}
470 442
 	return 0;
471 443
 }
472 444
 
... ...
@@ -55,10 +55,10 @@ MODULE_VERSION
55 55
 
56 56
 static int sms_init(void);
57 57
 static int sms_exit(void);
58
-static int sms_child_init(int);
59 58
 static int w_sms_send_msg(struct sip_msg*, char*, char* );
60 59
 static int w_sms_send_msg_to_net(struct sip_msg*, char*, char*);
61 60
 static int fixup_sms_send_msg_to_net(void** param, int param_no);
61
+static void sms_process(int);
62 62
 
63 63
 
64 64
 
... ...
@@ -79,6 +79,12 @@ int    sms_report_type = NO_REPORT;
79 79
 struct tm_binds tmb;
80 80
 
81 81
 
82
+static proc_export_t sms_procs[] = {
83
+	{"SMS receiver",  0,  0, sms_process, 0 },
84
+	{0,0,0}
85
+};
86
+
87
+
82 88
 static cmd_export_t cmds[]={
83 89
 	{"sms_send_msg_to_net", w_sms_send_msg_to_net, 1, 
84 90
 	     fixup_sms_send_msg_to_net, REQUEST_ROUTE},
... ...
@@ -109,11 +115,11 @@ struct module_exports exports= {
109 115
 	0,          /* exported statistics */
110 116
 	0,          /* exported MI functions */
111 117
 	0,          /* exported pseudo-variables */
112
-	0,          /* extra processes */
118
+	sms_procs,  /* extra processes */
113 119
 	sms_init,   /* module initialization function */
114 120
 	(response_function) 0,
115 121
 	(destroy_function) sms_exit,   /* module exit function */
116
-	(child_init_function) sms_child_init  /* per-child init function */
122
+	0           /* per-child init function */
117 123
 };
118 124
 
119 125
 
... ...
@@ -600,36 +606,14 @@ error:
600 606
 
601 607
 
602 608
 
603
-
604
-int sms_child_init(int rank)
609
+void sms_process(int rank)
605 610
 {
606
-	int  i, foo;
607
-
608
-	/* only the child 1 will execute this */
609
-	if (rank != 1) goto done;
610
-
611
-	/* creates processes for each modem */
612
-	for(i=0;i<nr_of_modems;i++)
613
-	{
614
-		if ( (foo=fork())<0 ) {
615
-			LOG(L_ERR,"ERROR: sms_child_init: cannot fork \n");
616
-			goto error;
617
-		}
618
-		if (!foo) {
619
-			modem_process(&(modems[i]));
620
-			goto done;
621
-		}
622
-	}
623
-
624
-done:
625
-	return 0;
626
-error:
627
-	return-1;
611
+	modem_process(&(modems[rank]));
612
+	exit(-1);
628 613
 }
629 614
 
630 615
 
631 616
 
632
-
633 617
 static int sms_init(void)
634 618
 {
635 619
 	LOG(L_INFO,"SMS - initializing\n");
... ...
@@ -638,6 +622,8 @@ static int sms_init(void)
638 622
 		return -1;
639 623
 	if (global_init()==-1)
640 624
 		return -1;
625
+	/* update the number of required processes */
626
+	sms_procs[0].no = nr_of_modems;
641 627
 	return 0;
642 628
 }
643 629