More HP-inspired patches

Heath Kehoe hakehoe at norand.com
Wed Sep 15 02:05:08 UTC 1999


The included patch addresses several issues, mostly related to HP/UX.

 * Created a new libinn function xsignal(), which implements a signal()
   function using sigaction().  This is because HP/UX (along with other
   SYSV-derived systems) has an "unreliable" signal.  You have to re-set
   the signal handler when a signal goes off, and a signal may cause
   a system call to fail (with EINTR).  Using sigaction, you don't have
   these problems.

   I created a symbol USE_SIGACTION, that when defined, the xsignal
   function does a call to sigaction.  Otherwise, xsignal simply uses
   signal.  (The innfeed source already has something like this.)
   Currently, USE_SIGACTION only gets defined for HP/UX (in clibrary.h).
   Perhaps we could define it through configure, but I don't know
   enough about autoconf to set it up right now.

 * HP/UX headers define LOG_NEWS, but syslogd ignores it (and if you
   have 'news' in syslog.conf, syslogd says 'unknown facility').
   So I put in a check in config.h for HPUX to reset the log facility
   to LOG_LOCAL1.

Would anyone object if I made the syslog facility configurable
via inn.conf?  That way it'll be easier to customize which facility
is used.

 * With HP/UX, you definitely do not want to mix mmap-accesses of
   a file with read()s and write()s of the same file.  Writes may
   get lost, and reads will see stale data, unless you do lots of
   msyncs (which is a pain).  The buffindexed code uses mmap-accesses
   in all but four places, so I modified those last few pwrite()s
   to use mmap instead.  With this change, buffindexed has been
   working reliably on my servers.  Without this change, the OV
   buffers invariably become corrupt.

--Heath


diff -rc ../inn-1999-09-13_03-00/MANIFEST ./MANIFEST
*** ../inn-1999-09-13_03-00/MANIFEST	Fri Aug 27 00:29:06 1999
--- ./MANIFEST	Tue Sep 14 16:03:49 1999
***************
*** 375,380 ****
--- 375,381 ----
  lib/xmalloc.c               1 Failsafe memory allocation wrapper
  lib/xmemerr.c               1 Memory allocation error routine
  lib/xrealloc.c              1 Failsafe memory reallocation wrapper
+ lib/xsignal.c               1 signal() wrapper using sigaction
  lib/xwrite.c                1 Write that handles partial transfers
  lib/xwritev.c               1 Writev that handles partial transfers
  ltconfig                    1 Script for libtool
diff -rc ../inn-1999-09-13_03-00/backends/batcher.c ./backends/batcher.c
*** ../inn-1999-09-13_03-00/backends/batcher.c	Sat Sep 11 06:08:40 1999
--- ./backends/batcher.c	Mon Sep 13 13:15:46 1999
***************
*** 192,198 ****
  {
      GotInterrupt = TRUE;
      /* Let two interrupts kill us. */
!     (void)signal(s, SIG_DFL);
  }
  
  
--- 192,198 ----
  {
      GotInterrupt = TRUE;
      /* Let two interrupts kill us. */
!     (void)xsignal(s, SIG_DFL);
  }
  
  
***************
*** 322,331 ****
      ArtsInCB = 0;
      Cookie = -1;
      GotInterrupt = FALSE;
!     (void)signal(SIGHUP, CATCHinterrupt);
!     (void)signal(SIGINT, CATCHinterrupt);
!     (void)signal(SIGTERM, CATCHinterrupt);
!     /* (void)signal(SIGPIPE, CATCHinterrupt); */
      (void)GetTimeInfo(&Now);
      STATbegin = TIMEINFOasDOUBLE(Now);
  
--- 322,331 ----
      ArtsInCB = 0;
      Cookie = -1;
      GotInterrupt = FALSE;
!     (void)xsignal(SIGHUP, CATCHinterrupt);
!     (void)xsignal(SIGINT, CATCHinterrupt);
!     (void)xsignal(SIGTERM, CATCHinterrupt);
!     /* (void)xsignal(SIGPIPE, CATCHinterrupt); */
      (void)GetTimeInfo(&Now);
      STATbegin = TIMEINFOasDOUBLE(Now);
  
diff -rc ../inn-1999-09-13_03-00/backends/buffchan.c ./backends/buffchan.c
*** ../inn-1999-09-13_03-00/backends/buffchan.c	Wed May 20 22:00:10 1998
--- ./backends/buffchan.c	Mon Sep 13 13:15:46 1999
***************
*** 366,372 ****
      int		s;
  {
      GotInterrupt = TRUE;
!     (void)signal(s, SIG_DFL);
  }
  
  
--- 366,372 ----
      int		s;
  {
      GotInterrupt = TRUE;
!     (void)xsignal(s, SIG_DFL);
  }
  
  
***************
*** 399,410 ****
      GotInterrupt = FALSE;
      (void)umask(NEWSUMASK);
  
!     (void)signal(SIGHUP, CATCHinterrupt);
!     (void)signal(SIGINT, CATCHinterrupt);
!     (void)signal(SIGQUIT, CATCHinterrupt);
!     (void)signal(SIGPIPE, CATCHinterrupt);
!     (void)signal(SIGTERM, CATCHinterrupt);
!     (void)signal(SIGALRM, CATCHinterrupt);
  
      /* Parse JCL. */
      while ((i = getopt(ac, av, "bc:C:d:f:l:L:m:p:rs:u")) != EOF)
--- 399,410 ----
      GotInterrupt = FALSE;
      (void)umask(NEWSUMASK);
  
!     (void)xsignal(SIGHUP, CATCHinterrupt);
!     (void)xsignal(SIGINT, CATCHinterrupt);
!     (void)xsignal(SIGQUIT, CATCHinterrupt);
!     (void)xsignal(SIGPIPE, CATCHinterrupt);
!     (void)xsignal(SIGTERM, CATCHinterrupt);
!     (void)xsignal(SIGALRM, CATCHinterrupt);
  
      /* Parse JCL. */
      while ((i = getopt(ac, av, "bc:C:d:f:l:L:m:p:rs:u")) != EOF)
diff -rc ../inn-1999-09-13_03-00/backends/innxbatch.c ./backends/innxbatch.c
*** ../inn-1999-09-13_03-00/backends/innxbatch.c	Wed May 20 22:00:11 1998
--- ./backends/innxbatch.c	Mon Sep 13 13:15:46 1999
***************
*** 307,313 ****
  {
      GotInterrupt = TRUE;
      /* Let two interrupts kill us. */
!     (void)signal(s, SIG_DFL);
  }
  
  
--- 307,313 ----
  {
      GotInterrupt = TRUE;
      /* Let two interrupts kill us. */
!     (void)xsignal(s, SIG_DFL);
  }
  
  
***************
*** 408,415 ****
    /* Open a connection to the remote server. */
    if (ConnectTimeout) {
      GotAlarm = FALSE;
!     old = signal(SIGALRM, CATCHalarm);
!     (void)alarm(ConnectTimeout);
      JMPyes = TRUE;
      if (setjmp(JMPwhere)) {
        (void)fprintf(stderr, "Can't connect to %s, timed out\n",
--- 408,414 ----
    /* Open a connection to the remote server. */
    if (ConnectTimeout) {
      GotAlarm = FALSE;
!     old = xsignal(SIGALRM, CATCHalarm);
      JMPyes = TRUE;
      if (setjmp(JMPwhere)) {
        (void)fprintf(stderr, "Can't connect to %s, timed out\n",
***************
*** 416,421 ****
--- 415,421 ----
  		    REMhost);
        exit(1);
      }
+     (void)alarm(ConnectTimeout);
    }
    if (NNTPconnect(REMhost, NNTP_PORT, &From, &To, buff) < 0 || GotAlarm) {
      i = errno;
***************
*** 442,448 ****
    }
    if (ConnectTimeout) {
      (void)alarm(0);
!     (void)signal(SIGALRM, old);
      JMPyes = FALSE;
    }
    
--- 442,448 ----
    }
    if (ConnectTimeout) {
      (void)alarm(0);
!     (void)xsignal(SIGALRM, old);
      JMPyes = FALSE;
    }
    
***************
*** 458,475 ****
      (void)perror("cant setsockopt(RCVBUF)");
  #endif	/* defined(SOL_SOCKET) && defined(SO_SNDBUF) && defined(SO_RCVBUF) */
  
    /* Set up signal handlers. */
!   (void)signal(SIGHUP, CATCHinterrupt);
!   (void)signal(SIGINT, CATCHinterrupt);
!   (void)signal(SIGTERM, CATCHinterrupt);
!   (void)signal(SIGPIPE, SIG_IGN);
    if (TotalTimeout) {
      (void)alarm(TotalTimeout);
-     (void)signal(SIGALRM, CATCHalarm);
    }
- 
-   GotInterrupt = FALSE;
-   GotAlarm = FALSE;
  
    /* Start timing. */
    if (GetTimeInfo(&Now) < 0) {
--- 458,475 ----
      (void)perror("cant setsockopt(RCVBUF)");
  #endif	/* defined(SOL_SOCKET) && defined(SO_SNDBUF) && defined(SO_RCVBUF) */
  
+   GotInterrupt = FALSE;
+   GotAlarm = FALSE;
+ 
    /* Set up signal handlers. */
!   (void)xsignal(SIGHUP, CATCHinterrupt);
!   (void)xsignal(SIGINT, CATCHinterrupt);
!   (void)xsignal(SIGTERM, CATCHinterrupt);
!   (void)xsignal(SIGPIPE, SIG_IGN);
    if (TotalTimeout) {
+     (void)xsignal(SIGALRM, CATCHalarm);
      (void)alarm(TotalTimeout);
    }
  
    /* Start timing. */
    if (GetTimeInfo(&Now) < 0) {
diff -rc ../inn-1999-09-13_03-00/backends/innxmit.c ./backends/innxmit.c
*** ../inn-1999-09-13_03-00/backends/innxmit.c	Thu Jun 10 22:40:04 1999
--- ./backends/innxmit.c	Mon Sep 13 13:15:46 1999
***************
*** 935,941 ****
  {
      GotInterrupt = TRUE;
      /* Let two interrupts kill us. */
!     (void)signal(s, SIG_DFL);
  }
  
  
--- 935,941 ----
  {
      GotInterrupt = TRUE;
      /* Let two interrupts kill us. */
!     (void)xsignal(s, SIG_DFL);
  }
  
  
***************
*** 1295,1302 ****
  	/* Open a connection to the remote server. */
  	if (ConnectTimeout) {
  	    GotAlarm = FALSE;
! 	    old = signal(SIGALRM, CATCHalarm);
! 	    (void)alarm(ConnectTimeout);
  	    JMPyes = TRUE;
  	    if (setjmp(JMPwhere)) {
  		(void)fprintf(stderr, "Can't connect to %s, timed out\n",
--- 1295,1301 ----
  	/* Open a connection to the remote server. */
  	if (ConnectTimeout) {
  	    GotAlarm = FALSE;
! 	    old = xsignal(SIGALRM, CATCHalarm);
  	    JMPyes = TRUE;
  	    if (setjmp(JMPwhere)) {
  		(void)fprintf(stderr, "Can't connect to %s, timed out\n",
***************
*** 1304,1309 ****
--- 1303,1309 ----
  		SMshutdown();
  		exit(1);
  	    }
+ 	    (void)alarm(ConnectTimeout);
  	}
  	if (NNTPconnect(REMhost, port, &From, &To, buff) < 0 || GotAlarm) {
  	    i = errno;
***************
*** 1331,1337 ****
  	}
  	if (ConnectTimeout) {
  	    (void)alarm(0);
! 	    (void)signal(SIGALRM, old);
  	    JMPyes = FALSE;
  	}
  
--- 1331,1337 ----
  	}
  	if (ConnectTimeout) {
  	    (void)alarm(0);
! 	    (void)xsignal(SIGALRM, old);
  	    JMPyes = FALSE;
  	}
  
***************
*** 1384,1396 ****
      }
  
      /* Set up signal handlers. */
!     (void)signal(SIGHUP, CATCHinterrupt);
!     (void)signal(SIGINT, CATCHinterrupt);
!     (void)signal(SIGTERM, CATCHinterrupt);
!     (void)signal(SIGPIPE, SIG_IGN);
      if (TotalTimeout) {
  	(void)alarm(TotalTimeout);
- 	(void)signal(SIGALRM, CATCHalarm);
      }
  
      /* Main processing loop. */
--- 1384,1396 ----
      }
  
      /* Set up signal handlers. */
!     (void)xsignal(SIGHUP, CATCHinterrupt);
!     (void)xsignal(SIGINT, CATCHinterrupt);
!     (void)xsignal(SIGTERM, CATCHinterrupt);
!     (void)xsignal(SIGPIPE, SIG_IGN);
      if (TotalTimeout) {
+ 	(void)xsignal(SIGALRM, CATCHalarm);
  	(void)alarm(TotalTimeout);
      }
  
      /* Main processing loop. */
diff -rc ../inn-1999-09-13_03-00/include/clibrary.h.in ./include/clibrary.h.in
*** ../inn-1999-09-13_03-00/include/clibrary.h.in	Tue Sep  7 23:09:47 1999
--- ./include/clibrary.h.in	Mon Sep 13 13:15:46 1999
***************
*** 232,237 ****
--- 232,241 ----
  #undef HAVE_UNION_WAIT
  #endif
  
+ #if defined(HPUX) && ! defined(USE_SIGACTION)
+ #define USE_SIGACTION
+ #endif
+ 
  #if ! defined(INADDR_NONE) && ! defined(_AIX41)
  #define		INADDR_NONE 	(unsigned long)0xffffffff
  #endif
diff -rc ../inn-1999-09-13_03-00/include/config.h.in ./include/config.h.in
*** ../inn-1999-09-13_03-00/include/config.h.in	Wed Aug 25 19:49:39 1999
--- ./include/config.h.in	Mon Sep 13 23:24:05 1999
***************
*** 193,198 ****
--- 193,204 ----
  # define LOG_FACILITY	LOG_LOCAL1
  #endif
  
+ /* HP/UX headers define LOG_NEWS, but syslogd doesn't recognize it.  Bleagh!  */
+ #ifdef HPUX
+ # undef LOG_FACILITY
+ # define LOG_FACILITY	LOG_LOCAL1
+ #endif
+ 
  #define LOG_INN_SERVER		LOG_FACILITY
  
  /* Facility all other programs should log under. */
diff -rc ../inn-1999-09-13_03-00/include/libinn.h ./include/libinn.h
*** ../inn-1999-09-13_03-00/include/libinn.h	Mon Sep 13 00:49:57 1999
--- ./include/libinn.h	Tue Sep 14 00:05:10 1999
***************
*** 258,263 ****
--- 258,264 ----
  extern BOOL	fdreserve(int fdnum);
  extern FILE	*Fopen(const char *p, char *type, int index);
  extern int	Fclose(FILE *fp);
+ extern void	(*xsignal(int signum, void (*sigfunc)(int )))(int );
  
  const char  *Aliasgetnamebyhash(const HASH hash);
  HASH Aliasgethashbyhash(const HASH hash);
diff -rc ../inn-1999-09-13_03-00/innd/cc.c ./innd/cc.c
*** ../inn-1999-09-13_03-00/innd/cc.c	Mon Sep 13 00:52:01 1999
--- ./innd/cc.c	Mon Sep 13 13:15:46 1999
***************
*** 2010,2016 ****
       *  needed (i.e. something has deleted our named socket.
       */
  #if     defined(SIGUSR1)
!     (void)signal(SIGUSR1, CCresetup);
  #endif  /* defined(SIGUSR1) */
  }
  
--- 2010,2016 ----
       *  needed (i.e. something has deleted our named socket.
       */
  #if     defined(SIGUSR1)
!     (void)xsignal(SIGUSR1, CCresetup);
  #endif  /* defined(SIGUSR1) */
  }
  
***************
*** 2043,2049 ****
  CCresetup(s)
      int         s;
  {
!     (void)signal(s, CCresetup);
      CCclose();
      CCsetup();
  }
--- 2043,2051 ----
  CCresetup(s)
      int         s;
  {
! #ifndef USE_SIGACTION
!     (void)xsignal(s, CCresetup);
! #endif
      CCclose();
      CCsetup();
  }
diff -rc ../inn-1999-09-13_03-00/innd/innd.c ./innd/innd.c
*** ../inn-1999-09-13_03-00/innd/innd.c	Fri Aug 27 00:36:04 1999
--- ./innd/innd.c	Mon Sep 13 13:15:46 1999
***************
*** 514,520 ****
  {
      GotTerminate = TRUE;
      KillerSignal = s;
!     (void)signal(s, CatchTerminate);
  }
  
  
--- 514,522 ----
  {
      GotTerminate = TRUE;
      KillerSignal = s;
! #ifndef USE_SIGACTION
!     (void)xsignal(s, CatchTerminate);
! #endif
  }
  
  
***************
*** 764,770 ****
      if (Debug) {
  	Log = stdout;
  	Errlog = stderr;
! 	(void)signal(SIGINT, CatchTerminate);
      }
      else {
  	if (ShouldFork) {
--- 766,772 ----
      if (Debug) {
  	Log = stdout;
  	Errlog = stderr;
! 	(void)xsignal(SIGINT, CatchTerminate);
      }
      else {
  	if (ShouldFork) {
***************
*** 851,859 ****
      /* Set up the various parts of the system.  Channel feeds start
       * processes so call PROCsetup before ICDsetup.  NNTP needs to know
       * if it's a slave, so call RCsetup before NCsetup. */
!     (void)signal(SIGTERM, CatchTerminate);
  #if	defined(SIGDANGER)
!     (void)signal(SIGDANGER, CatchTerminate);
  #endif	/* defined(SIGDANGER) */
      CHANsetup(i);
      PROCsetup(10);
--- 853,861 ----
      /* Set up the various parts of the system.  Channel feeds start
       * processes so call PROCsetup before ICDsetup.  NNTP needs to know
       * if it's a slave, so call RCsetup before NCsetup. */
!     (void)xsignal(SIGTERM, CatchTerminate);
  #if	defined(SIGDANGER)
!     (void)xsignal(SIGDANGER, CatchTerminate);
  #endif	/* defined(SIGDANGER) */
      CHANsetup(i);
      PROCsetup(10);
diff -rc ../inn-1999-09-13_03-00/innd/proc.c ./innd/proc.c
*** ../inn-1999-09-13_03-00/innd/proc.c	Tue Apr 14 15:28:16 1998
--- ./innd/proc.c	Mon Sep 13 13:15:46 1999
***************
*** 55,61 ****
      int			s;
  {
      PROCreap();
!     (void)signal(s, PROCcatchsignal);
  }
  
  
--- 55,63 ----
      int			s;
  {
      PROCreap();
! #ifndef USE_SIGACTION
!     (void)xsignal(s, PROCcatchsignal);
! #endif
  }
  
  
***************
*** 175,181 ****
  	*pp = PROCnull;
  
  #if	defined(SIGCHLD)
!     (void)signal(SIGCHLD, PROCcatchsignal);
  #endif	/* defined(SIGCHLD) */
!     (void)signal(SIGPIPE, PROCcatchsignal);
  }
--- 177,183 ----
  	*pp = PROCnull;
  
  #if	defined(SIGCHLD)
!     (void)xsignal(SIGCHLD, PROCcatchsignal);
  #endif	/* defined(SIGCHLD) */
!     (void)xsignal(SIGPIPE, PROCcatchsignal);
  }
diff -rc ../inn-1999-09-13_03-00/lib/Makefile ./lib/Makefile
*** ../inn-1999-09-13_03-00/lib/Makefile	Thu Sep  9 02:59:34 1999
--- ./lib/Makefile	Mon Sep 13 13:15:46 1999
***************
*** 19,25 ****
  	makedir.c md5.c nonblocking.c parsedate.c perl.c pread.c pwrite.c \
  	radix32.c readin.c remopen.c reservedfd.c resource.c rwlock.c \
  	sendarticle.c sendpass.c tempname.c waitnb.c wildmat.c xfopena.c \
! 	xmalloc.c xmemerr.c xrealloc.c xwrite.c xwritev.c
  OBJECTS = $(MISSING_OBJ) \
  	argparse.o checkart.o cleanfrom.o clientactive.o clientlib.o \
  	closeonexec.o concat.o conffile.o dbz.o defdist.o findheader.o \
--- 19,25 ----
  	makedir.c md5.c nonblocking.c parsedate.c perl.c pread.c pwrite.c \
  	radix32.c readin.c remopen.c reservedfd.c resource.c rwlock.c \
  	sendarticle.c sendpass.c tempname.c waitnb.c wildmat.c xfopena.c \
! 	xmalloc.c xmemerr.c xrealloc.c xsignal.c xwrite.c xwritev.c
  OBJECTS = $(MISSING_OBJ) \
  	argparse.o checkart.o cleanfrom.o clientactive.o clientlib.o \
  	closeonexec.o concat.o conffile.o dbz.o defdist.o findheader.o \
***************
*** 28,34 ****
  	makedir.o md5.o nonblocking.o parsedate.o pread.o pwrite.o radix32.o \
  	readin.o remopen.o reservedfd.o resource.o rwlock.o sendarticle.o \
  	sendpass.o tempname.o waitnb.o wildmat.o xfopena.o xmalloc.o \
! 	xmemerr.o xrealloc.o xwrite.o xwritev.o
  LOBJECTS	= $(OBJECTS:.o=.lo)
  
  all:			libinn.$(EXTLIB) perl.o ../include/autoconfig.h
--- 28,34 ----
  	makedir.o md5.o nonblocking.o parsedate.o pread.o pwrite.o radix32.o \
  	readin.o remopen.o reservedfd.o resource.o rwlock.o sendarticle.o \
  	sendpass.o tempname.o waitnb.o wildmat.o xfopena.o xmalloc.o \
! 	xmemerr.o xrealloc.o xsignal.o xwrite.o xwritev.o
  LOBJECTS	= $(OBJECTS:.o=.lo)
  
  all:			libinn.$(EXTLIB) perl.o ../include/autoconfig.h
diff -rc ../inn-1999-09-13_03-00/nnrpd/nnrpd.c ./nnrpd/nnrpd.c
*** ../inn-1999-09-13_03-00/nnrpd/nnrpd.c	Fri Jul 30 20:52:35 1999
--- ./nnrpd/nnrpd.c	Mon Sep 13 13:15:46 1999
***************
*** 517,523 ****
      int		s;
  {
      ChangeTrace = TRUE;
!     (void)signal(s, ToggleTrace);
  }
  
  /*
--- 517,525 ----
      int		s;
  {
      ChangeTrace = TRUE;
! #ifndef USE_SIGACTION
!     (void)xsignal(s, ToggleTrace);
! #endif
  }
  
  /*
***************
*** 545,551 ****
         if (pid <= 0)
         	    break;
      }
!     (void)signal(s, WaitChild);
  }
  
  STATIC void SetupDaemon(void) {
--- 547,555 ----
         if (pid <= 0)
         	    break;
      }
! #ifndef USE_SIGACTION
!     (void)xsignal(s, WaitChild);
! #endif
  }
  
  STATIC void SetupDaemon(void) {
***************
*** 800,806 ****
  	fclose(pidfile);
  
  	/* Set signal handle to care for dead children */
! 	(void)signal(SIGCHLD, WaitChild);
  	SetupDaemon();
   
  	TITLEset("nnrpd: accepting connections");
--- 804,810 ----
  	fclose(pidfile);
  
  	/* Set signal handle to care for dead children */
! 	(void)xsignal(SIGCHLD, WaitChild);
  	SetupDaemon();
   
  	TITLEset("nnrpd: accepting connections");
***************
*** 841,847 ****
  	}
  
  	/* Only automatically reap children in the listening process */
! 	(void)signal(SIGCHLD, SIG_DFL);
   
      } else {
  	SetupDaemon();
--- 845,851 ----
  	}
  
  	/* Only automatically reap children in the listening process */
! 	(void)xsignal(SIGCHLD, SIG_DFL);
   
      } else {
  	SetupDaemon();
***************
*** 868,877 ****
      strcpy (LogName, "?");
  
      /* Catch SIGPIPE so that we can exit out of long write loops */
!     (void)signal(SIGPIPE, CatchPipe);
  
      /* Arrange to toggle tracing. */
!     (void)signal(SIGHUP, ToggleTrace);
  
      /* Get permissions and see if we can talk to this client */
      StartConnection();
--- 872,881 ----
      strcpy (LogName, "?");
  
      /* Catch SIGPIPE so that we can exit out of long write loops */
!     (void)xsignal(SIGPIPE, CatchPipe);
  
      /* Arrange to toggle tracing. */
!     (void)xsignal(SIGHUP, ToggleTrace);
  
      /* Get permissions and see if we can talk to this client */
      StartConnection();
diff -rc ../inn-1999-09-13_03-00/storage/buffindexed/buffindexed.c ./storage/buffindexed/buffindexed.c
*** ../inn-1999-09-13_03-00/storage/buffindexed/buffindexed.c	Fri Sep 10 02:57:47 1999
--- ./storage/buffindexed/buffindexed.c	Mon Sep 13 20:14:57 1999
***************
*** 257,262 ****
--- 257,280 ----
  STATIC void *ovopensearch(char *group, int low, int high, BOOL needov);
  STATIC void ovclosesearch(void *handle, BOOL freeblock);
  
+ STATIC OFFSET_T mmappwrite(int fd, void *buf, OFFSET_T nbyte, OFFSET_T offset) {
+   int		pagefudge, len;
+   OFFSET_T	mmapoffset;
+   caddr_t	addr;
+ 
+   pagefudge = offset % pagesize;
+   mmapoffset = offset - pagefudge;
+   len = pagefudge + nbyte;
+ 
+   if ((addr = mmap((caddr_t) 0, len, PROT_READ|PROT_WRITE, MAP_SHARED, fd, mmapoffset)) == (caddr_t) -1) {
+     return -1;
+   }
+   memcpy(addr+pagefudge, buf, nbyte);
+   munmap(addr, len);
+   return nbyte;
+ }
+ 
+ 
  STATIC BOOL ovparse_part_line(char *l) {
    char		*p;
    struct stat	sb;
***************
*** 697,703 ****
  /* just search ov, do not set curindex */
  STATIC OV getsrchov(OV ov, ARTNUM artnum, OVINDEXHEAD *ovihp, SRCH type) {
    OVBUFF	*ovbuff;
!   OVINDEXHEAD	ovindexhead;
  
    if (type != SRCH_FRWD && type != SRCH_BKWD)
      return ovnull;
--- 715,724 ----
  /* just search ov, do not set curindex */
  STATIC OV getsrchov(OV ov, ARTNUM artnum, OVINDEXHEAD *ovihp, SRCH type) {
    OVBUFF	*ovbuff;
!   OVINDEXHEAD	*ovindexhead;
!   caddr_t	addr;
!   int		pagefudge, len;
!   OFFSET_T	offset, mmapoffset;
  
    if (type != SRCH_FRWD && type != SRCH_BKWD)
      return ovnull;
***************
*** 705,723 ****
      ovbuff = getovbuff(ov);
      if (ovbuff == NULL)
        return ovnull;
!     if (pread(ovbuff->fd, (POINTER)&ovindexhead, sizeof(ovindexhead), ovbuff->base + (ov.blocknum * OV_BLOCKSIZE)) != sizeof(ovindexhead)) {
!       syslog(L_ERROR, "%s: could not read index record index '%d', blocknum '%d': %m", LocalLogName, ov.index, ov.blocknum);
!       return ovnull;
      }
!     if (ovindexhead.base <= artnum && ovindexhead.base + OVINDEXMAX - ovindexhead.baseoffset > artnum) {
        if (ovihp)
! 	*ovihp = ovindexhead;
        return ov;
      }
      if (type == SRCH_FRWD)
!       ov = ovindexhead.next;
      else
!       ov = ovindexhead.prev;
    }
    return ovnull;
  }
--- 726,754 ----
      ovbuff = getovbuff(ov);
      if (ovbuff == NULL)
        return ovnull;
! 
!     offset = ovbuff->base + (ov.blocknum * OV_BLOCKSIZE);
!     pagefudge = offset % pagesize;
!     mmapoffset = offset - pagefudge;
!     len = pagefudge + OV_BLOCKSIZE;
! 
!     if ((addr = mmap((caddr_t) 0, len, PROT_READ, MAP_SHARED, ovbuff->fd, mmapoffset)) == (caddr_t) -1) {
! 	syslog(L_ERROR, "%s: could not mmap index record index '%d', blocknum '%d': %m", LocalLogName, ov.index, ov.blocknum);
! 	return ovnull;
      }
!     ovindexhead = (OVINDEXHEAD *)(addr + pagefudge);
! 
!     if (ovindexhead->base <= artnum && ovindexhead->base + OVINDEXMAX - ovindexhead->baseoffset > artnum) {
        if (ovihp)
! 	*ovihp = *ovindexhead;
!       munmap(addr, len);
        return ov;
      }
      if (type == SRCH_FRWD)
!       ov = ovindexhead->next;
      else
!       ov = ovindexhead->prev;
!     munmap(addr, len);
    }
    return ovnull;
  }
***************
*** 1231,1237 ****
      ovblock.ovindexhead.prev = ovnull;
      ovblock.ovindexhead.next = ovnull;
      ovblock.ovindexhead.base = base;
!     if (pwrite(ovbuff->fd, (POINTER)&ovblock, sizeof(ovblock), ovbuff->base + (ov.blocknum * OV_BLOCKSIZE)) != sizeof(ovblock)) {
        syslog(L_ERROR, "%s: ovsetcurindexblock could not initialize ovbuff block index '%d', blocknum '%d': %m", LocalLogName, ov.index, ov.blocknum);
        return FALSE;
      }
--- 1262,1268 ----
      ovblock.ovindexhead.prev = ovnull;
      ovblock.ovindexhead.next = ovnull;
      ovblock.ovindexhead.base = base;
!     if (mmappwrite(ovbuff->fd, (POINTER)&ovblock, sizeof(ovblock), ovbuff->base + (ov.blocknum * OV_BLOCKSIZE)) != sizeof(ovblock)) {
        syslog(L_ERROR, "%s: ovsetcurindexblock could not initialize ovbuff block index '%d', blocknum '%d': %m", LocalLogName, ov.index, ov.blocknum);
        return FALSE;
      }
***************
*** 1343,1349 ****
      abort();
    }
  #endif /* OV_DEBUG */
!   if (pwrite(ovbuff->fd, data, len, ovbuff->base + ge->curdata.blocknum * OV_BLOCKSIZE + ge->curoffset) != len) {
      syslog(L_ERROR, "%s: could not append overview record index '%d', blocknum '%d': %m", LocalLogName, ge->curdata.index, ge->curdata.blocknum);
      return FALSE;
    }
--- 1374,1380 ----
      abort();
    }
  #endif /* OV_DEBUG */
!   if (mmappwrite(ovbuff->fd, data, len, ovbuff->base + ge->curdata.blocknum * OV_BLOCKSIZE + ge->curoffset) != len) {
      syslog(L_ERROR, "%s: could not append overview record index '%d', blocknum '%d': %m", LocalLogName, ge->curdata.index, ge->curdata.blocknum);
      return FALSE;
    }
***************
*** 1374,1380 ****
      abort();
    }
  #endif /* OV_DEBUG */
!   if (pwrite(ovbuff->fd, &ie, sizeof(ie), ovbuff->base + ge->curindex.blocknum * OV_BLOCKSIZE + sizeof(OVINDEXHEAD) + sizeof(ie) * (artnum - ge->baseinblock + baseoffset)) != sizeof(ie)) {
      syslog(L_ERROR, "%s: could not write index record index '%d', blocknum '%d': %m", LocalLogName, ge->curindex.index, ge->curindex.blocknum);
      return TRUE;
    }
--- 1405,1411 ----
      abort();
    }
  #endif /* OV_DEBUG */
!   if (mmappwrite(ovbuff->fd, &ie, sizeof(ie), ovbuff->base + ge->curindex.blocknum * OV_BLOCKSIZE + sizeof(OVINDEXHEAD) + sizeof(ie) * (artnum - ge->baseinblock + baseoffset)) != sizeof(ie)) {
      syslog(L_ERROR, "%s: could not write index record index '%d', blocknum '%d': %m", LocalLogName, ge->curindex.index, ge->curindex.blocknum);
      return TRUE;
    }
*** /dev/null	Tue Sep 14 16:01:01 1999
--- ./lib/xsignal.c	Tue Sep 14 00:04:44 1999
***************
*** 0 ****
--- 1,36 ----
+ /*
+ **  Provides a 'reliable' implementation of signal() for SYSV-derived systems
+ */
+ #include <signal.h>
+ #include "configdata.h"
+ #include "clibrary.h"
+ 
+ #ifdef USE_SIGACTION
+ 
+ void (*xsignal(int signum, void (*sigfunc)(int )))(int )
+ {
+ 	struct sigaction act, oact;
+ 
+ 	act.sa_handler = sigfunc;
+ 	sigemptyset(&act.sa_mask);
+ 
+ #ifdef SA_RESTART
+ 	act.sa_flags = SA_RESTART;
+ #else
+ 	act.sa_flags = 0;
+ #endif
+ 
+ 	if (sigaction(signum, &act, &oact) < 0) {
+ 		return SIG_ERR;
+ 	}
+ 	return oact.sa_handler;
+ }
+ 
+ #else
+ 
+ void (*xsignal(int signum, void (*sigfunc)(int )))(int )
+ {
+ 	return signal(signum, sigfunc);
+ }
+ 
+ #endif


More information about the inn-workers mailing list