mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-15 08:14:15 +08:00
TTY: extract /dev/tty handling from tty_open
This one is special to others (done in the next patch). We have the tty directly, not its driver and index. So this will reside in a separation function. In the next patch, the rest will be moved to another function. So now we set neither driver nor index. Hence we need to init driver and check whether we are supposed to put a ref of that. Signed-off-by: Jiri Slaby <jslaby@suse.cz> Cc: Alan Cox <alan@linux.intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
This commit is contained in:
parent
1411dc4aa2
commit
b82154ac37
@ -1796,6 +1796,33 @@ int tty_release(struct inode *inode, struct file *filp)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* tty_open_current_tty - get tty of current task for open
|
||||||
|
* @device: device number
|
||||||
|
* @filp: file pointer to tty
|
||||||
|
* @return: tty of the current task iff @device is /dev/tty
|
||||||
|
*
|
||||||
|
* We cannot return driver and index like for the other nodes because
|
||||||
|
* devpts will not work then. It expects inodes to be from devpts FS.
|
||||||
|
*/
|
||||||
|
static struct tty_struct *tty_open_current_tty(dev_t device, struct file *filp)
|
||||||
|
{
|
||||||
|
struct tty_struct *tty;
|
||||||
|
|
||||||
|
if (device != MKDEV(TTYAUX_MAJOR, 0))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
tty = get_current_tty();
|
||||||
|
if (!tty)
|
||||||
|
return ERR_PTR(-ENXIO);
|
||||||
|
|
||||||
|
filp->f_flags |= O_NONBLOCK; /* Don't let /dev/tty block */
|
||||||
|
/* noctty = 1; */
|
||||||
|
tty_kref_put(tty);
|
||||||
|
/* FIXME: we put a reference and return a TTY! */
|
||||||
|
return tty;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* tty_open - open a tty device
|
* tty_open - open a tty device
|
||||||
* @inode: inode of device file
|
* @inode: inode of device file
|
||||||
@ -1819,9 +1846,9 @@ int tty_release(struct inode *inode, struct file *filp)
|
|||||||
|
|
||||||
static int tty_open(struct inode *inode, struct file *filp)
|
static int tty_open(struct inode *inode, struct file *filp)
|
||||||
{
|
{
|
||||||
struct tty_struct *tty = NULL;
|
struct tty_struct *tty;
|
||||||
int noctty, retval;
|
int noctty, retval;
|
||||||
struct tty_driver *driver;
|
struct tty_driver *driver = NULL;
|
||||||
int index;
|
int index;
|
||||||
dev_t device = inode->i_rdev;
|
dev_t device = inode->i_rdev;
|
||||||
unsigned saved_flags = filp->f_flags;
|
unsigned saved_flags = filp->f_flags;
|
||||||
@ -1840,22 +1867,15 @@ retry_open:
|
|||||||
mutex_lock(&tty_mutex);
|
mutex_lock(&tty_mutex);
|
||||||
tty_lock();
|
tty_lock();
|
||||||
|
|
||||||
if (device == MKDEV(TTYAUX_MAJOR, 0)) {
|
tty = tty_open_current_tty(device, filp);
|
||||||
tty = get_current_tty();
|
if (IS_ERR(tty)) {
|
||||||
if (!tty) {
|
tty_unlock();
|
||||||
tty_unlock();
|
mutex_unlock(&tty_mutex);
|
||||||
mutex_unlock(&tty_mutex);
|
tty_free_file(filp);
|
||||||
tty_free_file(filp);
|
return PTR_ERR(tty);
|
||||||
return -ENXIO;
|
} else if (tty)
|
||||||
}
|
|
||||||
driver = tty_driver_kref_get(tty->driver);
|
|
||||||
index = tty->index;
|
|
||||||
filp->f_flags |= O_NONBLOCK; /* Don't let /dev/tty block */
|
|
||||||
/* noctty = 1; */
|
|
||||||
/* FIXME: Should we take a driver reference ? */
|
|
||||||
tty_kref_put(tty);
|
|
||||||
goto got_driver;
|
goto got_driver;
|
||||||
}
|
|
||||||
#ifdef CONFIG_VT
|
#ifdef CONFIG_VT
|
||||||
if (device == MKDEV(TTY_MAJOR, 0)) {
|
if (device == MKDEV(TTY_MAJOR, 0)) {
|
||||||
extern struct tty_driver *console_driver;
|
extern struct tty_driver *console_driver;
|
||||||
@ -1911,7 +1931,8 @@ got_driver:
|
|||||||
tty = tty_init_dev(driver, index, 0);
|
tty = tty_init_dev(driver, index, 0);
|
||||||
|
|
||||||
mutex_unlock(&tty_mutex);
|
mutex_unlock(&tty_mutex);
|
||||||
tty_driver_kref_put(driver);
|
if (driver)
|
||||||
|
tty_driver_kref_put(driver);
|
||||||
if (IS_ERR(tty)) {
|
if (IS_ERR(tty)) {
|
||||||
tty_unlock();
|
tty_unlock();
|
||||||
tty_free_file(filp);
|
tty_free_file(filp);
|
||||||
|
Loading…
Reference in New Issue
Block a user