*BSD News Article 14819


Return to BSD News archive

Newsgroups: comp.os.386bsd.bugs
Path: sserve!newshost.anu.edu.au!munnari.oz.au!news.Hawaii.Edu!ames!elroy.jpl.nasa.gov!swrinde!cs.utexas.edu!wotan.compaq.com!moxie!hackney
From: hackney@moxie.hou.tx.us (Greg Hackney)
Subject: flock broken - I could use some help
Organization: Home
Message-ID: <C5t8wH.Hs@moxie.hou.tx.us>
Date: Wed, 21 Apr 1993 01:45:51 GMT
Lines: 95


It appears that flock() is causing panic's and reboots.

The problem was discovered using 'lprm' in the LPD package, and also in
the retry feature of smail3.1.28:

Scenario: A process flocks() a file for a long period (2 minutes
          or more). A 2nd process tries to flock the file in the
          blocking mode, but it alarms out and exits. Later, when the
          first process exits, the system panics and reboots.

Below is some test code to make it fail. Compile master.c and slave.c,
then type:    ./master&
              ./slave

In 120 seconds, the system will crash (if your's works like mine).
--
Greg

# This is a shell archive.  Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file".  Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
#	master.c
#	slave.c
#
echo x - master.c
sed 's/^X//' >master.c << 'END-of-master.c'
X#include <stdio.h>
X#include <sys/file.h>
X
Xmain()
X{
X	int i, fd;
X
X	if((fd=open("/tmp/lock", O_RDWR|O_CREAT, 0666)) == -1){
X		fprintf(stderr, "Can't open /tmp/lock\n");
X		exit(1);
X		}
X
X	if((flock(fd, LOCK_EX|LOCK_NB)) != 0) {
X		fprintf(stderr, "Can't lock /tmp/lock\n");
X		exit(1);
X		}
X
X	sleep(120);
X	flock(fd,LOCK_UN);
X	close(fd);
X	exit(0);
X}
X
END-of-master.c
echo x - slave.c
sed 's/^X//' >slave.c << 'END-of-slave.c'
X#include <stdio.h>
X#include <sys/file.h>
X#include <signal.h>
X
Xmain()
X{
X	int fd;
X	void dummy();
X
X	if((fd=open("/tmp/lock", O_RDWR|O_CREAT, 0666)) == -1){
X		fprintf(stderr, "Can't open /tmp/lock\n");
X		exit(1);
X		}
X
X	signal(SIGALRM, dummy);
X	alarm(10);
X
X	if((flock(fd, LOCK_EX)) != 0) {
X		fprintf(stderr, "Can't lock /tmp/lock\n");
X		exit(1);
X		}
X
X	sleep(120);
X	flock(fd,LOCK_UN);
X	close(fd);
X	exit(0);
X}
X
Xdummy()
X{
X	fprintf(stderr, "Got an alarmed exit\n");
X	exit(0);
X}
X
END-of-slave.c
exit