lockf: Invalid argument on pipe
Kostik Belousov
kostikbel at gmail.com
Tue Mar 10 04:17:21 PDT 2009
On Mon, Mar 09, 2009 at 11:35:58PM +0000, Robert Watson wrote:
>
> On Mon, 9 Mar 2009, Timothy Redaelli wrote:
>
> >Why can't I do a lockf on a file descriptor that does not point a real
> >file (such as stderr, stdout, or a character device)?
> >
> >Since it works under NetBSD, Linux, Solaris. For portability between
> >systems I hope I can do it under FreeBSD.
> >
> >The following code is simple, but It reproduce the problem. Under
> >non-FreeBSD systems, It will block before the puts. Instead under FreeBSD
> >the lockf calls return error and, so, the lock does not works.
>
> Could you file a PR for this, with pretty much this e-mail and sample code
> included? There's no real reason not for it to work other than that it is
> likely not implemented for devfs; that should be easy to fix it but opening
> a PR will help us keep track of the fact that it wants to be fixed.
>
> thanks,
>
> Robert N M Watson
> Computer Laboratory
> University of Cambridge
>
> >
> >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) == -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)
/* 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 = ap->a_vp, *oldvp;
@@ -1552,7 +1544,6 @@ static struct vop_vector devfs_specops = {
.vop_default = &default_vnodeops,
.vop_access = devfs_access,
- .vop_advlock = devfs_advlock,
.vop_bmap = VOP_PANIC,
.vop_close = devfs_close,
.vop_create = VOP_PANIC,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20090310/ee95ae07/attachment.pgp
More information about the freebsd-hackers
mailing list