[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <alpine.LFD.2.01.0907271500110.25224@localhost.localdomain>
Date: Mon, 27 Jul 2009 15:04:03 -0700 (PDT)
From: Linus Torvalds <torvalds@...ux-foundation.org>
To: Alan Cox <alan@...rguk.ukuu.org.uk>
cc: OGAWA Hirofumi <hirofumi@...l.parknet.co.jp>,
"Aneesh Kumar K.V" <aneesh.kumar@...ux.vnet.ibm.com>,
"Rafael J. Wysocki" <rjw@...k.pl>, Ray Lee <ray-lk@...rabbit.org>,
LKML <linux-kernel@...r.kernel.org>,
Andrew Morton <akpm@...ux-foundation.org>
Subject: Re: [PATCH] kdesu broken
On Mon, 27 Jul 2009, Alan Cox wrote:
>
> It's theoretically imperfect in the case where you write a vast amount of
> output in one go, the tty is blocked the other end and then you close.
> However in practice that doesn't happen because with tty->low_latency = 1
> we run the pty received n_tty ldisc code in our context so each write
> fires through the entire n_tty ldisc and does flow control synchronously.
An alternative might be something like this.
THIS IS TOTALLY UNTESTED.
This is just meant as a "this kind of approach may be a good idea", and
just tries to make sure that any delayed work is flushed by closing the
tty.
No guarantees. It may or may not compile. It may or may not make any
difference. It might do unspeakable things to your pets. It really is
meant to be an example of what a "flush" function could/should do. There
are probably other things/buffers that may need flushing.
Linus
---
drivers/char/tty_io.c | 33 +++++++++++++++++++++++++++++++++
1 files changed, 33 insertions(+), 0 deletions(-)
diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
index a3afa0c..1be69af 100644
--- a/drivers/char/tty_io.c
+++ b/drivers/char/tty_io.c
@@ -143,6 +143,7 @@ ssize_t redirected_tty_write(struct file *, const char __user *,
static unsigned int tty_poll(struct file *, poll_table *);
static int tty_open(struct inode *, struct file *);
static int tty_release(struct inode *, struct file *);
+static int tty_flush(struct file *filp, fl_owner_t id);
long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
#ifdef CONFIG_COMPAT
static long tty_compat_ioctl(struct file *file, unsigned int cmd,
@@ -415,6 +416,7 @@ static const struct file_operations tty_fops = {
.unlocked_ioctl = tty_ioctl,
.compat_ioctl = tty_compat_ioctl,
.open = tty_open,
+ .flush = tty_flush,
.release = tty_release,
.fasync = tty_fasync,
};
@@ -1831,7 +1833,38 @@ static int tty_open(struct inode *inode, struct file *filp)
return ret;
}
+/* This should probably be a generic function */
+static void flush_delayed_work(struct delayed_work *work)
+{
+ if (cancel_delayed_work(work)) {
+ schedule_delayed_work(work, 0);
+ flush_scheduled_work();
+ }
+}
+/**
+ * tty_flush - vfs callback for close
+ * @filp: file pointer for handle to tty
+ * @id: struct files_struct of owner.
+ *
+ * Called for every close(), whether the last or not
+ */
+static int tty_flush(struct file *filp, fl_owner_t id)
+{
+ struct tty_struct *tty, *o_tty;
+ struct inode *inode;
+
+ inode = filp->f_path.dentry->d_inode;
+ tty = (struct tty_struct *)filp->private_data;
+
+ if (tty_paranoia_check(tty, inode, "tty_flush"))
+ return 0;
+
+ o_tty = tty->link;
+ if (o_tty)
+ flush_delayed_work(&o_tty->buf.work);
+ return 0;
+}
/**
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists