Date: Tue, 10 Mar 2009 13:17:12 +0200 From: Kostik Belousov <kostikbel@gmail.com> To: Robert Watson <rwatson@freebsd.org> Cc: Timothy Redaelli <timothy@redaelli.eu>, freebsd-hackers@freebsd.org Subject: Re: lockf: Invalid argument on pipe Message-ID: <20090310111712.GA41617@deviant.kiev.zoral.com.ua> In-Reply-To: <alpine.BSF.2.00.0903092335060.92752@fledge.watson.org> References: <ac9bf7980903091448w1c3b8405la2a0084e5a947a05@mail.gmail.com> <alpine.BSF.2.00.0903092335060.92752@fledge.watson.org>
next in thread | previous in thread | raw e-mail | index | archive | help
--144W9TlQWTjTIokZ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Mar 09, 2009 at 11:35:58PM +0000, Robert Watson wrote: >=20 > On Mon, 9 Mar 2009, Timothy Redaelli wrote: >=20 > >Why can't I do a lockf on a file descriptor that does not point a real= =20 > >file (such as stderr, stdout, or a character device)? > > > >Since it works under NetBSD, Linux, Solaris. For portability between=20 > >systems I hope I can do it under FreeBSD. > > > >The following code is simple, but It reproduce the problem. Under=20 > >non-FreeBSD systems, It will block before the puts. Instead under FreeBS= D=20 > >the lockf calls return error and, so, the lock does not works. >=20 > Could you file a PR for this, with pretty much this e-mail and sample cod= e=20 > included? There's no real reason not for it to work other than that it i= s=20 > likely not implemented for devfs; that should be easy to fix it but openi= ng=20 > a PR will help us keep track of the fact that it wants to be fixed. >=20 > thanks, >=20 > Robert N M Watson > Computer Laboratory > University of Cambridge >=20 > > > >Any suggest? > > > ><snip> > >#include <stdio.h> > >#include <unistd.h> > >#include <stdlib.h> > >#include <string.h> > > > >int main(int argc, char *argv[]) { > > char tmp[256]; > > > > if (lockf(2, F_LOCK, 0) =3D=3D -1) > > perror("lock"); > > snprintf (tmp, 256, "%s XXX", argv[0]); > > if (!argv[1] || strcmp(argv[1], "XXX")) > > system(tmp); > > puts("You should see it only after ctrl+c"); > > return EXIT_SUCCESS; > >} > ><end snip> It is explicitely disabled in devfs code. The following patch works for me. diff --git a/sys/fs/devfs/devfs_vnops.c b/sys/fs/devfs/devfs_vnops.c index 1087452..b890da7 100644 --- a/sys/fs/devfs/devfs_vnops.c +++ b/sys/fs/devfs/devfs_vnops.c @@ -452,14 +452,6 @@ devfs_access(struct vop_access_args *ap) =20 /* ARGSUSED */ static int -devfs_advlock(struct vop_advlock_args *ap) -{ - - return (ap->a_flags & F_FLOCK ? EOPNOTSUPP : EINVAL); -} - -/* ARGSUSED */ -static int devfs_close(struct vop_close_args *ap) { struct vnode *vp =3D ap->a_vp, *oldvp; @@ -1552,7 +1544,6 @@ static struct vop_vector devfs_specops =3D { .vop_default =3D &default_vnodeops, =20 .vop_access =3D devfs_access, - .vop_advlock =3D devfs_advlock, .vop_bmap =3D VOP_PANIC, .vop_close =3D devfs_close, .vop_create =3D VOP_PANIC, --144W9TlQWTjTIokZ Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (FreeBSD) iEYEARECAAYFAkm2TDcACgkQC3+MBN1Mb4ip3wCdG+LG9sAemurNZw9ETgifBSpZ ms0AnjsLZMVyjLxvBUCfW9mkTw3N/sJ2 =HjD0 -----END PGP SIGNATURE----- --144W9TlQWTjTIokZ--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20090310111712.GA41617>