Received: from SOUTH-STATION-ANNEX.MIT.EDU by po7.MIT.EDU (5.61/4.7) id AA12816; Wed, 13 Dec 95 16:09:10 EST
Received: from halloran-eldar.lcs.mit.edu by MIT.EDU with SMTP
	id AB23413; Wed, 13 Dec 95 16:09:11 EST
Received: from freefall.FreeBSD.ORG by halloran-eldar.lcs.mit.edu; (5.65/1.1.8.2/19Aug95-0530PM)
	id AA11231; Wed, 13 Dec 1995 16:06:10 -0500
Received: from localhost (daemon@localhost)
          by freefall.freebsd.org (8.7.3/8.7.3) with SMTP id JAA09764
          Wed, 13 Dec 1995 09:58:37 -0800 (PST)
Received: (from root@localhost)
          by freefall.freebsd.org (8.7.3/8.7.3) id JAA09637
          for hackers-outgoing; Wed, 13 Dec 1995 09:57:09 -0800 (PST)
Received: from cls.net (freeside.cls.de [192.129.50.1])
          by freefall.freebsd.org (8.7.3/8.7.3) with SMTP id JAA09632
          for <hackers@freebsd.org>; Wed, 13 Dec 1995 09:57:04 -0800 (PST)
Received: by mail.cls.net (Smail3.1.29.1)
	  from allegro.lemis.de (192.109.197.134) with smtp
	  id <m0tPvQP-0011kSC@cls.net>; Wed, 13 Dec 95 17:57 GMT
From: grog@lemis.de (Greg Lehey)
Organisation: LEMIS, Schellnhausen 2, 36325 Feldatal, Germany
Phone: +49-6637-919123
Fax:   +49-6637-919122
Reply-To: grog@lemis.de (Greg Lehey)
Received: (grog@localhost) by allegro.lemis.de (8.6.9/8.6.9) 
	id SAA01254 for hackers@freebsd.org; Wed, 13 Dec 1995 18:45:56 +0100
Message-Id: <199512131745.SAA01254@allegro.lemis.de>
Subject: Re: samaphore remains
To: terry@lambert.org (Terry Lambert)
Date: Wed, 13 Dec 1995 18:45:39 +0100 (MET)
In-Reply-To: <199512061915.MAA01689@phaeton.artisoft.com> from "Terry Lambert" at Dec 6, 95 12:15:29 pm
X-Mailer: ELM [version 2.4 PL23]
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
Sender: owner-hackers@FreeBSD.ORG
Precedence: bulk

Terry Lambert writes:
> 
>> Currently I'm using FreeBSD-R2.1.0-RELEASE on GATEWAY 2000 P5-90.
>> 
>> I found the trouble that if a program using semaphore died
>> anbormally, the semaphore which was created remains on kernel.
>> I think it should be released by kernel's exit() function.
>> 
>> Although one of the UNIX implementation calls semexit() routine from
>> exit(), FreeBSD doesn't call semexit() from anywhere.
>> Is there any reason for this?
>> 
>> 
>> I tried to fix the exit() as follows and it seems working well.
>> 
>> ------------- cut here ---------------
>> *** kern_exit.c Tue May 30 17:05:25 1995
>> --- kern_exit.c.new     Wed Dec  6 15:12:28 1995
>> ***************
>> *** 130,135 ****
>> --- 130,139 ----
>> */
>> fdfree(p);
>> 
>> + #ifdef SYSVSEM
>> +       semexit(p);
>> + #endif
>> + 
>> /* The next two chunks should probably be moved to vmspace_exit. */
>> vm = p->p_vmspace;
>> #ifdef SYSVSHM
>> ------------- cut here ---------------
>> 
>> 
>> --
>> Mihoko Tanaka 
>> <m_tanaka@pa.yokogawa.co.jp>     
> 
> This looks exactly right.

That's a matter of definition.  In System V, by default the semaphore
remains beyond the death of the process.  See "The Magic Garden
Explained", pp 541 et seq., for an explanation which even makes this
apparent nonsense make sense.  The correct behaviour is to only reset
the semaphore if the SEM_UNDO flag is set.  I can't see any reason to
ever have it not set, but maybe some broken System V software relies
on it...

Greg


