Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 9 Mar 2009 22:48:39 +0100
From:      Timothy Redaelli <timothy@redaelli.eu>
To:        freebsd-hackers@freebsd.org
Subject:   lockf: Invalid argument on pipe
Message-ID:  <ac9bf7980903091448w1c3b8405la2a0084e5a947a05@mail.gmail.com>

next in thread | raw e-mail | index | archive | help
Hi,
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.

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>

-- 
Timothy Redaelli
IT Consultant
Email: timothy@redaelli.eu
Mobile: +39 (338) 1187273
WWW:  http://www.redaelli.eu/



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