有关tty hangup

调用函数tty_hangup触发work function do_tty_hangup的运行,   函数do_tty_hangup主要设置了filp->f_op = &hung_up_tty_fops;

后面的file operation操作就调用hung_up_tty_fops这组函数,这组函数实际上不能执行对写操作。

tty_hangup   -   trigger a hangup event

void tty_hangup(struct tty_struct *tty)
{
    schedule_work(&tty->hangup_work);
}

initialize_tty_struct -> INIT_WORK(&tty->hangup_work, do_tty_hangup);

static void do_tty_hangup(struct work_struct *work)
{
    struct tty_struct *tty =
        container_of(work, struct tty_struct, hangup_work);

    __tty_hangup(tty);
}

void __tty_hangup(struct tty_struct *tty)
{

    list_for_each_entry(priv, &tty->tty_files, list) {
        filp = priv->file;
        if (filp->f_op->write == redirected_tty_write)
            cons_filp = filp;
        if (filp->f_op->write != tty_write)
            continue;
        closecount++;
        __tty_fasync(-1, filp, 0);    /* can't block */
        filp->f_op = &hung_up_tty_fops;
    }

}


static const struct file_operations hung_up_tty_fops = {
    .llseek        = no_llseek,
    .read        = hung_up_tty_read,
    .write        = hung_up_tty_write,
    .poll        = hung_up_tty_poll,
    .unlocked_ioctl    = hung_up_tty_ioctl,
    .compat_ioctl    = hung_up_tty_compat_ioctl,
    .release    = tty_release,
};


static ssize_t hung_up_tty_read(struct file *file, char __user *buf,
                size_t count, loff_t *ppos)
{
    return 0;
}

static ssize_t hung_up_tty_write(struct file *file, const char __user *buf,
                 size_t count, loff_t *ppos)
{
    return -EIO;
}

/* No kernel lock held - none needed ;) */
static unsigned int hung_up_tty_poll(struct file *filp, poll_table *wait)
{
    return POLLIN | POLLOUT | POLLERR | POLLHUP | POLLRDNORM | POLLWRNORM;
}

static long hung_up_tty_ioctl(struct file *file, unsigned int cmd,
        unsigned long arg)
{
    return cmd == TIOCSPGRP ? -ENOTTY : -EIO;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值