From 519eb6b79c76864508e2d51e0e3cb5be2d0f36e1 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Sun, 19 May 2024 23:08:13 -0400 Subject: kernel: tty: Define TTY open hook Signed-off-by: Ian Moffett --- sys/kern/kern_tty.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/sys/kern/kern_tty.c b/sys/kern/kern_tty.c index 5c060a4..f8a4877 100644 --- a/sys/kern/kern_tty.c +++ b/sys/kern/kern_tty.c @@ -174,6 +174,20 @@ tty_ioctl(struct device *dev, uint32_t cmd, uintptr_t arg) return 0; } +static int +tty_open(struct device *dev) +{ + /* TODO: Support multiple TTYs */ + struct tty *tty = &g_root_tty; + struct tty_ring *ring = &tty->outring; + + /* Ensure the ring is clean */ + spinlock_acquire(&tty->rlock); + tty_reset_ring(ring); + spinlock_release(&tty->rlock); + return 0; +} + /* * Serialized wrapper over __tty_flush() */ @@ -286,6 +300,7 @@ tty_attach(struct tty *tty) dev->read = tty_dev_read; dev->ioctl = tty_ioctl; + dev->open = tty_open; dev->blocksize = 1; snprintf(devname, sizeof(devname), "tty%d", tty->id); -- cgit v1.2.3