Lines Matching defs:tty

24 #include <tty.h>
50 tty::lock: Guards the access to tty::{input_buffer,settings::{termios,
51 window_size,pgrp_id}}. Moreover when held guarantees that tty::open_count
52 won't drop to zero. A tty and the tty connected to it (master and slave)
55 gTTYRequestLock: Guards access to tty::{reader,writer}_queue (most
64 {Reader,Writer}Locker classes. Upon construction they lock the tty,
65 (tty::lock) create a RequestOwner and queue Requests in the respective
66 reader/writer queues (tty::{reader,writer}_queue). The
80 static void tty_notify_select_event(struct tty* tty, uint8 event);
81 static void tty_notify_if_available(struct tty* tty, struct tty* otherTTY,
99 { recursive_lock_lock(fCookie->tty->lock); }
101 { recursive_lock_unlock(fCookie->tty->lock); }
120 struct tty* fSource;
121 struct tty* fTarget;
139 struct tty* fTTY;
403 conditionVariable.Init(this, "tty request");
494 fSource(fCookie->tty),
501 // Now that the tty pair is locked, we can check, whether the target is
504 // The target tty is open. As soon as we have appended a request to
531 // check the tty queues and notify the next in line, and send out select
597 // when closing a tty, we re-get the error with the tty lock being held.
639 fTTY(cookie->tty),
656 // check the tty queues and notify the next in line, and send out select
658 struct tty* otherTTY = fCookie->other_tty;
802 tty_input_putc_locked(struct tty* tty, int c)
804 const termios& termios = tty->settings->termios;
822 clear_line_buffer(tty->input_buffer);
824 if (tty->settings->pgrp_id != 0)
825 send_signal(-tty->settings->pgrp_id, signal);
838 if (line_buffer_tail_getc(tty->input_buffer, &lastChar)) {
843 line_buffer_putc(tty->input_buffer, lastChar);
850 while (line_buffer_tail_getc(tty->input_buffer, &lastChar)) {
855 line_buffer_putc(tty->input_buffer, lastChar);
863 tty->pending_eof++;
870 line_buffer_putc(tty->input_buffer, c);
875 tty_readable(struct tty* tty)
877 if (!tty->is_master && (tty->settings->termios.c_lflag & ICANON) != 0) {
878 return line_buffer_readable_line(tty->input_buffer,
879 tty->settings->termios.c_cc[VEOL],
880 tty->settings->termios.c_cc[VEOF]);
883 return line_buffer_readable(tty->input_buffer);
895 tty_notify_select_event(struct tty* tty, uint8 event)
897 TRACE(("tty_notify_select_event(%p, %u)\n", tty, event));
899 if (tty->select_pool)
900 notify_select_event_pool(tty->select_pool, event);
911 \param tty The TTY.
915 tty_notify_if_available(struct tty* tty, struct tty* otherTTY,
918 if (!tty)
923 int32 readable = tty_readable(tty);
926 if (!tty->reader_queue.IsEmpty())
927 tty->reader_queue.NotifyFirst(readable);
929 tty_notify_select_event(tty, B_SELECT_READ);
932 int32 writable = line_buffer_writable(tty->input_buffer);
935 if (!tty->writer_queue.IsEmpty()) {
936 tty->writer_queue.NotifyFirst(writable);
947 \param tty The master tty.
950 \param _bytesNeeded The number of bytes needed in the target tty's
956 process_input_char(struct tty* tty, char c, char* buffer,
959 const termios& termios = tty->settings->termios;
1003 \param tty The master tty.
1012 process_output_char(struct tty* tty, char c, char* buffer,
1015 const termios& termios = tty->settings->termios;
1074 struct tty* source = sourceCookie->tty;
1075 struct tty* target = sourceCookie->other_tty;
1153 // changed in the meantime (while we've unlocked the tty). Note,
1180 struct tty* target = sourceCookie->other_tty;
1201 sourceCookie->tty, target, length));
1223 tty_notify_if_available(target, sourceCookie->tty, true);
1236 // changed in the meantime (while we've unlocked the tty).
1328 tty_create(tty_service_func func, struct tty* master, struct tty** _tty)
1330 struct tty* tty = new(std::nothrow) (struct tty);
1331 if (tty == NULL)
1335 tty->is_master = true;
1336 tty->lock = new(std::nothrow) recursive_lock;
1337 tty->settings = new(std::nothrow) tty_settings;
1338 if (tty->lock == NULL || tty->settings == NULL) {
1339 delete tty->lock;
1340 delete tty->settings;
1341 delete tty;
1345 recursive_lock_init(tty->lock, "tty lock");
1346 reset_tty_settings(*tty->settings);
1348 tty->is_master = false;
1349 tty->lock = master->lock;
1350 tty->settings = master->settings;
1353 tty->ref_count = 0;
1354 tty->open_count = 0;
1355 tty->opened_count = 0;
1356 tty->select_pool = NULL;
1357 tty->pending_eof = 0;
1358 tty->hardware_bits = 0;
1359 tty->is_exclusive = false;
1361 status_t status = init_line_buffer(tty->input_buffer, TTY_BUFFER_SIZE);
1364 if (tty->is_master) {
1365 recursive_lock_destroy(tty->lock);
1366 delete tty->lock;
1368 delete tty;
1372 tty->service_func = func;
1374 *_tty = tty;
1381 tty_destroy(struct tty* tty)
1383 TRACE(("tty_destroy(%p)\n", tty));
1384 ASSERT(tty->ref_count == 0);
1386 uninit_line_buffer(tty->input_buffer);
1387 delete_select_sync_pool(tty->select_pool);
1388 if (tty->is_master) {
1389 recursive_lock_destroy(tty->lock);
1390 delete tty->lock;
1391 delete tty->settings;
1394 delete tty;
1399 tty_create_cookie(struct tty* tty, struct tty* otherTTY, uint32 openMode, tty_cookie** _cookie)
1405 cookie->blocking_semaphore = create_sem(0, "wait for tty close");
1412 cookie->tty = tty;
1419 RecursiveLocker locker(cookie->tty->lock);
1421 if (tty->is_exclusive && geteuid() != 0) {
1428 tty->cookies.Add(cookie);
1429 tty->open_count++;
1430 tty->ref_count++;
1431 tty->opened_count++;
1455 cookie->tty->reader_queue.NotifyError(cookie, B_FILE_ERROR);
1456 cookie->tty->writer_queue.NotifyError(cookie, B_FILE_ERROR);
1479 RecursiveLocker ttyLocker(cookie->tty->lock);
1482 cookie->tty->cookies.Remove(cookie);
1484 // close the tty, if no longer used
1485 if (--cookie->tty->open_count == 0) {
1486 // The last cookie of this tty has been closed. We're going to close
1501 if (!cookie->tty->writer_queue.IsEmpty()) {
1503 cookie->tty->writer_queue.NotifyError(B_FILE_ERROR);
1507 requestOwner.Enqueue(cookie, &cookie->tty->writer_queue);
1512 clear_line_buffer(cookie->tty->input_buffer);
1529 // notify a select read and write event on the other tty, if we've closed this tty
1535 cookie->tty->is_exclusive = false;
1543 RecursiveLocker locker(cookie->tty->lock);
1544 cookie->tty->ref_count--;
1558 struct tty* tty = cookie->tty;
1567 TRACE(("tty_input_read(tty = %p, length = %lu, mode = %" B_PRIu32 ")\n",
1568 tty, length, mode));
1581 if ((!tty->is_master) && ((tty->settings->termios.c_lflag & ICANON) == 0)) {
1585 bytesNeeded = tty->settings->termios.c_cc[VMIN];
1586 bigtime_t vtime = tty->settings->termios.c_cc[VTIME] * 100000;
1624 bool* hitEOF = canon && tty->pending_eof > 0 ? &_hitEOF : NULL;
1626 ssize_t bytesRead = line_buffer_user_read(tty->input_buffer, buffer,
1627 toRead, tty->settings->termios.c_cc[VEOF], hitEOF);
1641 tty->pending_eof--;
1667 if (sourceCookie->tty->is_master)
1677 struct tty* tty = cookie->tty;
1684 TRACE(("tty_ioctl: tty %p, op %" B_PRIu32 ", buffer %p, length %"
1685 B_PRIuSIZE "\n", tty, op, buffer, length));
1686 RecursiveLocker locker(tty->lock);
1701 TRACE(("tty: get attributes\n"));
1702 return user_memcpy(buffer, &tty->settings->termios,
1709 TRACE(("tty: set attributes (iflag = %" B_PRIx32 ", oflag = %"
1711 tty->settings->termios.c_iflag, tty->settings->termios.c_oflag,
1712 tty->settings->termios.c_cflag,
1713 tty->settings->termios.c_lflag));
1715 status_t status = user_memcpy(&tty->settings->termios, buffer,
1720 tty->service_func(tty, TTYSETMODES, &tty->settings->termios,
1728 TRACE(("tty: get pgrp_id\n"));
1729 return user_memcpy(buffer, &tty->settings->pgrp_id, sizeof(pid_t));
1733 TRACE(("tty: set pgrp_id\n"));
1739 status_t error = team_set_foreground_process_group(tty,
1742 tty->settings->pgrp_id = groupID;
1749 TRACE(("tty: become controlling tty\n"));
1752 // Only session leaders can become controlling tty
1755 // Check if already controlling tty
1756 if (team_get_controlling_tty() == tty)
1758 tty->settings->session_id = sessionID;
1759 tty->settings->pgrp_id = sessionID;
1760 team_set_controlling_tty(tty);
1771 TRACE(("tty: get session_id\n"));
1772 return user_memcpy(buffer, &tty->settings->session_id,
1779 TRACE(("tty: get window size\n"));
1780 return user_memcpy(buffer, &tty->settings->window_size,
1785 uint16 oldColumns = tty->settings->window_size.ws_col;
1786 uint16 oldRows = tty->settings->window_size.ws_row;
1788 TRACE(("tty: set window size\n"));
1789 if (user_memcpy(&tty->settings->window_size, buffer,
1795 if ((oldColumns != tty->settings->window_size.ws_col
1796 || oldRows != tty->settings->window_size.ws_row)
1797 && tty->settings->pgrp_id != 0) {
1798 send_signal(-tty->settings->pgrp_id, SIGWINCH);
1810 //dprintf("tty: warning: legacy BeOS opcode 'ichr'\n");
1867 toWrite = line_buffer_readable(tty->input_buffer);
1878 //dprintf("tty: unsupported TCXONC\n");
1894 result &= tty->service_func(tty, TTYSETDTR, &dtr, sizeof(dtr));
1899 result &= tty->service_func(tty, TTYSETRTS, &rts, sizeof(rts));
1907 tty->service_func(tty, TTYGETSIGNALS, NULL, 0);
1908 int bits = tty->hardware_bits;
1923 result &= tty->service_func(tty, TTYSETDTR, &dtr, sizeof(dtr));
1927 result &= tty->service_func(tty, TTYSETRTS, &rts, sizeof(rts));
1946 if (tty->service_func(tty, TTYSETBREAK, &set, sizeof(set)))
1956 struct tty* otherTTY = cookie->other_tty;
1964 clear_line_buffer(tty->input_buffer);
1966 if (tty->service_func(tty, TTYFLUSH, &value, sizeof(value)))
1974 tty->is_exclusive = true;
1980 tty->is_exclusive = false;
1985 TRACE(("tty: unsupported opcode %" B_PRIu32 "\n", op));
1993 struct tty* tty = cookie->tty;
2013 RecursiveLocker ttyLocker(tty->lock);
2016 struct tty* otherTTY = cookie->other_tty;
2021 status_t error = add_select_sync_pool_entry(&tty->select_pool, sync, event);
2036 if (tty->reader_queue.IsEmpty() && tty_readable(tty) > 0)
2050 bool echo = (tty->is_master
2051 && tty->settings->termios.c_lflag & ECHO);
2056 || (tty->writer_queue.IsEmpty()
2057 && line_buffer_writable(tty->input_buffer) > 0)) {
2076 struct tty* tty = cookie->tty;
2086 RecursiveLocker ttyLocker(tty->lock);
2088 return remove_select_sync_pool_entry(&tty->select_pool, sync, event);
2116 cookie->tty->hardware_bits |= bit;
2118 cookie->tty->hardware_bits &= ~bit;