1 2 3 | int fasync_helper(int fd, struct file *filp, int mode, struct fasync_struct **fa); void kill_fasync(struct fasync_struct **fa, int sig, int band); |
1 2 3 4 5 6 7 8 9 10 | struct my_dev{ wait_queue_head_t in, out; ... struct fasync_struct *async_queue; }; static int my_f_fasync(int fd, struct file *filp, int mode) { struct my_dev *dev = filp->private_data; return fasync_helper(fd, filp, mode, &dev->async_queue); } |
1 2 | if (dev->async_queue) kill_fasync(&dev->async_queue, SIGIO, POLL_IN); |
1 2 | /* remove this filp from the asynchronously notified filp's */ my_f_fasync(-1, filp, 0); |
1 2 3 4 5 6 7 8 | case F_SETSIG: /* arg == 0 restores default behaviour. */ if (arg < 0 || arg > _NSIG) { break; } err = 0; filp->f_owner.signum = arg; break; |
1 2 3 4 5 | /* Don't send SIGURG to processes which have not set a queued signum: SIGURG has its own default signalling mechanism. */ if (!(sig == SIGURG && fown->signum == 0)) send_sigio(fown, fa->fa_fd, band); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | switch (fown->signum) { siginfo_t si; default: /* Queue a rt signal with the appropriate fd as its value. We use SI_SIGIO as the source, not SI_KERNEL, since kernel signals always get delivered even if we can't queue. Failure to queue in this case _should_ be reported; we fall back to SIGIO in that case. --sct */ si.si_signo = fown->signum; si.si_errno = 0; si.si_code = reason; /* Make sure we are called with one of the POLL_* reasons, otherwise we could leak kernel stack into userspace. */ if ((reason & __SI_MASK) != __SI_POLL) BUG(); if (reason - POLL_IN >= NSIGPOLL) si.si_band = ~0L; else si.si_band = band_table[reason - POLL_IN]; si.si_fd = fd; if (!send_sig_info(fown->signum, &si, p)) break; /* fall-through: fall back on the old plain SIGIO signal */ case 0: send_sig(SIGIO, p, 1); } |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |