lkml.org 
[lkml]   [2001]   [Nov]   [15]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[PATCH] make sys_open respect FASYNC
Please roll your eyeballs over the following -- idea is to have open(blah,
O_ASYNC) work as expected (device permitting), and not to leave the caller
with an fd with a frustrated flag.

Successfully applied against 2.4.14. Simple test case (for ttys) attached.
Previous post [1] has more about motivation and scope (incl. FIFOs) of this
somewhat obscure concern.

=============================
--- linux/fs/open.c.orig Wed Nov 14 09:53:36 2001
+++ linux/fs/open.c Wed Nov 14 15:34:33 2001
@@ -789,6 +789,15 @@
error = PTR_ERR(f);
if (IS_ERR(f))
goto out_error;
+ /* handle open(foo, O_ASYNC|...) */
+ if ((f->f_flags & FASYNC) &&
+ f->f_op && f->f_op->fasync) {
+ error = f->f_op->fasync(fd, f, 1);
+ if (error < 0) {
+ filp_close(f, NULL);
+ goto out_error;
+ }
+ }
fd_install(fd, f);
}
out:
=============================
Notes:

[1] "open(O_ASYNC) sets futile flag"
http://www.uwsg.indiana.edu/hypermail/linux/kernel/0111.1/1401.html

Regards,
Mike
--
MJ Pomraning
mjp@pilcrow.madison.wi.us
#include <unistd.h>
#include <signal.h>
#include <stdio.h>
#define __USE_GNU
#include <fcntl.h>

/* mjp@pilcrow.madison.wi.us; 15 Nov 2001 */

/* gcc -o fasync-tty fasync-tty.c */

sig_atomic_t flag_io = 0;

void sigio(int signo) {
flag_io = 1;
}

void pdie(char *errtag) {
perror(errtag);
exit(1);
}

int main() {
int fd;
char buf[512];
char * tty;

if (signal(SIGIO, sigio) == SIG_ERR)
pdie("signal");

tty = ttyname(fileno(stdin));
if (!tty)
pdie("tty/stdin");

fd = open(tty, O_ASYNC|O_RDONLY);
if (fd == -1)
pdie("open");

if (fcntl(fd, F_SETOWN, getpid()) == -1)
pdie("F_SETOWN");

printf("%s open()d O_ASYNC, F_SETOWN'd\n", tty);

printf("A line of input, please...\n");
(void) fgets(buf, 512, stdin);

printf("O_ASYNC set? %s\n",
(fcntl(fd, F_GETFL) & O_ASYNC) ? "Yes" : "No");

printf("O_ASYNC respected? %s\n",
flag_io ? "Yes" : "No (bummer)");
exit(0);
}
\
 
 \ /
  Last update: 2005-03-22 13:13    [W:0.035 / U:0.708 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site