Browse Source

- make install
- exit on SIGCHLD even if in a child
- hack for nofork is_main & init_child

Andrei Pelinescu-Onciul 23 năm trước cách đây
mục cha
commit
db1b50170b
3 tập tin đã thay đổi với 68 bổ sung4 xóa
  1. 43 1
      Makefile
  2. 20 1
      Makefile.defs
  3. 5 2
      main.c

+ 43 - 1
Makefile

@@ -10,7 +10,7 @@ auto_gen=lex.yy.c cfg.tab.c   #lexx, yacc etc
 #include  source related defs
 #include  source related defs
 include Makefile.sources
 include Makefile.sources
 
 
-exclude_modules=CVS mysql auth cpl jabber acc pike ext 
+exclude_modules=CVS mysql pike
 static_modules=
 static_modules=
 static_modules_path=$(addprefix modules/, $(static_modules))
 static_modules_path=$(addprefix modules/, $(static_modules))
 extra_sources=$(wildcard $(addsuffix /*.c, $(static_modules_path)))
 extra_sources=$(wildcard $(addsuffix /*.c, $(static_modules_path)))
@@ -22,6 +22,8 @@ DEFS+=$(static_defs)
 modules=$(filter-out $(addprefix modules/, \
 modules=$(filter-out $(addprefix modules/, \
 			$(exclude_modules) $(static_modules)), \
 			$(exclude_modules) $(static_modules)), \
 			$(wildcard modules/*))
 			$(wildcard modules/*))
+modules_names=$(patsubst modules/%/, %.so, $(modules))
+modules_full_path=$(join $(modules), $(modules_names))
 
 
 NAME=ser
 NAME=ser
 
 
@@ -84,3 +86,43 @@ tar: mantainer-clean
 	tar -C .. -zcf ../$(NAME)-$(RELEASE)_src.tar.gz  $(notdir $(CURDIR)) 
 	tar -C .. -zcf ../$(NAME)-$(RELEASE)_src.tar.gz  $(notdir $(CURDIR)) 
 
 
 
 
+install: all mk-install-dirs install-cfg install-bin install-modules \
+	install-doc
+
+
+mk-install-dirs: $(cfg-prefix)/$(cfg-dir) $(bin-prefix)/$(bin-dir) \
+			$(modules-prefix)/$(modules-dir) $(doc-prefix)/$(doc-dir)
+
+$(cfg-prefix)/$(cfg-dir): 
+		mkdir -p $(cfg-prefix)/$(cfg-dir)
+
+$(bin-prefix)/$(bin-dir):
+		mkdir -p $(bin-prefix)/$(bin-dir)
+
+$(modules-prefix)/$(modules-dir):
+		mkdir -p $(modules-prefix)/$(modules-dir)
+
+
+$(doc-prefix)/$(doc-dir):
+		mkdir -p $(doc-prefix)/$(doc-dir)
+
+
+install-cfg:
+		$(INSTALL-CFG) ser.cfg $(cfg-prefix)/$(cfg-dir)
+
+install-bin:
+		$(INSTALL-BIN) ser $(bin-prefix)/$(bin-dir)
+
+
+install-modules:
+	-@for r in $(modules_full_path) "" ; do \
+		if [ -n "$$r" ]; then \
+			$(INSTALL-MODULES)  $$r  $(modules-prefix)/$(modules-dir) ; \
+		fi ; \
+	done 
+
+
+install-doc:
+	$(INSTALL-DOC) README $(doc-prefix)/$(doc-dir)
+
+

+ 20 - 1
Makefile.defs

@@ -8,12 +8,31 @@
 VERSION = 0
 VERSION = 0
 PATCHLEVEL = 8
 PATCHLEVEL = 8
 SUBLEVEL = 7
 SUBLEVEL = 7
-EXTRAVERSION = -5-ipv6
+EXTRAVERSION = -6-ipv6
 
 
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
 OS = $(shell uname -s)
 OS = $(shell uname -s)
 ARCH = $(shell uname -m |sed -e s/i.86/i386/ -e s/sun4u/sparc64/ )
 ARCH = $(shell uname -m |sed -e s/i.86/i386/ -e s/sun4u/sparc64/ )
 
 
+prefix = /usr/local
+cfg-prefix = $(prefix)
+bin-prefix = $(prefix)
+modules-prefix= $(prefix)
+doc-prefix = $(prefix)
+
+# dirs
+cfg-dir = etc/ser/
+bin-dir = sbin/
+modules-dir = lib/ser/modules/
+doc-dir = doc/ser/
+
+INSTALL = install -b
+INSTALL-CFG = $(INSTALL) -m 644
+INSTALL-BIN = $(INSTALL) -m 755
+INSTALL-MODULES = $(INSTALL) -m 755
+INSTALL-DOC = $(INSTALL) -m 644
+
+
 # compile-time options
 # compile-time options
 #
 #
 # -DSTATS
 # -DSTATS

+ 5 - 2
main.c

@@ -484,7 +484,6 @@ int main_loop()
 				}
 				}
 		}
 		}
 		/* main process, receive loop */
 		/* main process, receive loop */
-		is_main=1;
 		pids[0]=getpid();
 		pids[0]=getpid();
 		process_bit = 1;
 		process_bit = 1;
 		process_no=0; /*main process number*/
 		process_no=0; /*main process number*/
@@ -497,6 +496,8 @@ int main_loop()
 			LOG(L_ERR, "init_child failed\n");
 			LOG(L_ERR, "init_child failed\n");
 			goto error;
 			goto error;
 		}
 		}
+		is_main=1; /* hack 42: call init_child with is_main=0 in case
+					 some modules wants to fork a child */
 		
 		
 		return udp_rcv_loop();
 		return udp_rcv_loop();
 	}else{
 	}else{
@@ -593,7 +594,7 @@ static void sig_usr(int signo)
 		else /*  previous sig. not processed yet, ignoring? */
 		else /*  previous sig. not processed yet, ignoring? */
 			return; ;
 			return; ;
 		if (dont_fork) 
 		if (dont_fork) 
-				/* only one proc, dooing everything from the sig handler,
+				/* only one proc, doing everything from the sig handler,
 				unsafe, but this is only for debugging mode*/
 				unsafe, but this is only for debugging mode*/
 			handle_sigs();
 			handle_sigs();
 	}else{
 	}else{
@@ -611,6 +612,8 @@ static void sig_usr(int signo)
 			case SIGUSR2:
 			case SIGUSR2:
 			case SIGHUP:
 			case SIGHUP:
 					break;
 					break;
+			case SIGCHLD:
+					exit(0); /* terminate if one child died */
 		}
 		}
 	}
 	}
 }
 }