Browse Source

- added pid and process no information when logging to stderror

Andrei Pelinescu-Onciul 24 years ago
parent
commit
cbd9fc8bb1
5 changed files with 33 additions and 5 deletions
  1. 1 1
      Makefile.defs
  2. 1 0
      dprint.c
  3. 2 0
      globals.h
  4. 26 1
      main.c
  5. 3 3
      t_debug.cfg

+ 1 - 1
Makefile.defs

@@ -46,7 +46,7 @@ ARCH = $(shell uname -s)
 #		malloc etc.)
 DEFS= -DNAME='"$(NAME)"' -DVERSION='"$(RELEASE)"' -DARCH='"$(ARCH)"' \
 	 -DDNS_IP_HACK  -DPKG_MALLOC -DSHM_MEM  -DSHM_MMAP \
-	 -DDBG_QM_MALLOC #-DNO_DEBUG #
+	 -DDBG_QM_MALLOC -DNO_DEBUG #
 #-DEXTRA_DEBUG
 # -DUSE_SHM_MEM
 #-DNO_DEBUG 

+ 1 - 0
dprint.c

@@ -14,6 +14,7 @@ void dprint(char * format, ...)
 {
 	va_list ap;
 
+	fprintf(stderr, "%2d(%d) ", process_no, pids[process_no]);
 	va_start(ap, format);
 	vfprintf(stderr,format,ap);
 	fflush(stderr);

+ 2 - 0
globals.h

@@ -31,6 +31,8 @@ extern int log_stderr;
 extern int check_via;
 extern int received_dns;
 extern int loop_checks;
+extern int process_no;
+extern int *pids;
 
 extern int cfg_errors;
 extern unsigned int msg_no;

+ 26 - 1
main.c

@@ -148,6 +148,8 @@ unsigned int maxbuffer = MAX_RECV_BUFFER_SIZE; /* maximum buffer size we do not
 				      		durig the auto-probing procedure; may be
 				      		re-configured */
 int children_no = 0;           /* number of children processing requests */
+int *pids;		       /*array with childrens pids, 0= main proc,
+				alloc'ed in shared mem if possible*/
 int debug = 0;
 int dont_fork = 0;
 int log_stderr = 0;
@@ -192,7 +194,8 @@ int daemonize(char*  name)
 	int r;
 	
 	if (log_stderr==0)
-		openlog(name, LOG_PID, LOG_DAEMON); /* LOG_CONS, LOG_PERRROR ? */
+		openlog(name, LOG_PID|LOG_CONS, LOG_LOCAL1 /*LOG_DAEMON*/);
+		/* LOG_CONS, LOG_PERRROR ? */
 
 	if (chdir("/")<0){
 		LOG(L_CRIT,"cannot chroot:%s\n", strerror(errno));
@@ -254,10 +257,12 @@ int main_loop()
 
 		/* we need another process to act as the timer*/
 		if (timer_list){
+				process_no++;
 				if ((pid=fork())<0){
 					LOG(L_CRIT,  "ERRROR: main_loop: Cannot fork\n");
 					goto error;
 				}
+				
 				if (pid==0){
 					/* child */
 					/* timer!*/
@@ -265,10 +270,14 @@ int main_loop()
 						sleep(TIMER_TICK);
 						timer_ticker();
 					}
+				}else{
+						pids[process_no]=pid; /*should be shared mem anway*/
 				}
 		}
 		/* main process, receive loop */
 		is_main=1;
+		pids[0]=getpid();
+		process_no=0; /*main process number*/
 		udp_rcv_loop();
 	}else{
 		for(r=0;r<addresses_no;r++){
@@ -281,16 +290,20 @@ int main_loop()
 				}
 				if (pid==0){
 					/* child */
+					process_no=i+1; /*0=main*/
 #ifdef STATS
 					setstats( i );
 #endif
 					return udp_rcv_loop();
+				}else{
+						pids[i+1]=pid; /*should be in shared mem.*/
 				}
 			}
 			/*close(udp_sock);*/ /*parent*/
 		}
 	}
 	/*this is the main process*/
+	pids[process_no]=getpid();
 	is_main=1;
 	if (timer_list){
 		for(;;){
@@ -557,6 +570,18 @@ int main(int argc, char** argv)
 
 	
 	if (children_no<=0) children_no=CHILD_NO;
+	/*alloc pids*/
+#ifdef SHM_MEM
+	pids=shm_malloc(sizeof(int)*children_no);
+#else
+	pids=malloc(sizeof(int)*children_no);
+#endif
+	if (pids==0){
+		fprintf(stderr, "ERROR: out  of memory\n");
+		goto error;
+	}
+	memset(pids, 0, sizeof(int)*children_no);
+
 	if (addresses_no==0) {
 		/* get our address, only the first one */
 		if (uname (&myname) <0){

+ 3 - 3
t_debug.cfg

@@ -2,11 +2,11 @@ debug=9          # debug level (cmd line: -dddddddddd)
 check_via=yes     # (cmd. line: -v)
 dns=on           # (cmd. line: -r)
 rev_dns=yes      # (cmd. line: -R)
-fork=yes          # (cmd. line: -D)
-children=4
+fork=no          # (cmd. line: -D)
+children=10
 log_stderror=yes # (cmd line: -E)
 #port=5080
-listen=127.0.0.1
+#listen=127.0.0.1
 loop_checks=1
 # for more info: sip_router -h