Deliver 2.0 Patch #12

Chip Salzenberg chip at tct.uucp
Wed Aug 8 05:52:40 AEST 1990


Changes in patch #12 to Deliver 2.0:

1.  If kernel locking and modern (three-parameter) open() are
    available, Deliver no longer uses lock files for the logs and
    undeliverable mail storage ("Undel.mail").  In config.h, you must
    now specify your kernel locking method with the LOCK_XXX macros
    and your mailbox locking strategy with the ML_XXX macros.

    This change should avoid the problem I had when a stale log lock
    file caused logging to slow to a crawl.  However, stale lock files
    can still result in slow delivery to user mailboxes.  A complete
    solution is not possible as long as lock files are used.

2.  In PL11, if a delivery file said DROP, an errant debugging message
    would be printed, causing an error log.  Apparently, no one uses
    the DROP feature, or I'd have gotten a bug report by now.  :-)

3.  A typo caused compilation errors if MBX_NAME is defined instead of
    MBX_DIR.  This feature, too, must be little-used, since this bug
    has existed since Deliver 1.0 PL0.  Thanks to Rainer Orth for
    the bug report.

4.  The header program now avoids passing negative values to the
    isxxx() macros.  Sigh.

5.  Flags shared by lint and cc are now in $(DEFS).


NOTE: If you have made custom changes to Makefile, config.h or lock.c,
I'd suggest backing them out temporarily before applying this patch.
Otherwise, you're likely to have some patches rejected.


This patch contains changes to the following files:
	patchlevel.h
	Makefile
	config.h
	dfile.c
	header.c
	lock.c
	log.c
	mbox.c
	misc.h
	subs.c
	sysdep.c

Index: patchlevel.h
Prereq: 11
***************
*** 1,1 ****
! #define PATCHLEVEL 11
--- 1,1 ----
! #define PATCHLEVEL 12

Index: Makefile
***************
*** 1,3 ****
! # $Header: Makefile,v 2.7 90/05/09 12:26:11 chip Exp $
  #
  # Makefile for deliver
--- 1,3 ----
! # $Header: Makefile,v 2.9 90/08/06 18:39:30 chip Exp $
  #
  # Makefile for deliver
***************
*** 32,37 ****
  #       Your favorite C compiler.
  #
! # CFLAGS
! #       Compile-time flags to cc.
  #       For BSD systems, include "-DBSD".
  #       For USG (System III and System V) systems, include "-DUSG".
--- 32,37 ----
  #       Your favorite C compiler.
  #
! # DEFS
! #       Compile-time flags to cc and lint.
  #       For BSD systems, include "-DBSD".
  #       For USG (System III and System V) systems, include "-DUSG".
***************
*** 38,41 ****
--- 38,44 ----
  #       For Xenix systems, don't define anything.
  #
+ # CFLAGS
+ #	Compile-time flags to cc; should include DEFS.
+ #
  # LDFLAGS
  #       Link-time flags to cc.  The -i flag creates pure (sharable) code.
***************
*** 58,71 ****
  #
  
! SHELL = /bin/sh
! COPY =  cp
! SHAR =  shar
! CC = cc
! CFLAGS = -O
! LDFLAGS = -i
! LIBS = -lx
! LINT = lint -x
! BIN =   /usr/bin
! DELSHAR =  deliver.sh
  
  #
--- 61,75 ----
  #
  
! SHELL	= /bin/sh
! COPY	= cp
! SHAR	= shar
! CC	= cc
! DEFS	= -DUSG
! CFLAGS	= -O $(DEFS)
! LDFLAGS	=
! LIBS	=
! LINT	= lint -x
! BIN	= /usr/bin
! DELSHAR	= deliver
  
  #
***************
*** 184,194 ****
  
  deliver.lint: $(HDRS) $(DELSRCC) $(COMSRCS)
! 	$(LINT) $(DELSRCC) $(COMSRCS) $(LIBS) >$@
  
  header.lint: $(HDRSRCS) $(COMSRCS)
! 	$(LINT) $(HDRSRCS) $(COMSRCS) $(LIBS) >$@
  
  uid.lint: config.h $(UIDSRCS) $(COMSRCS)
! 	$(LINT) $(UIDSRCS) $(COMSRCS) $(LIBS) >$@
  
  clean::
--- 188,198 ----
  
  deliver.lint: $(HDRS) $(DELSRCC) $(COMSRCS)
! 	$(LINT) $(DEFS) $(DELSRCC) $(COMSRCS) $(LIBS) >$@
  
  header.lint: $(HDRSRCS) $(COMSRCS)
! 	$(LINT) $(DEFS) $(HDRSRCS) $(COMSRCS) $(LIBS) >$@
  
  uid.lint: config.h $(UIDSRCS) $(COMSRCS)
! 	$(LINT) $(DEFS) $(UIDSRCS) $(COMSRCS) $(LIBS) >$@
  
  clean::

Index: config.h
***************
*** 1,3 ****
! /* $Header: config.h,v 2.10 90/05/03 10:28:48 chip Exp $
   *
   * Deliver configuration.
--- 1,3 ----
! /* $Header: config.h,v 2.13 90/08/06 18:41:01 chip Exp $
   *
   * Deliver configuration.
***************
*** 4,7 ****
--- 4,16 ----
   *
   * $Log:	config.h,v $
+  * Revision 2.13  90/08/06  18:41:01  chip
+  * Use LOCK_XXX; make LOCK_ANY available to all modules.
+  * 
+  * Revision 2.12  90/08/06  17:24:18  chip
+  * Separate kernel locking features from their use on mailboxes.
+  * 
+  * Revision 2.11  90/08/01  13:11:07  chip
+  * SCO Unix locates mailboxes like Xenix.
+  * 
   * Revision 2.10  90/05/03  10:28:48  chip
   * Add UUCP configuration.
***************
*** 115,121 ****
  
  /*----------------------------------------------------------------------
   * Various kinds of mailbox locking.
   * You may define one or both of ML_DOTLOCK and ML_DOTMLK.
!  * You may define no more than one of ML_FCNTL, ML_LOCKF and ML_LOCKING.
   *
   * File creation locking:
--- 124,153 ----
  
  /*----------------------------------------------------------------------
+  * Various kinds of kernel file/record locking.
+  *
+  * You may define no more than one of these:
+  *     LOCK_LOCKF     lockf(F_LOCK, ...)     (SVID systems only)
+  *     LOCK_FCNTL     fcntl(F_SETLKW, ...)   (SVID systems only)
+  *     LOCK_FLOCK     flock(..., LOCK_EX)    (BSD systems only)
+  *     LOCK_LOCKING   locking(LK_LOCK, ...)  (Xenix systems only)
+  */
+ 
+ #ifdef M_XENIX
+ #define LOCK_LOCKING
+ #else
+ #ifdef USG
+ #define LOCK_LOCKF
+ #else
+ #ifdef BSD
+ #define LOCK_FLOCK
+ #endif
+ #endif
+ #endif
+ 
+ /*----------------------------------------------------------------------
   * Various kinds of mailbox locking.
   * You may define one or both of ML_DOTLOCK and ML_DOTMLK.
!  * You may define ML_KERNEL, or not, as you please.
!  * Locking methods are cumulative.
   *
   * File creation locking:
***************
*** 124,130 ****
   *
   * Kernel record locking:
!  *     ML_FCNTL     lock with fcntl(F_SETLKW)   (SVID systems only)
!  *     ML_LOCKF     lock with lockf(F_LOCK)     (SVID systems only)
!  *     ML_LOCKING   lock with locking(LK_LOCK)  (Xenix systems only)
   */
  
--- 156,160 ----
   *
   * Kernel record locking:
!  *     ML_KERNEL    lock with kernel locking primitives.
   */
  
***************
*** 131,135 ****
  #ifdef M_XENIX
  #define ML_DOTMLK
- #define ML_LOCKING
  #else
  #define ML_DOTLOCK
--- 161,164 ----
***************
*** 136,139 ****
--- 165,170 ----
  #endif
  
+ #define ML_KERNEL
+ 
  /*----------------------------------------------------------------------
   * Maximum filename length.
***************
*** 193,197 ****
   */
  
! #ifdef USG
  #define HAS_VPRINTF
  #endif
--- 224,228 ----
   */
  
! #if __STDC__ || defined(USG)
  #define HAS_VPRINTF
  #endif
***************
*** 291,295 ****
   */
  
! #if defined(USG) && !defined(M_XENIX)
  /* #define MBX_NAME   "mbox" */
  #define MBX_DIR     "/usr/mail"
--- 322,326 ----
   */
  
! #if defined(USG) && !defined(M_XENIX) && !defined(M_UNIX)
  /* #define MBX_NAME   "mbox" */
  #define MBX_DIR     "/usr/mail"

Index: dfile.c
***************
*** 1,3 ****
! /* $Header: dfile.c,v 2.7 90/03/06 12:21:12 chip Exp $
   *
   * Filter destination(s) through delivery file(s).
--- 1,3 ----
! /* $Header: dfile.c,v 2.8 90/08/01 12:41:37 chip Exp $
   *
   * Filter destination(s) through delivery file(s).
***************
*** 4,7 ****
--- 4,10 ----
   *
   * $Log:	dfile.c,v $
+  * Revision 2.8  90/08/01  12:41:37  chip
+  * Print diagnostic message only if verbose.
+  * 
   * Revision 2.7  90/03/06  12:21:12  chip
   * Move logging into log.c and address parsing into addr.c.
***************
*** 563,567 ****
  		if (strcmp(buf, DFILE_DROP) == 0)
  		{
! 			message("\tDelivery file says OK to drop\n");
  			++linecount;
  			continue;
--- 566,571 ----
  		if (strcmp(buf, DFILE_DROP) == 0)
  		{
! 			if (verbose)
! 				message("\tDelivery file says OK to drop\n");
  			++linecount;
  			continue;

Index: header.c
***************
*** 1,3 ****
! /* $Header: header.c,v 2.5 89/11/10 12:23:54 network Exp $
   *
   * A program to parse RFC 822 mail/news headers.
--- 1,3 ----
! /* $Header: header.c,v 2.6 90/08/01 12:26:15 chip Exp $
   *
   * A program to parse RFC 822 mail/news headers.
***************
*** 18,21 ****
--- 18,24 ----
   *
   * $Log:	header.c,v $
+  * Revision 2.6  90/08/01  12:26:15  chip
+  * Don't pass negative values to isxxx() macros.
+  * 
   * Revision 2.5  89/11/10  12:23:54  network
   * Delintify.
***************
*** 199,203 ****
  
  		p = buf;
! 		while (isupper(*p) || islower(*p) || isdigit(*p) || *p == '-')
  			++p;
  		if (p == buf || *p != ':')
--- 202,206 ----
  
  		p = buf;
! 		while (isalnum(*p & 0xFF) || *p == '-')
  			++p;
  		if (p == buf || *p != ':')
***************
*** 289,294 ****
  	while (n-- > 0)
  	{
! 		c = *s++;
! 		d = *t++;
  		if ((c == 0) && (d == 0))
  			break;
--- 292,297 ----
  	while (n-- > 0)
  	{
! 		c = *s++ & 0xFF;
! 		d = *t++ & 0xFF;
  		if ((c == 0) && (d == 0))
  			break;

Index: lock.c
***************
*** 1,3 ****
! /* $Header: lock.c,v 2.2 90/05/03 10:13:56 chip Exp $
   *
   * Mailbox locking.
--- 1,3 ----
! /* $Header: lock.c,v 2.5 90/08/07 14:46:16 chip Exp $
   *
   * Mailbox locking.
***************
*** 5,8 ****
--- 5,18 ----
   *
   * $Log:	lock.c,v $
+  * Revision 2.5  90/08/07  14:46:16  chip
+  * Separate mailbox locking from locking algorithms.
+  * 
+  * Revision 2.4  90/08/06  18:42:17  chip
+  * Use LOCK_XXX and LOCK_ANY.
+  * 
+  * Revision 2.3  90/08/06  17:24:53  chip
+  * Separate kernel locking features from their use on mailboxes.
+  * Add log_lock() and log_unlock().
+  * 
   * Revision 2.2  90/05/03  10:13:56  chip
   * Really unlock file descriptors in fd_unlock().  (!)
***************
*** 19,49 ****
  
  /*
!  * Validate the locking configuration.
   */
  
! #if (defined(ML_FCNTL) + defined(ML_LOCKF) + defined(ML_LOCKING)) > 1
!   lose! "Only one of ML_FCNTL, ML_LOCKF and ML_LOCKING may be defined.";
  #endif
  
  /*
!  * Support for the lockf() system call.
   */
  
! #ifdef ML_LOCKF
! #include <unistd.h>
! #define SIMPLE_LOCK "lockf"
! #define LOCKFD(fd, size)    lockf(fd, F_LOCK, size)
! #define UNLOCKFD(fd, size)  lockf(fd, F_ULOCK, size)
! #endif /* ML_LOCKF */
  
  /*
!  * Setup for the locking() system call.
   */
  
! #ifdef ML_LOCKING
  #include <sys/locking.h>
  #define SIMPLE_LOCK "locking"
! #define LOCKFD(fd, size)    locking(fd, LK_LOCK, size)
! #define UNLOCKFD(fd, size)  locking(fd, LK_UNLCK, size)
  #endif
  
--- 29,62 ----
  
  /*
!  * Support for the lockf() system call.
   */
  
! #ifdef LOCK_LOCKF
! #include <unistd.h>
! #define SIMPLE_LOCK "lockf"
! #define LOCKFD(fd)	lockf(fd, F_LOCK, 0L)
! #define UNLOCKFD(fd)	lockf(fd, F_ULOCK, 0L)
  #endif
  
  /*
!  * Support for the flock() system call.
   */
  
! #ifdef LOCK_FLOCK
! #include <sys/file.h>
! #define SIMPLE_LOCK "flock"
! #define LOCKFD(fd)	flock(fd, LOCK_EX)
! #define UNLOCKFD(fd)	flock(fd, LOCK_UN)
! #endif
  
  /*
!  * Support for the locking() system call.
   */
  
! #ifdef LOCK_LOCKING
  #include <sys/locking.h>
  #define SIMPLE_LOCK "locking"
! #define LOCKFD(fd)	locking(fd, LK_LOCK, 0L)
! #define UNLOCKFD(fd)	locking(fd, LK_UNLCK, 0L)
  #endif
  
***************
*** 60,63 ****
--- 73,106 ----
  
  /*----------------------------------------------------------------------
+  * Lock a mailbox by fd.
+  */
+ 
+ int
+ mbox_fdlock(fd)
+ int     fd;
+ {
+ #ifdef ML_KERNEL
+ 	return k_lock(fd);
+ #else
+ 	return 0;
+ #endif
+ }
+ 
+ /*----------------------------------------------------------------------
+  * Unlock a mailbox by fd.
+  */
+ 
+ int
+ mbox_fdunlock(fd)
+ int     fd;
+ {
+ #ifdef ML_KERNEL
+ 	return k_unlock(fd);
+ #else
+ 	return 0;
+ #endif
+ }
+ 
+ /*----------------------------------------------------------------------
   * Lock a mailbox by name.
   *
***************
*** 68,72 ****
  
  int
! name_lock(name)
  char    *name;
  {
--- 111,115 ----
  
  int
! mbox_nlock(name)
  char    *name;
  {
***************
*** 78,81 ****
--- 121,129 ----
  #endif
  
+ #ifdef SAFE_UPDATE
+ 	if (strcmp(name, MBX_UNDEL) == 0)
+ 		return 0;
+ #endif
+ 
  #ifdef ML_DOTLOCK
  	if ((dotlock = dotlock_name(name)) == NULL
***************
*** 103,107 ****
  
  int
! name_unlock(name)
  char    *name;
  {
--- 151,155 ----
  
  int
! mbox_nunlock(name)
  char    *name;
  {
***************
*** 115,118 ****
--- 163,171 ----
  #endif
  
+ #ifdef SAFE_UPDATE
+ 	if (strcmp(name, MBX_UNDEL) == 0)
+ 		return 0;
+ #endif
+ 
  #ifdef ML_DOTLOCK
  	if ((dotlock = dotlock_name(name)) == NULL
***************
*** 131,237 ****
  
  /*----------------------------------------------------------------------
!  * Lock a file descriptor.
   */
  
  int
! fd_lock(fd)
! int     fd;
  {
! #ifdef ML_FCNTL
! 	struct flock fl;
! 
! 	fl.l_type = F_WRLCK;
! 	fl.l_whence = 0;
! 	fl.l_start = 0L;
! 	fl.l_len = 0L;
! 
! 	if (fcntl(fd, F_SETLKW, &fl) == -1)
! 	{
! 		syserr("can't lock with fcntl()");
! 		return -1;
! 	}
! 
! 	if (verbose)
! 		message("locked mailbox with fcntl()\n");
! #endif /* ML_FCNTL */
! 
! #ifdef SIMPLE_LOCK
! 	long    pos;
! 
! 	if ((pos = lseek(fd, 0L, 0)) == -1)
! 	{
! 		syserr("can't seek in mailbox");
! 		return -1;
! 	}
! 	if (LOCKFD(fd, 0L) == -1)
! 	{
! 		syserr("can't lock with %s()", SIMPLE_LOCK);
! 		return -1;
! 	}
! 	if (lseek(fd, pos, 0) == -1)
! 	{
! 		syserr("can't seek in mailbox");
! 		return -1;
! 	}
! 
! 	if (verbose)
! 		message("locked mailbox with %s()\n", SIMPLE_LOCK);
! #endif /* SIMPLE_LOCK */
! 
! 	/* Default: success */
  	return 0;
  }
  
- /*----------------------------------------------------------------------
-  * Unlock a file descriptor.
-  */
- 
  int
! fd_unlock(fd)
! int     fd;
  {
! #ifdef ML_FCNTL
! 	struct flock fl;
! 
! 	fl.l_type = F_UNLCK;
! 	fl.l_whence = 0;
! 	fl.l_start = 0L;
! 	fl.l_len = 0L;
! 
! 	if (fcntl(fd, F_SETLKW, &fl) == -1)
! 	{
! 		syserr("can't unlock with fcntl()");
! 		return -1;
! 	}
! 
! 	if (verbose)
! 		message("unlocked mailbox with fcntl()\n");
! #endif /* ML_FCNTL */
! 
! #ifdef SIMPLE_LOCK
! 	long    pos;
! 
! 	if ((pos = lseek(fd, 0L, 0)) == -1)
! 	{
! 		syserr("can't seek in mailbox");
! 		return -1;
! 	}
! 	if (UNLOCKFD(fd, 0L) == -1)
! 	{
! 		syserr("can't unlock with %s()", SIMPLE_LOCK);
! 		return -1;
! 	}
! 	if (lseek(fd, pos, 0) == -1)
! 	{
! 		syserr("can't seek in mailbox");
! 		return -1;
! 	}
! 
! 	if (verbose)
! 		message("unlocked mailbox with %s()\n", SIMPLE_LOCK);
! #endif /* SIMPLE_LOCK */
! 
! 	/* Default: success */
  	return 0;
  }
  
--- 184,212 ----
  
  /*----------------------------------------------------------------------
!  * Lock and unlock the Deliver logs.
!  *
!  * If kernel locking and modern open() are available, these
!  * routines are no-ops, since logs will be kernel-locked before
!  * they are written.
   */
  
  int
! log_lock()
  {
! #ifdef SAFE_UPDATE
  	return 0;
+ #else
+ 	return create_lockfile(LOGLOCK);
+ #endif
  }
  
  int
! log_unlock()
  {
! #ifdef SAFE_UPDATE
  	return 0;
+ #else
+ 	return remove_lockfile(LOGLOCK);
+ #endif
  }
  
***************
*** 316,320 ****
  {
  #ifndef O_CREAT
! 	char    *othername, *p;
  #endif
  	int     fd, tries;
--- 291,295 ----
  {
  #ifndef O_CREAT
! 	char    *othername;
  #endif
  	int     fd, tries;
***************
*** 388,391 ****
--- 363,472 ----
  		message("removed lockfile %s\n", name);
  
+ 	return 0;
+ }
+ 
+ /*----------------------------------------------------------------------
+  * Lock a file descriptor using kernel locking.
+  */
+ 
+ int
+ k_lock(fd)
+ int	fd;
+ {
+ #ifdef LOCK_FCNTL
+ 	struct flock fl;
+ 
+ 	fl.l_type = F_WRLCK;
+ 	fl.l_whence = 0;
+ 	fl.l_start = 0L;
+ 	fl.l_len = 0L;
+ 
+ 	if (fcntl(fd, F_SETLKW, &fl) == -1)
+ 	{
+ 		syserr("can't lock with fcntl()");
+ 		return -1;
+ 	}
+ 
+ 	if (verbose)
+ 		message("locked with fcntl()\n");
+ #endif /* LOCK_FCNTL */
+ 
+ #ifdef SIMPLE_LOCK
+ 	long    pos;
+ 
+ 	if ((pos = lseek(fd, 0L, 0)) == -1)
+ 	{
+ 		syserr("can't seek before %s()", SIMPLE_LOCK);
+ 		return -1;
+ 	}
+ 	if (LOCKFD(fd) == -1)
+ 	{
+ 		syserr("can't lock with %s()", SIMPLE_LOCK);
+ 		return -1;
+ 	}
+ 	if (lseek(fd, pos, 0) == -1)
+ 	{
+ 		syserr("can't seek after %s()", SIMPLE_LOCK);
+ 		return -1;
+ 	}
+ 
+ 	if (verbose)
+ 		message("locked with %s()\n", SIMPLE_LOCK);
+ #endif /* SIMPLE_LOCK */
+ 
+ 	/* Default: success */
+ 	return 0;
+ }
+ 
+ /*----------------------------------------------------------------------
+  * Unlock a file descriptor using kernel locking.
+  */
+ 
+ int
+ k_unlock(fd)
+ int     fd;
+ {
+ #ifdef LOCK_FCNTL
+ 	struct flock fl;
+ 
+ 	fl.l_type = F_UNLCK;
+ 	fl.l_whence = 0;
+ 	fl.l_start = 0L;
+ 	fl.l_len = 0L;
+ 
+ 	if (fcntl(fd, F_SETLKW, &fl) == -1)
+ 	{
+ 		syserr("can't unlock with fcntl()");
+ 		return -1;
+ 	}
+ 
+ 	if (verbose)
+ 		message("unlocked with fcntl()\n");
+ #endif /* LOCK_FCNTL */
+ 
+ #ifdef SIMPLE_LOCK
+ 	long    pos;
+ 
+ 	if ((pos = lseek(fd, 0L, 0)) == -1)
+ 	{
+ 		syserr("can't seek before %s()", SIMPLE_LOCK);
+ 		return -1;
+ 	}
+ 	if (UNLOCKFD(fd) == -1)
+ 	{
+ 		syserr("can't unlock with %s()", SIMPLE_LOCK);
+ 		return -1;
+ 	}
+ 	if (lseek(fd, pos, 0) == -1)
+ 	{
+ 		syserr("can't seek after %s()", SIMPLE_LOCK);
+ 		return -1;
+ 	}
+ 
+ 	if (verbose)
+ 		message("unlocked with %s()\n", SIMPLE_LOCK);
+ #endif /* SIMPLE_LOCK */
+ 
+ 	/* Default: success */
  	return 0;
  }

Index: log.c
***************
*** 1,3 ****
! /* $Header: log.c,v 2.3 90/05/03 10:13:31 chip Exp $
   *
   * Deliver logging.
--- 1,3 ----
! /* $Header: log.c,v 2.5 90/08/07 14:47:12 chip Exp $
   *
   * Deliver logging.
***************
*** 4,7 ****
--- 4,13 ----
   *
   * $Log:	log.c,v $
+  * Revision 2.5  90/08/07  14:47:12  chip
+  * Separate mailbox locking from locking algorithms.
+  * 
+  * Revision 2.4  90/08/06  17:25:43  chip
+  * Use kernel locking for log locking if available.
+  * 
   * Revision 2.3  90/05/03  10:13:31  chip
   * Print correct filename when log can't be opened.
***************
*** 133,137 ****
  	 || (errlog && ftell(errlog) > 0))
  	{
! 		if (create_lockfile(LOGLOCK) == 0)
  		{
  #ifdef LOG
--- 139,143 ----
  	 || (errlog && ftell(errlog) > 0))
  	{
! 		if (log_lock() == 0)
  		{
  #ifdef LOG
***************
*** 142,146 ****
  			applog(&errlog, ERRLOG);
  #endif
! 			(void) remove_lockfile(LOGLOCK);
  		}
  	}
--- 148,152 ----
  			applog(&errlog, ERRLOG);
  #endif
! 			(void) log_unlock();
  		}
  	}
***************
*** 151,155 ****
   * We pass a FILE **, so that it can be set to NULL when closed;
   * this is important, since errlog is used by syserr().
!  * Note:  The logfile is ass_u_med to be locked already!
   */
  
--- 157,165 ----
   * We pass a FILE **, so that it can be set to NULL when closed;
   * this is important, since errlog is used by syserr().
!  *
!  * Note:  It is assumed that the caller already called log_lock().
!  * Nowever, on systems where kernel locking and modern open() are
!  * available, log_lock() is just a nop.  We call k_lock() here,
!  * which does the real locking on modern systems.
   */
  
***************
*** 193,197 ****
  	/*
  	 * Open the real logfile, creating it if necessary.
! 	 * Note that there is no race condition since the logs are locked.
  	 */
  
--- 203,210 ----
  	/*
  	 * Open the real logfile, creating it if necessary.
! 	 *
! 	 * Note that there is no race condition here, since if
! 	 * O_CREAT isn't available, the logs are already locked.
! 	 * See log_lock() and log_unlock() in lock.c.
  	 */
  
***************
*** 206,214 ****
  	else
  	{
! 		/* Append the temporary log to the real log. */
  
! 		(void) lseek(fd, 0L, 0);
! 		(void) lseek(realfd, 0L, 2);
! 		(void) copyfd(fd, realfd);
  		(void) close(realfd);
  	}
--- 219,233 ----
  	else
  	{
! 		if (k_lock(realfd) == -1)
! 			syserr("can't lock %s", realfile);
! 		else
! 		{
! 			/* Append the temporary log to the real log. */
  
! 			(void) lseek(fd, 0L, 0);
! 			(void) lseek(realfd, 0L, 2);
! 			(void) copyfd(fd, realfd);
! 			(void) k_unlock(realfd);
! 		}
  		(void) close(realfd);
  	}

Index: mbox.c
***************
*** 1,3 ****
! /* $Header: mbox.c,v 2.5 90/02/23 16:35:55 chip Exp $
   *
   * Finally!  Put the message in the specified mailbox(es).
--- 1,3 ----
! /* $Header: mbox.c,v 2.8 90/08/07 14:47:15 chip Exp $
   *
   * Finally!  Put the message in the specified mailbox(es).
***************
*** 4,7 ****
--- 4,17 ----
   *
   * $Log:	mbox.c,v $
+  * Revision 2.8  90/08/07  14:47:15  chip
+  * Separate mailbox locking from locking algorithms.
+  * 
+  * Revision 2.7  90/08/06  18:42:28  chip
+  * If kernel locking and modern open(), don't use
+  * file locking for undelivered mail.
+  * 
+  * Revision 2.6  90/08/01  12:47:10  chip
+  * Fix typo that broke mailboxes in home directories.
+  * 
   * Revision 2.5  90/02/23  16:35:55  chip
   * \Fix problems determining legality of user references.
***************
*** 214,218 ****
  			MBX_DIR, d->d_name
  #else
! 			d->d_home, MBX_NAME
  #endif
  			);
--- 224,228 ----
  			MBX_DIR, d->d_name
  #else
! 			ct->ct_home, MBX_NAME
  #endif
  			);
***************
*** 232,235 ****
--- 242,247 ----
   * If we have to create the mailbox, give it to the specified user.
   * If "is_sys" is true, then we're writing to a system mailbox.
+  * If kernel locking and modern open() are available, no file locking
+  * is performed on delivery of undelivered mail.
   */
  
***************
*** 250,254 ****
  	}
  
! 	if (name_lock(mailbox) < 0)
  		return -1;
  
--- 262,266 ----
  	}
  
! 	if (mbox_nlock(mailbox) < 0)
  		return -1;
  
***************
*** 327,338 ****
  	if (fd == -1)
  	{
! 		(void) name_unlock(mailbox);
  		return -1;
  	}
  
! 	if (fd_lock(fd) < 0)
  	{
  		(void) close(fd);
! 		(void) name_unlock(mailbox);
  		return -1;
  	}
--- 339,350 ----
  	if (fd == -1)
  	{
! 		(void) mbox_nunlock(mailbox);
  		return -1;
  	}
  
! 	if (mbox_fdlock(fd) < 0)
  	{
  		(void) close(fd);
! 		(void) mbox_nunlock(mailbox);
  		return -1;
  	}
***************
*** 362,369 ****
  	}
  
! 	if (fd_unlock(fd) < 0)
  		ret = -1;
  	(void) close(fd);
! 	if (name_unlock(mailbox) < 0)
  		ret = -1;
  
--- 374,383 ----
  	}
  
! 	if (mbox_fdunlock(fd) < 0)
  		ret = -1;
+ 
  	(void) close(fd);
! 
! 	if (mbox_nunlock(mailbox) < 0)
  		ret = -1;
  

Index: misc.h
***************
*** 1,3 ****
! /* $Header: misc.h,v 2.4 89/12/19 16:28:05 network Exp $
   *
   * Miscellaneous definitions.
--- 1,3 ----
! /* $Header: misc.h,v 2.7 90/08/07 14:45:51 chip Exp $
   *
   * Miscellaneous definitions.
***************
*** 4,7 ****
--- 4,16 ----
   *
   * $Log:	misc.h,v $
+  * Revision 2.7  90/08/07  14:45:51  chip
+  * We don't need O_EXCL for safe update.
+  * 
+  * Revision 2.6  90/08/07  14:41:34  chip
+  * If kernel locking and modern open, log updates are safe.
+  * 
+  * Revision 2.5  90/08/06  18:41:16  chip
+  * Use LOCK_XXX; make LOCK_ANY available to all modules.
+  * 
   * Revision 2.4  89/12/19  16:28:05  network
   * Simplify preprocessor conditionals for pre-ANSI compilers.
***************
*** 144,146 ****
--- 153,177 ----
  #ifndef Linebuf
  #define Linebuf(f)      (void) setbuf(f, (char *)NULL)
+ #endif
+ 
+ /*
+  * Kernel locking.
+  */
+ 
+ /*
+  * Validate the locking configuration.
+  */
+ 
+ #define LOCK_ANY  (defined(LOCK_LOCKF) + defined(LOCK_FCNTL) + \
+ 		   defined(LOCK_FLOCK) + defined(LOCK_LOCKING))
+ #if LOCK_ANY > 1
+ ACK! "Define only one of LOCK_LOCKF, LOCK_FCNTL, LOCK_FLOCK and LOCK_LOCKING.";
+ #endif
+ 
+ /*
+  * If kernel locking and modern open() are available, then we can
+  * safely create and update mailboxes and logs.
+  */
+ #if (LOCK_ANY > 0) && defined(O_CREAT)
+ #define SAFE_UPDATE
  #endif

Index: subs.c
***************
*** 1,3 ****
! /* $Header: subs.c,v 2.7 90/05/15 11:22:01 chip Exp $
   *
   * Miscellaneous subroutines.
--- 1,3 ----
! /* $Header: subs.c,v 2.8 90/08/06 17:26:32 chip Exp $
   *
   * Miscellaneous subroutines.
***************
*** 4,7 ****
--- 4,10 ----
   *
   * $Log:	subs.c,v $
+  * Revision 2.8  90/08/06  17:26:32  chip
+  * Use O_XXX macros for all open() calls.
+  * 
   * Revision 2.7  90/05/15  11:22:01  chip
   * Add skipfrom().
***************
*** 99,103 ****
  #ifndef O_CREAT
  	(void) close(fd);
! 	if ((fd = open(name, 2)) == -1)
  	{
  		syserr("can't re-open %s", name);
--- 102,106 ----
  #ifndef O_CREAT
  	(void) close(fd);
! 	if ((fd = open(name, O_RDWR)) == -1)
  	{
  		syserr("can't re-open %s", name);

Index: sysdep.c
***************
*** 1,3 ****
! /* $Header: sysdep.c,v 2.9 90/05/03 10:13:06 chip Exp $
   *
   * Routines which are (or might well be) system-dependant.
--- 1,3 ----
! /* $Header: sysdep.c,v 2.10 90/08/07 15:24:30 chip Exp $
   *
   * Routines which are (or might well be) system-dependant.
***************
*** 6,9 ****
--- 6,12 ----
   *
   * $Log:	sysdep.c,v $
+  * Revision 2.10  90/08/07  15:24:30  chip
+  * Ignore return value of uname().
+  * 
   * Revision 2.9  90/05/03  10:13:06  chip
   * Support nap() call in ABCenix.  (Huh?)
***************
*** 251,255 ****
  	static struct utsname u;
  
! 	uname(&u);
  	return (u.nodename[0] ? u.nodename : NULL);
  }
--- 254,258 ----
  	static struct utsname u;
  
! 	(void) uname(&u);
  	return (u.nodename[0] ? u.nodename : NULL);
  }
-- 
Chip Salzenberg at ComDev/TCT     <chip at tct.uucp>, <uunet!ateng!tct!chip>



More information about the Comp.sources.bugs mailing list