| 227 | } |
| 228 | |
| 229 | static void |
| 230 | ttydev_leave(struct tty *tp) |
| 231 | { |
| 232 | |
| 233 | tty_assert_locked(tp); |
| 234 | |
| 235 | if (tty_opened(tp) || tp->t_flags & TF_OPENCLOSE) { |
| 236 | /* Device is still opened somewhere. */ |
| 237 | tty_unlock(tp); |
| 238 | return; |
| 239 | } |
| 240 | |
| 241 | tp->t_flags |= TF_OPENCLOSE; |
| 242 | |
| 243 | /* Remove console TTY. */ |
| 244 | if (constty == tp) |
| 245 | constty_clear(); |
| 246 | |
| 247 | /* Drain any output. */ |
| 248 | if (!tty_gone(tp)) |
| 249 | tty_drain(tp, 1); |
| 250 | |
| 251 | ttydisc_close(tp); |
| 252 | |
| 253 | /* Free i/o queues now since they might be large. */ |
| 254 | ttyinq_free(&tp->t_inq); |
| 255 | tp->t_inlow = 0; |
| 256 | ttyoutq_free(&tp->t_outq); |
| 257 | tp->t_outlow = 0; |
| 258 | |
| 259 | knlist_clear(&tp->t_inpoll.si_note, 1); |
| 260 | knlist_clear(&tp->t_outpoll.si_note, 1); |
| 261 | |
| 262 | if (!tty_gone(tp)) |
| 263 | ttydevsw_close(tp); |
| 264 | |
| 265 | tp->t_flags &= ~TF_OPENCLOSE; |
| 266 | cv_broadcast(&tp->t_dcdwait); |
| 267 | tty_rel_free(tp); |
| 268 | } |
| 269 | |
| 270 | /* |
| 271 | * Operations that are exposed through the character device in /dev. |
no test coverage detected