summaryrefslogtreecommitdiffstats
path: root/sys/kern/tty.c
Commit message (Collapse)AuthorAgeFilesLines
* Add new make_dev_p(9) flag MAKEDEV_ETERNAL to inform devfs that createdkib2010-08-061-3/+3
| | | | | | | | | cdev will never be destroyed. Propagate the flag to devfs vnodes as VV_ETERNVALDEV. Use the flags to avoid acquiring devmtx and taking a thread reference on such nodes. In collaboration with: pho MFC after: 1 month
* Fix a race condition, where a TTY could be destroyed twice.ed2010-07-061-1/+2
| | | | | | | | | There are special cases where tty_rel_free() can be called twice in a row, namely when closing and revoking the TTY at the same moment. Only call destroy_dev_sched_cb() once. Reported by: Jeremie Le Hen MFC after: 1 week
* Make TIOCSTI work again.ed2010-01-041-6/+16
| | | | | | | | It looks like I didn't implement this when I imported MPSAFE TTY. Applications like mail(1) still use this. I think it's conceptually bad. Tested by: Pete French <petefrench ticketswitch com> MFC after: 2 weeks
* Update d_mmap() to accept vm_ooffset_t and vm_memattr_t.rnoland2009-12-291-4/+5
| | | | | | | | | | | | | This replaces d_mmap() with the d_mmap2() implementation and also changes the type of offset to vm_ooffset_t. Purge d_mmap2(). All driver modules will need to be rebuilt since D_VERSION is also bumped. Reviewed by: jhb@ MFC after: Not in this lifetime...
* Don't allocate an input buffer for a TTY when the receiver is turned off.ed2009-12-011-2/+4
| | | | | | | | | When the termios CREAD flag is not set, it makes little sense to allocate an input buffer. Just set the size to 0 in this case to reduce memory footprint. Disallow CREAD to be disabled for pseudo-devices to prevent foot-shooting.
* Among signal generation syscalls, only sigqueue(2) is allowed by POSIXkib2009-11-171-2/+14
| | | | | | | | | | | | | | | | | | | | | | | | | to fail due to lack of resources to queue siginfo. Add KSI_SIGQ flag that allows sigqueue_add() to fail while trying to allocate memory for new siginfo. When the flag is not set, behaviour is the same as for KSI_TRAP: if memory cannot be allocated, set bit in sq_kill. KSI_TRAP is kept to preserve KBI. Add SI_KERNEL si_code, to be used in siginfo.si_code when signal is generated by kernel. Deliver siginfo when signal is generated by kill(2) family of syscalls (SI_USER with properly filled si_uid and si_pid), or by kernel (SI_KERNEL, mostly job control or SIGIO). Since KSI_SIGQ flag is not set for the ksi, low memory condition cause old behaviour. Keep psignal(9) KBI intact, but modify it to generate SI_KERNEL si_code. Pgsignal(9) and gsignal(9) now take ksi explicitely. Add pksignal(9) that behaves like psignal but takes ksi, and ddb kill command implemented as pksignal(..., ksi = NULL) to not do allocation while in debugger. While there, remove some register specifiers and use ANSI C prototypes. Reviewed by: davidxu MFC after: 1 month
* Properly set the low watermarks when reducing the baud rate.ed2009-10-191-2/+2
| | | | | | | | | | | | | Now that buffers are deallocated lazily, we should not use tty*q_getsize() to obtain the buffer size to calculate the low watermarks. Doing this may cause the watermark to be placed outside the typical buffer size. This caused some regressions after my previous commit to the TTY code, which allows pseudo-devices to resize the buffers as well. Reported by: yongari, dougb MFC after: 1 week
* Allow the buffer size to be configured for pseudo-like TTY devices.ed2009-10-181-2/+13
| | | | | | | | | | | | | | | Devices that don't implement param() (which means they don't support hardware parameters such as flow control, baud rate) hardcode the baud rate to TTYDEF_SPEED. This means the buffer size cannot be configured, which is a little inconvenient when using canonical mode with big lines of input, etc. Make it adjustable, but do clamp it between B50 and B115200 to prevent awkward buffer sizes. Remove the baud rate assignment from /etc/gettytab. Trust the kernel to fill in a proper value. Reported by: Mikolaj Golub <to my trociny gmail com> MFC after: 1 month
* Make lock devices work properly.ed2009-10-181-0/+28
| | | | | | | | | | It turned out I did add the code to use the init state devices to set the termios structure when opening the device, but it seems I totally forgot to add the bits required to force the actual locking of flags through the lock state devices. Reported by: ru MFC after: 1 week (to be discussed)
* Use C99 initialization for struct filterops.rwatson2009-09-121-4/+10
| | | | | | Obtained from: Mac OS X Sponsored by: Apple Inc. MFC after: 3 weeks
* Fix regressions in return events of poll() on TTYs.ed2009-07-081-9/+7
| | | | | | | | | As pointed out, POLLHUP should be generated, even if it hasn't been specified on input. It is also not allowed to return both POLLOUT and POLLHUP at the same time. Reported by: jilles Approved by: re (kib)
* Add FIONWRITE support to TTYs.ed2009-06-281-3/+4
| | | | | | | TTYs already supported TIOCOUTQ, but FIONWRITE seems to be a more generic name for this. Approved by: re (kib)
* Improve my last commit: use a separate condvar to serialize.ed2009-06-231-2/+4
| | | | | | | The advantage of using a separate condvar is that we can just use cv_signal(9) instead of cv_broadcast(9). It makes no sense to wake up multiple threads. It also makes the TTY code easier to understand. t_dcdwait sounds totally unrelated.
* Use dcdwait to block threads to serialize writes.ed2009-06-231-2/+3
| | | | | | | | I suspect the usage of bgwait causes a lot of spurious wakeups when threads are blocked in the background, because they will be woken up each time a write() call is performed. Also wakeup dcdwait when the TTY is abandoned.
* Improve nested jail awareness of devfs by handling credentials.ed2009-06-201-7/+0
| | | | | | | | | | | | | | | | | | Now that we start to use credentials on character devices more often (because of MPSAFE TTY), move the prison-checks that are in place in the TTY code into devfs. Instead of strictly comparing the prisons, use the more common prison_check() function to compare credentials. This means that pseudo-terminals are only visible in devfs by processes within the same jail and parent jails. Even though regular users in parent jails can now interact with pseudo-terminals from child jails, this seems to be the right approach. These processes are also capable of interacting with the jailed processes anyway, through signals for example. Reviewed by: kib, rwatson (older version)
* Perform some more cleanups to in-kernel session handling.ed2009-06-151-1/+1
| | | | | | | | | | | | | | | | | | | | | The code that was in place in exit1() was mainly based on code from the old TTY layer. The main reason behind this, was because at one moment I ran a system that had two TTY layers in place at the same time. It is now sufficient to do the following: - Remove references from the session structure to the TTY vnode and the session leader. - If we have a controlling TTY and the session used by the TTY is equal to our session, send the SIGHUP. - If we have a vnode to the controlling TTY which has not been revoked, revoke it. While there, change sys/kern/tty.c to use s_ttyp in the comparison instead of s_ttyvp. It should not make any difference, because s_ttyvp can only become null when the session leader already left, but it's nicer to compare against the proper value.
* Make tcsetsid(3) work on revoked TTYs.ed2009-06-151-3/+6
| | | | | | | | | | | Right now the only way to make tcsetsid(3)/TIOCSCTTY work, is by ensuring the session leader is dead. This means that an application that catches SIGHUPs and performs a sleep prevents us from assigning a new session leader. Change the code to make it work on revoked TTYs as well. This allows us to change init(8) to make the shutdown script run in a more clean environment.
* Revert my previous change, because it reintroduces an old regression.ed2009-06-121-7/+7
| | | | | | | | | Because our rc scripts also open the /etc/ttyv* nodes, it revokes the console, preventing startup messages from being displayed. I really have to think about this. Maybe we should just give the console its own TTY and let it build on top of other TTYs. I'm still not sure what to do with input handling there.
* Prevent yet another staircase effect bug in the console device.ed2009-06-121-7/+7
| | | | | | | | | | | | | | | | | | Even though I thought I fixed the staircase issue (and I was no longer able to reproduce it), I got some reports of the issue still being there. It turns out the staircase effect still occurred when /dev/console was kept open while killing the getty on the same TTY (ttyv0). For some reason I can't figure out how the old TTY code dealt with that, so I assume the issue has always been there. I only exposed it more by merging consolectl with ttyv0, which means that the issue was present, even on systems without a serial console. I'm now marking the console device as being closed when closing the regular TTY device node. This means that when the getty shuts down, init(8) will open /dev/console, which means the termios attributes will always be reset in this case.
* Adapt vfs kqfilter to the shared vnode lock used by zfs write vop. Usekib2009-06-101-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | vnode interlock to protect the knote fields [1]. The locking assumes that shared vnode lock is held, thus we get exclusive access to knote either by exclusive vnode lock protection, or by shared vnode lock + vnode interlock. Do not use kl_locked() method to assert either lock ownership or the fact that curthread does not own the lock. For shared locks, ownership is not recorded, e.g. VOP_ISLOCKED can return LK_SHARED for the shared lock not owned by curthread, causing false positives in kqueue subsystem assertions about knlist lock. Remove kl_locked method from knlist lock vector, and add two separate assertion methods kl_assert_locked and kl_assert_unlocked, that are supposed to use proper asserts. Change knlist_init accordingly. Add convenience function knlist_init_mtx to reduce number of arguments for typical knlist initialization. Submitted by: jhb [1] Noted by: jhb [2] Reviewed by: jhb Tested by: rnoland
* Do not dereference vp->v_rdev without holding any of dev_mtx or vnodekib2009-06-081-8/+20
| | | | | | | lock. Use code similar to devfs_fp_check(), but inlined to feet other checks performed by ttyhook_register(). Reviewed by: ed
* Last minute TTY API change: remove mutex argument from tty_alloc().ed2009-05-291-1/+8
| | | | | | | | | | I don't want people to override the mutex when allocating a TTY. It has to be there, to keep drivers like syscons happy. So I'm creating a tty_alloc_mutex() which can be used in those cases. tty_alloc_mutex() should eventually be removed. The advantage of this approach, is that we can just remove a function, without breaking the regular API in the future.
* Get rid of M_TEMP.ed2009-05-261-2/+2
|
* Block when initially opening a TTY multiple times.ed2009-05-241-5/+11
| | | | | | | | | | | | | | | In the original MPSAFE TTY code, I changed the behaviour by returning EBUSY. I thought this made more sense, because it's basically a race to see who gets the TTY first. It turns out this is not a good change, because it also causes EBUSY to be returned when another process is closing the TTY. This can happen during startup, when /etc/rc (or one of its children) is still busy draining its data and /sbin/init is attempting to open the TTY to spawn a getty. Reported by: bz Tested by: bz
* - Implement a lockless file descriptor lookup algorithm injeff2009-05-141-4/+7
| | | | | | | | | | | | fget_unlocked(). - Save old file descriptor tables created on expansion until the entire descriptor table is freed so that pointers may be followed without regard for expanders. - Mark the file zone as NOFREE so we may attempt to reference potentially freed files. - Convert several fget_locked() users to fget_unlocked(). This requires us to manage reference counts explicitly but reduces locking overhead in the common case.
* Remove unneeded check for SESS_LEADER().ed2009-05-041-1/+1
| | | | We perform the same check ~10 lines above.
* Fix tty_wait_background() to comply with standards.ed2009-04-081-8/+16
| | | | | | | | | It turns out my handling of SIGTTOU and SIGTTIN didn't entirely comply to the standards. It is true that in the SIGTTOU case we should not return EIO when the signal is ignored/blocked, but in the SIGTTIN case we must. See also: POSIX issue 7 section 11.1.4
* Improve my previous changes to the TTY code: also remove memcpy().ed2009-03-011-5/+5
| | | | | | | | It's better to just use internal language constructs, because it is likely the compiler has a better opinion on whether to perform inlining, which is very likely to happen to struct winsize. Submitted by: Christoph Mallon <christoph mallon gmx de>
* Replace bcopy() calls inside the TTY layer with memcpy()/strlcpy().ed2009-02-281-7/+7
| | | | | In all these cases the buffers never overlap. Program names are also likely to be shorter, so use a regular strlcpy() to copy p_comm.
* Serialize write() calls on TTYs.ed2009-02-111-6/+24
| | | | | | | | | | | | | | | | | | | | Just like the old TTY layer, the current MPSAFE TTY layer does not make any attempt to serialize calls of write(). Data is copied into the kernel in 256 (TTY_STACKBUF) byte chunks. If a write() call occurs at the same time, the data may interleave. This is especially likely when the TTY starts blocking, because the output queue reaches the high watermark. I've implemented this by adding a new flag, TTY_BUSY_OUT, which is used to mark a TTY as having a thread stuck in write(). Because I don't want non-blocking processes to be possibly blocked by a sleeping thread, I'm still allowing it to bypass the protection. According to this message, the Linux kernel returns EAGAIN in such cases, but I think that's a little too restrictive: http://kerneltrap.org/index.php?q=mailarchive/linux-kernel/2007/5/2/85418/thread PR: kern/118287
* Don't leave the console TTY constantly open.ed2009-02-051-31/+40
| | | | | | | | | | | | | | | | | When we leave the console TTY constantly open, we never reset the termios attributes. This causes output processing, echoing, etc. not to be reset to the proper values when going into single user mode after the system has booted. It also causes nl-to-crnl-conversion not to take place during shutdown, which causes a `staircase effect'. This patch adds a new TTY flag, TF_OPENED_CONS, which is set when the TTY is opened through /dev/console. Because the flags are only used by the kernel and the pstat(8) utility, I've decided to renumber the TTY flags. This shouldn't be an issue, because the TTY layer is not yet part of a stable release. Reported by: Mark Atkinson <atkin901 yahoo com> Tested by: sepotvin
* Slightly improve the design of the TTY buffer.ed2009-02-031-3/+0
| | | | | | | | | | | | | | | | | | | The TTY buffers used the standard <sys/queue.h> lists. Unfortunately they have a big shortcoming. If you want to have a double linked list, but no tail pointer, it's still not possible to obtain the previous element in the list. Inside the buffers we don't need them. This is why I switched to custom linked list macros. The macros will also keep track of the amount of items in the list. Because it doesn't use a sentinel, we can just initialize the queues with zero. In its simplest form (the output queue), we will only keep two references to blocks in the queue, namely the head of the list and the last block in use. All free blocks are stored behind the last block in use. I noticed there was a very subtle bug in the previous code: in a very uncommon corner case, it would uma_zfree() a block in the queue before calling memcpy() to extract the data from the block.
* Use the proper flag to let kern.ttys be executed without Giant.ed2009-01-261-1/+1
| | | | Pointed out by: jhb
* Mark kern.ttys as MPSAFE.ed2009-01-241-1/+1
| | | | | sysctl now allows Giantless calls, so make kern.ttys use this. If it needs Giant, it locks the proper TTY anyway.
* Fix a corner case in my previous commit.ed2009-01-021-1/+2
| | | | | Even though there are not many setups that have absolutely no console device, make sure a close() on a TTY doesn't dereference a null pointer.
* Don't let /dev/console be revoked if the TTY below is being closed.ed2009-01-021-0/+7
| | | | | | | | | | | During startup some of the syscons TTY's are used to set attributes like the screensaver and mouse options. These actions cause /dev/console to be rendered unusable. Fix the issue by leaving the TTY opened when it is used as the console device. Reported by: imp
* Let wchan names more closely match pre-MPSAFE TTY behaviour.ed2008-12-201-3/+3
| | | | | | | | | Right now the wchan strings "ttyinp" and "ttybgw" only differ one character from the strings we used prior to MPSAFE TTY. Just rename them back to their pre-MPSAFE TTY counterparts. Also rename "ttylck" to "ttymtx", which should make it more clear that a process is blocked on the TTY mutex, not some other form of locking.
* Further beautify the lock strings to be more pleasing to the eye andivoras2008-12-191-4/+4
| | | | | | | self documenting within 6 characters. Reviewed by: ed (older version) Approved by: gnn (older version)
* Remove spaces in wait object names to make top (1) output prettier andivoras2008-12-181-5/+5
| | | | | | | unbreak scripts that examine ps (1) output. Reviewed by: ed Approved by: gnn (mentor)
* Change ttyhook_register() second argument from thread to process pointer.mav2008-12-131-4/+11
| | | | | Thread was not really needed there, while previous ng_tty implementation that used thread pointer had locking issues (using sx while holding mutex).
* Reduce the default baud rate of PTY's to 9600.ed2008-11-081-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | On RELENG_6 (and probably RELENG_7) we see our syscons windows and pseudo-terminals have the following buffer sizes: | LINE RAW CAN OUT IHIWT ILOWT OHWT LWT COL STATE SESS PGID DISC | ttyv0 0 0 0 7680 6720 2052 256 7 OCcl 1146 1146 term | ttyp0 0 0 0 7680 6720 1296 256 0 OCc 82033 82033 term These buffer sizes make no sense, because we often have much more output than input, but I guess having higher input buffer sizes improves guarantees of the system. On MPSAFE TTY I just sent both the input and output buffer sizes to 7 KB, which is pretty big on a standard FreeBSD install with 8 syscons windows and some PTY's. Reduce the baud rate to 9600 baud, which means we now have the following buffer sizes: | LINE INQ CAN LIN LOW OUTQ USE LOW COL SESS PGID STATE | ttyv0 1920 0 0 192 1984 0 199 7 2401 2401 Oil | pts/0 1920 0 0 192 1984 0 199 5631 1305 2526 Oi This is a lot smaller, but for pseudo-devices this should be good enough. You need to do a lot of punching to fill up a 7.5 KB input buffer. If it turns out things don't work out this way, we'll just switch to 19200 baud.
* Clamp the values of t_column to 5 digits in `pstat -t' and `show all ttys'.ed2008-11-011-1/+1
| | | | | | | | We often run into these very high column numbers when we run curses applications, because they don't print any newlines. This messes up the table output of `pstat -t'. If these numbers get really high, they aren't of any use to the reader anyway. Convert them to `99999' when they run out of bounds.
* Reimplement the /dev/console device node.ed2008-11-011-9/+87
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | One of the pieces of code that I had left alone during the development of the MPSAFE TTY layer, was tty_cons.c. This file actually has two different functions: - It contains low-level console input/output routines (cnputc(), etc). - It creates /dev/console and wraps all its cdevsw calls to the appropriate TTY. This commit reimplements the second set of functions by moving it directly into the TTY layer. /dev/console is now a character device node that's basically a regular TTY, but does a lookup of `si_drv1' each time you open it. d_write has also been changed to call log_console(). d_close() is not present, because we must make sure we don't revoke the TTY after writing a log message to it. Even though I'm not convinced this is in line with the future directions of our console code, it is a good move for now. It removes recursive locking from the top half of the TTY layer. The previous implementation called into the TTY layer with Giant held. I'm renaming tty_cons.c to kern_cons.c now. The code hardly contains any TTY related bits, so we'd better give it a less misleading name. Tested by: Andrzej Tobola <ato iem pw edu pl>, Carlos A.M. dos Santos <unixmania gmail com>, Eygene Ryabinkin <rea-fbsd codelabs ru>
* Fix spelling mistake in the last rev.thompsa2008-10-211-1/+1
|
* If we have getc_inject hooked then the outq buffer is inaccessible to thethompsa2008-10-211-0/+4
| | | | | | driver so skip the drain rather than waiting indefinitely. Reviewed by: ed
* Import some improvements to the TTY code from the MPSAFE TTY branch.ed2008-10-151-37/+162
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Change the ddb(4) commands to be more useful (by thompsa@): - `show ttys' is now called `show all ttys'. This command will now also display the address where the TTY data structure resides. - Add `show tty <addr>', which dumps the TTY in a readable form. - Place an upper bound on the TTY buffer sizes. Some drivers do not want to care about baud rates. Protect these drivers by preventing the TTY buffers from getting enormous. Right now we'll just clamp it to 64K, which is pretty high, taking into account that these buffers are only used by the built-in discipline. - Only call ttydev_leave() when needed. Back in April/May the TTY reference counting mechanism was a little different, which required us to call ttydev_leave() each time we finished a cdev operation. Nowadays we only need to call ttydev_leave() when we really mark it as being closed. - Improve return codes of read() and write() on TTY device nodes. - Make sure we really wake up all blocked threads when the driver calls tty_rel_gone(). There were some possible code paths where we didn't properly wake up any readers/writers. - Add extra assertions to prevent sleeping on a TTY that has been abandoned by the driver. - Use ttydev_cdevsw as a more reliable method to figure out whether a device node is a real TTY device node. Obtained from: //depot/projects/mpsafetty/... Reviewed by: thompsa
* Don't forget to initialize `int error' in ttydev_open().ed2008-09-261-1/+1
| | | | | | | | | | I've had some reports in the past that opening an already opened TTY through, for example, /dev/tty can fail with random error codes. Looking at ttydev_open(), I can see there is a way `error' is returned without initialising it. Even though I haven't had any confirmation this fixes the bug, I'll fix it anyway. Reported by: Andrzej Tobola <ato iem pw edu pl>
* Fix a crash when calling tty_rel_free() while draining during closure.ed2008-09-241-2/+2
| | | | | | | | | | | | Yesterday I got two reports of potential crashes, related to TTY deallocation during device closure. When a thread is in TF_OPENCLOSE, draining its output upon closure, we should not allow calls to tty_rel_free() to happen at the same time. This could cause the TTY to be torn down twice. PR: kern/127561 Reported by: KOIE Hidetaka <koie suri co jp> Discussed with: thompsa
* Introduce a hooks layer for the MPSAFE TTY layer.ed2008-09-221-2/+88
| | | | | | | | | | | | | | | | | | | | One of the features that prevented us from fixing some of the TTY consumers to work once again, was an interface that allowed consumers to do the following: - `Sniff' incoming data, which is used by the snp(4) driver. - Take direct control of the input and output paths of a TTY, which is used by ng_tty(4), ppp(4), sl(4), etc. There's no practical advantage in committing a hooks layer without having any consumers. In P4 there is a preliminary port of snp(4) and thompsa@ is busy porting ng_tty(4) to this interface. I already want to have it in the tree, because this may stimulate others to work on the remaining modules. Discussed with: thompsa Obtained from: //depot/projects/mpsafetty/...
* Fix minor TTY API inconsistency.ed2008-09-161-0/+3
| | | | | | | | | | Unlike tty_rel_gone() and tty_rel_sess(), the tty_rel_pgrp() routine does not unlock the TTY. I once had the idea to make the code call tty_rel_pgrp() and tty_rel_sess(), picking up the TTY lock once. This turned out a little harder than I expected, so this is how it works now. It's a lot easier if we just let tty_rel_pgrp() unlock the TTY, because the other routines do this anyway.
OpenPOWER on IntegriCloud