Rename signal() to sysv_signal() to keep people from getting confused

Centralize makefile rules to new MRULES file

diff --git a/MRULES b/MRULES
new file mode 100644
index 0000000..8a8831c
--- /dev/null
+++ b/MRULES
@@ -0,0 +1,41 @@
+# -*- makefile -*-
+#
+# Standard pattern rules
+#
+
+.SUFFIXES: .c .o .a .so .lo .i .S .s .ls .ss .lss
+
+.c.o:
+	$(CC) $(CFLAGS) -c -o $@ $<
+
+.c.i:
+	$(CC) $(CFLAGS) -E -o $@ $<
+
+.c.s:
+	$(CC) $(CFLAGS) -S -o $@ $<
+
+.S.o:
+	$(CC) $(CFLAGS) -D__ASSEMBLY__ -c -o $@ $<
+
+.S.s:
+	$(CC) $(CFLAGS) -D__ASSEMBLY__ -E -o $@ $<
+
+.S.lo:
+	$(CC) $(CFLAGS) $(SOFLAGS) -D__ASSEMBLY__ -c -o $@ $<
+
+.S.ls:
+	$(CC) $(CFLAGS) $(SOFLAGS) -D__ASSEMBLY__ -E -o $@ $<
+
+.s.o:
+	$(CC) $(CFLAGS) -x assembler -c -o $@ $<
+
+.ls.lo:
+	$(CC) $(CFLAGS) $(SOFLAGS) -x assembler -c -o $@ $<
+
+.c.lo:
+	$(CC) $(CFLAGS) $(SOFLAGS) -c -o $@ $<
+
+.c.ls:
+	$(CC) $(CFLAGS) $(SOFLAGS) -S -o $@ $<
+
+
diff --git a/ash/Makefile b/ash/Makefile
index 647ecca..4f25b00 100644
--- a/ash/Makefile
+++ b/ash/Makefile
@@ -18,6 +18,7 @@
 
 SRCROOT  = ..
 include ../MCONFIG
+include ../MRULES
 
 MAKEDEPS = -Wp,-MD,.$(subst /,-,$*).d
 CFLAGS   = $(MAKEDEPS) $(OPTFLAGS) $(REQFLAGS) -DSHELL
@@ -30,9 +31,6 @@
 	builtins.c builtins.h init.c mkinit mknodes \
 	nodes.c nodes.h token.def
 
-.c.o:
-	$(CC) $(CFLAGS) -c -o $@ $<
-
 all:	$(PROG) $(PROG).shared
 
 $(PROG): $(OBJS) $(LIBS) $(CRT0)
diff --git a/gzip/Makefile b/gzip/Makefile
index c33794f..5b80539 100644
--- a/gzip/Makefile
+++ b/gzip/Makefile
@@ -16,13 +16,14 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
-# $Id: Makefile,v 1.4 2002/08/23 21:06:05 hpa Exp $
+# $Id: Makefile,v 1.5 2004/02/09 23:18:14 hpa Exp $
 
 #### Start of system configuration section. ####
 
 SRCROOT = ..
 include ../MCONFIG
 include MCONFIG
+include ../MRULES
 
 #### End of system configuration section. ####
 
@@ -42,9 +43,6 @@
 SRCS += $(ZIPSRCS)
 endif
 
-.c.o:
-	$(CC) -c $(CFLAGS) $<
-
 all:	gzip gunzip zcat gzip.stripped
 
 # Actual build-related targets
diff --git a/gzip/gzip.c b/gzip/gzip.c
index 3d122c9..9d84110 100644
--- a/gzip/gzip.c
+++ b/gzip/gzip.c
@@ -45,7 +45,7 @@
  */
 
 #ifdef RCSID
-static char rcsid[] = "$Id: gzip.c,v 1.1 2002/08/18 00:59:21 hpa Exp $";
+static char rcsid[] = "$Id: gzip.c,v 1.2 2004/02/09 23:18:14 hpa Exp $";
 #endif
 
 #include <ctype.h>
@@ -238,18 +238,18 @@
     env = add_envopt(&argc, &argv, OPTIONS_VAR);
     if (env != NULL) args = argv;
 
-    foreground = signal(SIGINT, SIG_IGN) != SIG_IGN;
+    foreground = sysv_signal(SIGINT, SIG_IGN) != SIG_IGN;
     if (foreground) {
-	(void) signal (SIGINT, (sig_type)abort_gzip);
+	(void) sysv_signal(SIGINT, (sig_type)abort_gzip);
     }
 #ifdef SIGTERM
-    if (signal(SIGTERM, SIG_IGN) != SIG_IGN) {
-	(void) signal(SIGTERM, (sig_type)abort_gzip);
+    if (sysv_signal(SIGTERM, SIG_IGN) != SIG_IGN) {
+	(void) sysv_signal(SIGTERM, (sig_type)abort_gzip);
     }
 #endif
 #ifdef SIGHUP
-    if (signal(SIGHUP, SIG_IGN) != SIG_IGN) {
-	(void) signal(SIGHUP,  (sig_type)abort_gzip);
+    if (sysv_signal(SIGHUP, SIG_IGN) != SIG_IGN) {
+	(void) sysv_signal(SIGHUP,  (sig_type)abort_gzip);
     }
 #endif
 
diff --git a/include/signal.h b/include/signal.h
index f9eebb2..513b4e5 100644
--- a/include/signal.h
+++ b/include/signal.h
@@ -64,7 +64,7 @@
 }
 
 __extern __sighandler_t __signal(int, __sighandler_t, int);
-__extern __sighandler_t signal(int, __sighandler_t);
+__extern __sighandler_t sysv_signal(int, __sighandler_t);
 __extern __sighandler_t bsd_signal(int, __sighandler_t);
 __extern int sigaction(int, const struct sigaction *, struct sigaction *);
 __extern int sigprocmask(int, const sigset_t *, sigset_t *);
diff --git a/ipconfig/MCONFIG b/ipconfig/MCONFIG
index ba4814e..472f092 100644
--- a/ipconfig/MCONFIG
+++ b/ipconfig/MCONFIG
@@ -3,5 +3,6 @@
 SRCROOT = ..
 
 include $(SRCROOT)/MCONFIG
+include $(SRCROOT)/MRULES
 
 CFLAGS = -Wp,-MD,$(dir $@).$(notdir $@).d $(OPTFLAGS) $(REQFLAGS) -Wstrict-prototypes -Wall -I.
diff --git a/kinit/Makefile b/kinit/Makefile
index 78b4f57..b55cf93 100644
--- a/kinit/Makefile
+++ b/kinit/Makefile
@@ -1,5 +1,6 @@
 SRCROOT = ..
 include $(SRCROOT)/MCONFIG
+include $(SRCROOT)/MRULES
 
 MAKEDEPS = -Wp,-MD,.$(subst /,-,$*).d
 CFLAGS	= $(MAKEDEPS) $(OPTFLAGS) $(REQFLAGS) -W -Wall \
diff --git a/klibc/CAVEATS b/klibc/CAVEATS
index c7131ac..5bc11e4 100644
--- a/klibc/CAVEATS
+++ b/klibc/CAVEATS
@@ -49,3 +49,13 @@
 klibc is not thread-safe.  Consequently, clone() or any of the
 pthreads functions are not included.
 
+
+bsd_signal vs sysv_signal:
+--------------------------
+
+There is no signal() call, because you never know if you want
+Linux/SysV semantics (SA_RESETHAND) or GNU/BSD semantics (SA_RESTART).
+The best, in *any* circumstances, is to never use signal() and instead
+use sigaction(), but in order to simplify porting you can use either
+sysv_signal() or bsd_signal(), depending on what you actually want.
+
diff --git a/klibc/MCONFIG b/klibc/MCONFIG
index a46a98a..253a946 100644
--- a/klibc/MCONFIG
+++ b/klibc/MCONFIG
@@ -5,45 +5,9 @@
 
 SRCROOT = ..
 include ../MCONFIG
+include ../MRULES
 
 WARNFLAGS = -W -Wall -Wpointer-arith -Wwrite-strings -Wstrict-prototypes -Winline
 CFLAGS  = -Wp,-MD,$(dir $*).$(notdir $*).d $(OPTFLAGS) $(REQFLAGS) $(WARNFLAGS)
 
 SOFLAGS = -fPIC
-
-.SUFFIXES: .c .o .a .so .lo .i .S .s .ls .ss .lss
-
-.c.o:
-	$(CC) $(CFLAGS) -c -o $@ $<
-
-.c.i:
-	$(CC) $(CFLAGS) -E -o $@ $<
-
-.c.s:
-	$(CC) $(CFLAGS) -S -o $@ $<
-
-.S.o:
-	$(CC) $(CFLAGS) -D__ASSEMBLY__ -c -o $@ $<
-
-.S.s:
-	$(CC) $(CFLAGS) -D__ASSEMBLY__ -E -o $@ $<
-
-.S.lo:
-	$(CC) $(CFLAGS) $(SOFLAGS) -D__ASSEMBLY__ -c -o $@ $<
-
-.S.ls:
-	$(CC) $(CFLAGS) $(SOFLAGS) -D__ASSEMBLY__ -E -o $@ $<
-
-.s.o:
-	$(CC) $(CFLAGS) -x assembler -c -o $@ $<
-
-.ls.lo:
-	$(CC) $(CFLAGS) $(SOFLAGS) -x assembler -c -o $@ $<
-
-.c.lo:
-	$(CC) $(CFLAGS) $(SOFLAGS) -c -o $@ $<
-
-.c.ls:
-	$(CC) $(CFLAGS) $(SOFLAGS) -S -o $@ $<
-
-
diff --git a/klibc/Makefile b/klibc/Makefile
index 49cd43b..5ec7f93 100644
--- a/klibc/Makefile
+++ b/klibc/Makefile
@@ -22,7 +22,7 @@
 	  fopen.o fread.o fread2.o fgetc.o fgets.o \
 	  fwrite.o fwrite2.o fputc.o fputs.o puts.o \
 	  sleep.o usleep.o raise.o abort.o assert.o alarm.o pause.o \
-	  __signal.o signal.o bsd_signal.o siglist.o siglongjmp.o \
+	  __signal.o sysv_signal.o bsd_signal.o siglist.o siglongjmp.o \
 	  sigaction.o sigpending.o sigprocmask.o sigsuspend.o \
 	  brk.o sbrk.o malloc.o realloc.o calloc.o mmap.o getpagesize.o \
 	  memcpy.o memcmp.o memset.o memccpy.o memmem.o memswap.o \
diff --git a/klibc/include/signal.h b/klibc/include/signal.h
index f9eebb2..513b4e5 100644
--- a/klibc/include/signal.h
+++ b/klibc/include/signal.h
@@ -64,7 +64,7 @@
 }
 
 __extern __sighandler_t __signal(int, __sighandler_t, int);
-__extern __sighandler_t signal(int, __sighandler_t);
+__extern __sighandler_t sysv_signal(int, __sighandler_t);
 __extern __sighandler_t bsd_signal(int, __sighandler_t);
 __extern int sigaction(int, const struct sigaction *, struct sigaction *);
 __extern int sigprocmask(int, const sigset_t *, sigset_t *);
diff --git a/klibc/signal.c b/klibc/sysv_signal.c
similarity index 60%
rename from klibc/signal.c
rename to klibc/sysv_signal.c
index 982d0c6..3e55a02 100644
--- a/klibc/signal.c
+++ b/klibc/sysv_signal.c
@@ -1,10 +1,10 @@
 /*
- * signal.c
+ * sysv_signal.c
  */
 
 #include <signal.h>
 
-__sighandler_t signal(int signum, __sighandler_t handler)
+__sighandler_t sysv_signal(int signum, __sighandler_t handler)
 {
   /* Linux/SysV signal() semantics */
   return __signal(signum, handler, SA_RESETHAND);
diff --git a/klibc/tests/nfs_no_rpc.c b/klibc/tests/nfs_no_rpc.c
index 11b9f61..5c17706 100644
--- a/klibc/tests/nfs_no_rpc.c
+++ b/klibc/tests/nfs_no_rpc.c
@@ -282,7 +282,7 @@
 	int n;
 	int fd;
 
-	signal(SIGALRM, timeout);
+	sysv_signal(SIGALRM, timeout);
 	fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
 	if (fd < 0)
 		goto Esocket;
diff --git a/nfsmount/MCONFIG b/nfsmount/MCONFIG
index ba4814e..472f092 100644
--- a/nfsmount/MCONFIG
+++ b/nfsmount/MCONFIG
@@ -3,5 +3,6 @@
 SRCROOT = ..
 
 include $(SRCROOT)/MCONFIG
+include $(SRCROOT)/MRULES
 
 CFLAGS = -Wp,-MD,$(dir $@).$(notdir $@).d $(OPTFLAGS) $(REQFLAGS) -Wstrict-prototypes -Wall -I.
diff --git a/utils/Makefile b/utils/Makefile
index c29bddc..c92e766 100644
--- a/utils/Makefile
+++ b/utils/Makefile
@@ -1,5 +1,6 @@
 SRCROOT  = ..
 include ../MCONFIG
+include ../MRULES
 
 MAKEDEPS = -Wp,-MD,.$(subst /,-,$*).d
 CFLAGS   = $(MAKEDEPS) $(OPTFLAGS) $(REQFLAGS) -W -Wall
diff --git a/utils/dd.c b/utils/dd.c
index 2451cca..1313c3a 100644
--- a/utils/dd.c
+++ b/utils/dd.c
@@ -430,11 +430,11 @@
 
 	ret = sigsetjmp(jmp, 1);
 	if (ret == 0) {
-		signal(SIGINT, sigint_handler);
+		sysv_signal(SIGINT, sigint_handler);
 		ret = do_dd(rd_fd, wr_fd, stats);
 	}
 
-	signal(SIGINT, SIG_DFL);
+	sysv_signal(SIGINT, SIG_DFL);
 	return ret;
 }