From owner-freebsd-current Fri Sep 6 11: 5:31 2002 Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 74A2E37B405; Fri, 6 Sep 2002 11:05:25 -0700 (PDT) Received: from prg.traveller.cz (prg.traveller.cz [193.85.2.77]) by mx1.FreeBSD.org (Postfix) with ESMTP id 89ED843E4A; Fri, 6 Sep 2002 11:05:24 -0700 (PDT) (envelope-from mime@traveller.cz) Received: from prg.traveller.cz (localhost [127.0.0.1]) by prg.traveller.cz (8.12.2[KQ/pukvis]/8.12.2-prg) with ESMTP id g86I5NWR051795; Fri, 6 Sep 2002 20:05:23 +0200 (CEST) Received: from localhost (mime@localhost) by prg.traveller.cz (8.12.2[KQ/pukvis]/8.12.2-prg/submit) with ESMTP id g86I5NiN051792; Fri, 6 Sep 2002 20:05:23 +0200 (CEST) Date: Fri, 6 Sep 2002 20:05:23 +0200 (CEST) From: Michal Mertl To: Alfred Perlstein Cc: current@freebsd.org Subject: Re: bug in sysv semaphores on -CURRENT In-Reply-To: <20020906175802.GE21806@elvis.mu.org> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Fri, 6 Sep 2002, Alfred Perlstein wrote: Alfred (thanks) found a bug in my code. Sorry for the fuss folks :-(. > * Michal Mertl [020906 06:10] wrote: > > There seems to be bug in $SUBJ. When I run attached program on recent > > -CURRENT, it always (after several seconds) triggers the bug. I first > > suspected a problem in the program's logic but on stable in runs just > > fine. > > > > Esentially I use piece of shm memory to pass some data between several > > processes. I implemented simple locking functions with semaphores and > > noticed it behaves strange on -CURRENT and ok on -STABLE. > > > > CCing Alfred because he made some changes into the kernel part of $SUBJ. I > > don't expect the bug is new though. > > > > May I ask someone with older -CURRENT to try running the program for a > > minute? > > I found your bug. > > In the function ipc_unlock() you do this: > > > int > > ipc_unlock(void) > > { > > struct sembuf sem_buf; > > int err; > > > > if (ipc_cfg->sem_owner != getpid()) { > > fprintf(stderr, "%d: can't unlock (bug), owner: %d\n", > > getpid(), ipc_cfg->sem_owner); > > return (-1); > > } > > if (semctl(ipc_cfg->sem_id, 0, GETVAL) != 0) { > > fprintf(stderr, "%d: can't unlock (bug), not locked\n", > > getpid()); > > return (-1); > > } > > printf("%d: ipc_unlock()\n", getpid()); > > sem_buf.sem_num = 0; > > sem_buf.sem_op = 1; > > sem_buf.sem_flg = 0; > > err = semop(ipc_cfg->sem_id, &sem_buf, 1); > > if (err == -1) { > > fprintf(stderr, "%d: semop()\n", getpid()); > > return (-1); > > } > > ipc_cfg->sem_owner = -1; > > return (0); > > } > > Problem is that you're messing with lock state after dropping your > semaphore! > > If you move the > ipc_cfg->sem_owner = -1; > to before the semop() call it seems to fix things. > > -Alfred > -- Michal Mertl mime@traveller.cz To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message