From owner-freebsd-current@FreeBSD.ORG Mon Jun 28 14:20:49 2010 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 81D051065674 for ; Mon, 28 Jun 2010 14:20:49 +0000 (UTC) (envelope-from imp@bsdimp.com) Received: from harmony.bsdimp.com (bsdimp.com [199.45.160.85]) by mx1.freebsd.org (Postfix) with ESMTP id 378968FC23 for ; Mon, 28 Jun 2010 14:20:49 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by harmony.bsdimp.com (8.14.3/8.14.1) with ESMTP id o5SEEliJ084107; Mon, 28 Jun 2010 08:14:47 -0600 (MDT) (envelope-from imp@bsdimp.com) Date: Mon, 28 Jun 2010 08:14:58 -0600 (MDT) Message-Id: <20100628.081458.18103541849609641.imp@bsdimp.com> To: des@des.no From: "M. Warner Losh" In-Reply-To: <86mxuf7eli.fsf@ds4.des.no> References: <20100627.155004.49280345238493664.imp@bsdimp.com> <86mxuf7eli.fsf@ds4.des.no> X-Mailer: Mew version 6.3 on Emacs 22.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Cc: yanefbsd@gmail.com, freebsd-current@freebsd.org, hselasky@c2i.net Subject: Re: Patch for rc.d/devd on FreeBSD 9-current X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 Jun 2010 14:20:49 -0000 In message: <86mxuf7eli.fsf@ds4.des.no> Dag-Erling Sm=F8rgrav writes: : "M. Warner Losh" writes: : > Why not fix pidfile_open to not return a file handle when the PID : > doesn't match? : = : It doesn't. If it can't lock the file, or if fstat(2) fails after it= : has locked the file, it returns NULL. Then we have a bug in the locking code. I've definitely seen things fail to behave properly after killing devd. Let me trace out what I think is going on: From=20pidfile_open: /* * Open the PID file and obtain exclusive lock. * We truncate PID file here only to remove old PID immediatelly, * PID file will be truncated again in pidfile_write(), so * pidfile_write() can be called multiple times. */ fd =3D flopen(pfh->pf_path, O_WRONLY | O_CREAT | O_TRUNC | O_NONBLOCK, mode); if (fd =3D=3D -1) { ---> We take this path, fd =3D=3D -1. count =3D 0; rqtp.tv_sec =3D 0; rqtp.tv_nsec =3D 5000000; if (errno =3D=3D EWOULDBLOCK && pidptr !=3D NULL) { again: ---> and this one, so errno is EWOULDBLOCK errno =3D pidfile_read(pfh->pf_path, pidptr); ---> errno is 0 here, so if (errno =3D=3D 0) errno =3D EEXIST; ---> We return NULL with errno set toEEXIST = else if (errno =3D=3D EAGAIN) { if (++count <=3D 3) { nanosleep(&rqtp, 0); goto again; } } } free(pfh); return (NULL); } So what's going on? Warner