O_ASYNC question

Amos Waterland (apw@us.ibm.com)
Tue, 25 Jun 2002 11:30:52 -0500


The man page for fcntl() says:

If you set the O_ASYNC status flag on a file descriptor (either by
providing this flag with the open(2) call, or by using the F_SETFL
command of fcntl), a SIGIO signal is sent whenever input or output
becomes possible on that file descriptor.

On a 2.4.18 kernel, this test program waits forever in sigwaitinfo():

#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main(int argc, char *argv[])
{
const int BYTES = 5000000;
int i, fd;
char buff[BYTES];
char name[] = "/tmp/aio8.XXXXXX";
sigset_t sigset;
siginfo_t siginfo;

if ((fd = open(name, O_CREAT|O_WRONLY|O_NONBLOCK|O_ASYNC, 0600)) < 0 ||
unlink(name)) {
perror("creating temp file"); exit(1);
}

for (i = 0; i < BYTES; i++) buff[i] = 'Z';

if (sigemptyset(&sigset) || sigaddset(&sigset, SIGIO) ||
sigprocmask(SIG_BLOCK, &sigset, NULL)) {
perror("setting up signal mask"); exit(2);
}

if (write(fd, buff, BYTES) < 0) {
perror("writing to temp file"); exit(3);
}

printf("recv sig: %i\n", sigwaitinfo(&sigset, &siginfo));

return 0;
}

Shouldn't SIGIO be raised when the write() completes? (Is O_ASYNC only
valid for sockets, maybe?) Thanks in advance.

Amos Waterland
-
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/