[PATCH] make sys_open respect FASYNC

M.J. Pomraning (mjp@pilcrow.madison.wi.us)
Thu, 15 Nov 2001 01:08:08 -0600 (EST)


This message is in MIME format. The first part should be readable text,
while the remaining parts are likely unreadable without MIME-aware tools.
Send mail to mime@docserver.cac.washington.edu for more info.

--168428044-816439665-1005808088=:13207
Content-Type: TEXT/PLAIN; charset=US-ASCII

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

--168428044-816439665-1005808088=:13207 Content-Type: TEXT/PLAIN; charset=US-ASCII; name="fasync-tty.c" Content-Transfer-Encoding: BASE64 Content-ID: <Pine.LNX.4.33.0111150108080.13207@alice.wi.securepipe.com> Content-Description: Content-Disposition: attachment; filename="fasync-tty.c"

I2luY2x1ZGUgPHVuaXN0ZC5oPg0KI2luY2x1ZGUgPHNpZ25hbC5oPg0KI2lu Y2x1ZGUgPHN0ZGlvLmg+DQojZGVmaW5lIF9fVVNFX0dOVQ0KI2luY2x1ZGUg PGZjbnRsLmg+DQoNCi8qIG1qcEBwaWxjcm93Lm1hZGlzb24ud2kudXM7IDE1 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IlllcyIgOiAiTm8gKGJ1bW1lcikiKTsNCiAgZXhpdCgwKTsNCn0NCg== --168428044-816439665-1005808088=:13207-- - 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/