lkml.org 
[lkml]   [2005]   [Oct]   [12]   [last100]   RSS Feed
Views: [more markup]  [less markup]  [headers]  [forward] 
 
Messages in this thread
/
DateWed, 12 Oct 2005 14:48:59 +0200
FromAlex Riesen <>
SubjectRe: blocking file lock functions (lockf,flock,fcntl) do not return after timer signal
On 10/12/05, "Dieter Müller (BOI GmbH)" <dieter.mueller@boi.at> wrote:
> bug description:
>
> flock, lockf, fcntl do not return even after the signal SIGALRM  has
> been raised and the signal handler function has been executed
> the functions should return with a return value EWOULDBLOCK as described
> in the man pages

To confirm:

#include <unistd.h>
#include <sys/time.h>
#include <sys/file.h>
#include <time.h>
#include <signal.h>

void alrm(int sig)
{
    write(2, "timeout\n", 8);
}
int main(int argc, char* argv[])
{
    struct itimerval tv = {
        .it_interval = {.tv_sec = 10, .tv_usec = 0},
        .it_value = {.tv_sec = 10, .tv_usec = 0},
    };
    struct itimerval otv;
    signal(SIGALRM, alrm);
    setitimer(ITIMER_REAL, &tv, &otv);
    int fd = open(argv[1], O_RDWR);
    if ( fd < 0 )
    {
        perror(argv[1]);
        return 1;
    }
    printf("locking...\n");
    if ( flock(fd, LOCK_EX) < 0 )
    {
        perror("flock");
        return 1;
    }
    printf("sleeping...\n");
    int ch;
    read(0, &ch, 1);
    close(fd);
    return 0;
}
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
\
 
 \ /
  Last update: 2005-10-12 12:53    [from the cache]
©2003-2008