Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 12 Dec 2000 14:45:37 -0800
From:      Jeff Roberson <jeff@midstream.com>
To:        "'freebsd-current@freebsd.org'" <freebsd-current@freebsd.org>
Subject:   Bug Fix for SYSV semaphores.
Message-ID:  <31E4B6337A4FD411BD45000102472E0C05E6FD@EMAIL_SERVER>

next in thread | raw e-mail | index | archive | help
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_001_01C0648D.4319C7E0
Content-Type: text/plain;
	charset="iso-8859-1"

I noticed that sysv semaphores initialize the otime member of the semid_ds
structure to 0, but they never update it afterwards.  This field is supposed
to be the last operation time.  ie the last time a semctl was done.  In UNIX
Network Programming, Stevens suggests using this variable to detect races
between multiple processes creating/accessing a sysv semaphore.  Anyway, I
looked through the code and came up with the following trivial patch.  Could
some one review it and perhaps commit it?  This patch was made against
current, but I noticed the bug is there in 4.1.1 and most likely everything
before that.

Thanks,
Jeff

(Pardon the revision numbers, they are from my own repository)

*** sysv_sem.c  2000/09/15 11:11:48     1.1.1.1
--- sysv_sem.c  2000/12/12 23:44:28
***************
*** 543,548 ****
--- 543,550 ----
                return(EINVAL);
        }
  
+       semaptr->sem_otime = time_second;
+ 
        if (eval == 0)
                p->p_retval[0] = rval;
        return(eval);

------_=_NextPart_001_01C0648D.4319C7E0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Diso-8859-1">
<META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version =
5.5.2650.12">
<TITLE>Bug Fix for SYSV semaphores.</TITLE>
</HEAD>
<BODY>

<P><FONT SIZE=3D2>I noticed that sysv semaphores initialize the otime =
member of the semid_ds structure to 0, but they never update it =
afterwards.&nbsp; This field is supposed to be the last operation =
time.&nbsp; ie the last time a semctl was done.&nbsp; In UNIX Network =
Programming, Stevens suggests using this variable to detect races =
between multiple processes creating/accessing a sysv semaphore.&nbsp; =
Anyway, I looked through the code and came up with the following =
trivial patch.&nbsp; Could some one review it and perhaps commit =
it?&nbsp; This patch was made against current, but I noticed the bug is =
there in 4.1.1 and most likely everything before that.</FONT></P>

<P><FONT SIZE=3D2>Thanks,</FONT>
<BR><FONT SIZE=3D2>Jeff</FONT>
</P>

<P><FONT SIZE=3D2>(Pardon the revision numbers, they are from my own =
repository)</FONT>
</P>

<P><FONT SIZE=3D2>*** sysv_sem.c&nbsp; 2000/09/15 =
11:11:48&nbsp;&nbsp;&nbsp;&nbsp; 1.1.1.1</FONT>
<BR><FONT SIZE=3D2>--- sysv_sem.c&nbsp; 2000/12/12 23:44:28</FONT>
<BR><FONT SIZE=3D2>***************</FONT>
<BR><FONT SIZE=3D2>*** 543,548 ****</FONT>
<BR><FONT SIZE=3D2>--- 543,550 ----</FONT>
<BR><FONT =
SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp; return(EINVAL);</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</FONT>
<BR><FONT SIZE=3D2>&nbsp; </FONT>
<BR><FONT SIZE=3D2>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
semaptr-&gt;sem_otime =3D time_second;</FONT>
<BR><FONT SIZE=3D2>+ </FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (eval =
=3D=3D 0)</FONT>
<BR><FONT =
SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp; p-&gt;p_retval[0] =3D rval;</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
return(eval);</FONT>
</P>

</BODY>
</HTML>
------_=_NextPart_001_01C0648D.4319C7E0--


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?31E4B6337A4FD411BD45000102472E0C05E6FD>