Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sdd.hp.com!spool.mu.edu!snorkelwacker.mit.edu!bloom-beacon!eru!hagbard!sunic!mcsun!unido!math.fu-berlin.de!fub!geminix.in-berlin.de!gemini From: gemini@geminix.in-berlin.de (Uwe Doering) Newsgroups: comp.mail.elm Subject: Re: Will ELM ever use lockf()? Message-ID: Date: 5 Apr 91 10:04:58 GMT Article-I.D.: geminix.UHPPYLW References: <1991Mar25.193741.12360@coplex.uucp> <27F120EF.63A3@tct.uucp> <1991Mar30.213039.28713@coplex.uucp> <27FA24B0.5244@tct.com> Organization: Private UNIX Site Lines: 113 chip@tct.com (Chip Salzenberg) writes: >According to dean@coplex.uucp (Dean Brooks): >>chip@tct.uucp (Chip Salzenberg) writes: >>>Check the Smail source code -- specifically, sysdep.c. Smail does use >>>".lock" files, just like Elm. >> >>Yeah, but ".lock" files dont hack hack it for 20 messages all trying >>to arrive in your mailbox at the same time. > >Correspondence with Dean reveals that Smail seems to work okay, and >that it's Elm that's dropping the ball. > >Of course, there is no such thing as reliable elimination of a stale >lock file under UNIX: how do you know that you're removing the stale >one? So lockf() is really the best solution. You may be right that lockf() is the best solution. However, in this case there is simply a bug in Elm's lock() function. It happily blows away every lock file that has a PID of another process in it, regardless of whether this process is still alive or not. Took a while until I found this out. Anyway, below there is the necessary patch that corrects this problem. Following this patch, there is another one that shows how to convince Smail 3.1.20 to use lock files instead of lockf() unter SysVr3. Maybe this works for earlier Smail releases, too. Have fun. Uwe Here's the Elm 2.3 PL11 patch for $ELMSRC/src/leavembox.c: ---------------------------- cut here ------------------------------ *** leavembox.c.00 Sat Mar 30 04:01:47 1991 --- leavembox.c Sat Mar 30 04:01:58 1991 *************** *** 704,711 **** if (read(create_fd, pid_buffer, SHORT) > 0) { create_iteration = atoi(pid_buffer); if (create_iteration) { ! if (kill(create_iteration, 0)) { ! close(create_fd); if (unlink(lock_name) != 0) { dprint(1, (debugfile, "Error %s (%s)\n\ttrying to unlink file %s (%s)\n", --- 704,710 ---- if (read(create_fd, pid_buffer, SHORT) > 0) { create_iteration = atoi(pid_buffer); if (create_iteration) { ! if (kill(create_iteration, 0) && errno == ESRCH) { if (unlink(lock_name) != 0) { dprint(1, (debugfile, "Error %s (%s)\n\ttrying to unlink file %s (%s)\n", *************** *** 714,719 **** --- 713,719 ---- "\n\rCouldn't remove the current lock file %s\n\r", lock_name); PutLine2(LINES, 0, "** %s - %s **\n\r", error_name(errno), error_description(errno)); + close(create_fd); if (direction == INCOMING) leave(); else *************** *** 722,727 **** --- 722,728 ---- } } } + close(create_fd); create_iteration = 0; } #endif ---------------------------- cut here ------------------------------ And this is the Smail 3.1.20 patch for file $SMAILSRC/conf/os/sys5.3: ---------------------------- cut here ------------------------------ *** sys5.3.00 Sat Feb 23 11:18:59 1991 --- sys5.3 Thu Mar 28 11:51:19 1991 *************** *** 21,37 **** OSNAMES=UNIX_SYS5_3:UNIX_SYS5:UNIX # LOCKING_PROTOCOL - macros for efficient file locking ! LOCKING_PROTOCOL="\ ! #include ! #define LOCK_REQUIRES_WRITE ! #define lock_fd(fd) (lockf((fd), F_TLOCK, 0L) < 0? FAIL: SUCCEED) ! #define lock_fd_wait(fd) (lockf((fd), F_LOCK, 0L) < 0? FAIL: SUCCEED) ! #define unlock_fd(fd) ((void) lockf((fd), F_ULOCK, 0L)) ! #define unlock_fd_wait(fd) ((void) lockf((fd), F_ULOCK, 0L)) ! #define USE_FCNTL_RD_LOCK ! #define lock_fd_rd_wait(fd) (fcntl_rd_lock(fd)) ! extern int fcntl_rd_lock(); ! " # MAILBOX_DIR - in which directory are user mailbox files MAILBOX_DIR=/usr/mail --- 21,28 ---- OSNAMES=UNIX_SYS5_3:UNIX_SYS5:UNIX # LOCKING_PROTOCOL - macros for efficient file locking ! LOCKING_PROTOCOL= ! LOCK_BY_NAME=TRUE # compatible with ELM # MAILBOX_DIR - in which directory are user mailbox files MAILBOX_DIR=/usr/mail ---------------------------- cut here ------------------------------ -- Uwe Doering | INET : gemini@geminix.in-berlin.de Berlin |---------------------------------------------------------------- Germany | UUCP : ...!unido!fub!geminix.in-berlin.de!gemini