diff --git a/base/usr/include/kernel/pty.h b/base/usr/include/kernel/pty.h index 0854c0d7..3808a270 100644 --- a/base/usr/include/kernel/pty.h +++ b/base/usr/include/kernel/pty.h @@ -43,4 +43,4 @@ typedef struct pty { void tty_output_process_slave(pty_t * pty, uint8_t c); void tty_output_process(pty_t * pty, uint8_t c); void tty_input_process(pty_t * pty, uint8_t c); -pty_t * pty_new(struct winsize * size); +pty_t * pty_new(struct winsize * size, int index); diff --git a/kernel/arch/x86_64/serial.c b/kernel/arch/x86_64/serial.c index f123bff4..ef799521 100644 --- a/kernel/arch/x86_64/serial.c +++ b/kernel/arch/x86_64/serial.c @@ -140,7 +140,7 @@ static void serial_fill_name(pty_t * pty, char * name) { } static fs_node_t * serial_device_create(int port) { - pty_t * pty = pty_new(NULL); + pty_t * pty = pty_new(NULL, 0); *pty_for_port(port) = pty; pty->write_out = serial_write_out; pty->fill_name = serial_fill_name; diff --git a/kernel/vfs/tty.c b/kernel/vfs/tty.c index 46a1bcd3..14aad82b 100644 --- a/kernel/vfs/tty.c +++ b/kernel/vfs/tty.c @@ -381,7 +381,9 @@ void open_pty_slave(fs_node_t * node, unsigned int flags) { void close_pty_slave(fs_node_t * node) { pty_t * pty = (pty_t *)node->device; - hashmap_remove(_pty_index, (void*)pty->name); + if (pty->name) { + hashmap_remove(_pty_index, (void*)pty->name); + } return; } @@ -646,7 +648,7 @@ void pty_install(void) { vfs_mount("/dev/tty", _dev_tty); } -pty_t * pty_new(struct winsize * size) { +pty_t * pty_new(struct winsize * size, int index) { if (!_pty_index) { pty_install(); @@ -667,13 +669,15 @@ pty_t * pty_new(struct winsize * size) { pty->slave = pty_slave_create(pty); /* tty name */ - pty->name = _pty_counter++; + pty->name = index; pty->fill_name = tty_fill_name; pty->write_in = pty_write_in; pty->write_out = pty_write_out; - hashmap_set(_pty_index, (void*)pty->name, pty); + if (index) { + hashmap_set(_pty_index, (void*)pty->name, pty); + } if (size) { memcpy(&pty->size, size, sizeof(struct winsize)); @@ -713,7 +717,7 @@ pty_t * pty_new(struct winsize * size) { } int pty_create(void *size, fs_node_t ** fs_master, fs_node_t ** fs_slave) { - pty_t * pty = pty_new(size); + pty_t * pty = pty_new(size, ++_pty_counter); *fs_master = pty->master; *fs_slave = pty->slave;