History log of /freebsd-9.3-release/sys/dev/pty/pty.c
Revision Date Author Comments
(<<< Hide modified files)
(Show modified files >>>)
# 267654 19-Jun-2014 gjb

Copy stable/9 to releng/9.3 as part of the 9.3-RELEASE cycle.

Approved by: re (implicit)
Sponsored by: The FreeBSD Foundation

# 225736 22-Sep-2011 kensmith

Copy head to stable/9 as part of 9.0-RELEASE release cycle.

Approved by: re (implicit)


# 223575 26-Jun-2011 ed

Fix whitespace inconsistencies in the TTY layer and its drivers owned by me.


# 216952 04-Jan-2011 kib

Finish r210923, 210926. Mark some devices as eternal.

MFC after: 2 weeks


# 196886 06-Sep-2009 ed

Move ptmx into pty(4).

Now that pty(4) is a loadable kernel module, I'd better move /dev/ptmx
in there as well. This means that pty(4) now provides almost all
pseudo-terminal compatibility code. This means it's very easy to test
whether applications use the proper library interfaces when allocating
pseudo-terminals (namely posix_openpt and openpty).


# 196480 23-Aug-2009 ed

Allow pty(4) to be loaded as a kld.

Unfortunately, the wrappers that are present in pts(4) don't have the
mechanics to allow pty(4) to be unloaded safely, so I'm forcing this kld
to return EBUSY. This also means we have to enable some extra code in
pts(4) unconditionally.

Proposed by: rwatson


# 196378 19-Aug-2009 ed

Small changes to the warning message generated by pty(4):

- Only print the warning once, instead of filling up the screen.
- Use the word "legacy" for the pty_warningcnt description, to prevent
confusion.
- Use log() instead of printf().

Discussed with: rwatson, jhb
Approved by: re (kib)


# 189060 26-Feb-2009 ed

Don't use PTY name as format string, even though it isn't insecure here.

It's guaranteed that the `name' variable always contains a string of the
form pty[l‐sL‐S][0‐9a‐v], but I'd rather keep the compiler happy (LLVM).


# 187680 25-Jan-2009 ed

Remove unneeded use of device unit numbers from pty(4).

A much more simple approach to generate the slave device name, is to
obtain the device name of the master and replace 'p' by 't'.


# 182069 23-Aug-2008 ed

Allow the user to suppress the rate-limited pty(4) warning.

The pty(4) driver raises up to warnings when an old BSD-style PTY is
created. The reason why I added this warning, was to make it easier to
spot applications that allocate BSD-style PTY's, while they should just
use openpty() or posix_openpt().

Add a sysctl, which allows you to override the number of remaining
messages, making it possible to suppress the warnings.

Requested by: kib
Reviewed by: kib


# 181905 20-Aug-2008 ed

Integrate the new MPSAFE TTY layer to the FreeBSD operating system.

The last half year I've been working on a replacement TTY layer for the
FreeBSD kernel. The new TTY layer was designed to improve the following:

- Improved driver model:

The old TTY layer has a driver model that is not abstract enough to
make it friendly to use. A good example is the output path, where the
device drivers directly access the output buffers. This means that an
in-kernel PPP implementation must always convert network buffers into
TTY buffers.

If a PPP implementation would be built on top of the new TTY layer
(still needs a hooks layer, though), it would allow the PPP
implementation to directly hand the data to the TTY driver.

- Improved hotplugging:

With the old TTY layer, it isn't entirely safe to destroy TTY's from
the system. This implementation has a two-step destructing design,
where the driver first abandons the TTY. After all threads have left
the TTY, the TTY layer calls a routine in the driver, which can be
used to free resources (unit numbers, etc).

The pts(4) driver also implements this feature, which means
posix_openpt() will now return PTY's that are created on the fly.

- Improved performance:

One of the major improvements is the per-TTY mutex, which is expected
to improve scalability when compared to the old Giant locking.
Another change is the unbuffered copying to userspace, which is both
used on TTY device nodes and PTY masters.

Upgrading should be quite straightforward. Unlike previous versions,
existing kernel configuration files do not need to be changed, except
when they reference device drivers that are listed in UPDATING.

Obtained from: //depot/projects/mpsafetty/...
Approved by: philip (ex-mentor)
Discussed: on the lists, at BSDCan, at the DevSummit
Sponsored by: Snow B.V., the Netherlands
dcons(4) fixed by: kan


# 181301 04-Aug-2008 jhb

Close two different races with concurrent opens of pty master devices
that could result in leaked ttys or a leaked pty + tty pair.

MFC after: 1 week


# 177253 16-Mar-2008 rwatson

In keeping with style(9)'s recommendations on macros, use a ';'
after each SYSINIT() macro invocation. This makes a number of
lightweight C parsers much happier with the FreeBSD kernel
source, including cflow's prcc and lxr.

MFC after: 1 month
Discussed with: imp, rink


# 175669 26-Jan-2008 kib

In rev. 1.156, the convertion of the minor number to the unit number
resulted in the argument to the make_dev() to be a unit number.

Correct this by supplying a minor number to make_dev(), and using
the unit number for the calculation of the slave tty name.

Reported and tested by: Peter Holm
Reviewed by: jhb
Yet another pointy hat to: kib
MFC after: 1 day


# 175451 18-Jan-2008 kib

In the rev. 1.153, the one place for converting minor number to unit
was missed. As result, pty_create_slave() may index out of the names[]
bounds, creating wrong slave tty names.

Tested by: kensmith
Reviewed by: jhb
MFC after: 3 days


# 173755 19-Nov-2007 jhb

Bump up the number of ttys supported by pty(4) to 512 by making use of
[pt]ty[lmnoLMNO][0-9a-v].

MFC after: 3 days
Reviewed by: rwatson


# 173487 08-Nov-2007 jhb

A couple of optimizations to the last commit.

Submitted by: Christoph Mallon christoph mallon of gmx de


# 173456 08-Nov-2007 jhb

Make it easier to add more ptys to the pty(4) driver:
- Use unit2minor() and minor2unit() to generate minor numbers to support
unit numbers higher than 255.
- Use simple string operations on the 'names' array rather than hard-coded
constants and switch statements so that more ptys can be added by simply
expanding the 'names' array.

MFC after: 1 week


# 171185 03-Jul-2007 kib

Use make_dev_credf(MAKEDEV_REF) instead of make_dev() from pty clone handler.

Debugging help and testing by: Peter Holm
Approved by: re (kensmith)


# 164033 06-Nov-2006 rwatson

Sweep kernel replacing suser(9) calls with priv(9) calls, assigning
specific privilege names to a broad range of privileges. These may
require some future tweaking.

Sponsored by: nCircle Network Security, Inc.
Obtained from: TrustedBSD Project
Discussed on: arch@
Reviewed (at least in part) by: mlaier, jmg, pjd, bde, ceri,
Alex Lyashkov <umka at sevcity dot net>,
Skip Ford <skip dot ford at verizon dot net>,
Antoine Brodin <antoine dot brodin at laposte dot net>


# 162997 04-Oct-2006 mbr

Back out part of rev. 1.149. While adding a workaround in ptcopen() to
avoid leaked ptys works fine, this opens a possible security hole.

Submitted by: bde
MFC after: 3 days


# 162905 30-Sep-2006 mbr

Readd rev. 1.145 because of vfs bugs and races near revoke(). Until they
are fixed we can't free any slaves. Add a workaround to not to leak ptys
by number.


# 162777 29-Sep-2006 mbr

Free tty struct after last close. This should fix the pty-leak by numbers.
Remove workarounds for tty_refcount beeing 0, this will be fixed differently
later.

Back out rev 1.145 since we initialize the tty struct from scratch and bad
things can't happen anymore.


# 162711 27-Sep-2006 ru

Fix our ioctl(2) implementation when the argument is "int". New
ioctls passing integer arguments should use the _IOWINT() macro.
This fixes a lot of ioctl's not working on sparc64, most notable
being keyboard/syscons ioctls.

Full ABI compatibility is provided, with the bonus of fixing the
handling of old ioctls on sparc64.

Reviewed by: bde (with contributions)
Tested by: emax, marius
MFC after: 1 week


# 162575 23-Sep-2006 mbr

Check for tp->t_refcnt == 0 before doing anything in tty_open().

PR: 103520
MFC after: 1 week


# 155227 02-Feb-2006 cognet

Don't destroy the slave /dev entry until someone figures out why devfs seems
to behave badly when we do so.


# 155117 31-Jan-2006 csjp

Allow root in the host environment to open ptys within jailed environments.
This logic change was introduced in revision 1.74:

Correct an oversight in jail() that allowed processes in jail to access
ptys in ways that might be unethical, especially towards processes not in
jail, or in other jails.

It should be fine to allow root in the host environment to do this. This
allows for more effective monitoring of prisons from the host environment.

Discussed with: rwatson
MFC after: 1 week


# 154868 26-Jan-2006 cognet

Don't attempt to re-create the /dev entry for the slave part if it already
exist when opening the master. This can happen if one open the master, then
open the slave, then close and re-open the master.

Reported by: Peter Holm


# 154833 25-Jan-2006 cognet

Bring in a sysv-style pts implementation, as found in the rwatson_pts perforce branch. It works the same as its SysV/linux counterpart : You obtain a fd to the master pseudo terminal by opening /dev/ptmx, which craetes a node for the master as /dev/pty[num] and a node for the slave as /dev/pts/[num].
It should play nicely with the existing BSD ptys.
By default, the system will use the BSD ptys, one can set the sysctl
kern.pts.enable to 1 to make it use the new pts system.
The max number of pty that can be allocated on a system can be changed with the
sysctl kern.pts.max. It defaults to 1000, and can be increased, but it is not
recommanded, as any pty with a number > 999 won't be handled by whatever uses
utmp(5).


# 154170 10-Jan-2006 phk

Move the old BSD4.3 tty compatibility from (!BURN_BRIDGES && COMPAT_43)
to COMPAT_43TTY.

Add COMPAT_43TTY to NOTES and */conf/GENERIC

Compile tty_compat.c only under the new option.

Spit out
#warning "Old BSD tty API used, please upgrade."
if ioctl_compat.h gets #included from userland.


# 154015 04-Jan-2006 phk

Use ttyalloc() instead of ttymalloc()


# 148868 08-Aug-2005 rwatson

Merge the dev_clone and dev_clone_cred event handlers into a single
event handler, dev_clone, which accepts a credential argument.
Implementors of the event can ignore it if they're not interested,
and most do. This avoids having multiple event handler types and
fall-back/precedence logic in devfs.

This changes the kernel API for /dev cloning, and may affect third
party packages containg cloning kernel modules.

Requested by: phk
MFC after: 3 days


# 147982 14-Jul-2005 rwatson

When devfs cloning takes place, provide access to the credential of the
process that caused the clone event to take place for the device driver
creating the device. This allows cloned device drivers to adapt the
device node based on security aspects of the process, such as the uid,
gid, and MAC label.

- Add a cred reference to struct cdev, so that when a device node is
instantiated as a vnode, the cloning credential can be exposed to
MAC.

- Add make_dev_cred(), a version of make_dev() that additionally
accepts the credential to stick in the struct cdev. Implement it and
make_dev() in terms of a back-end make_dev_credv().

- Add a new event handler, dev_clone_cred, which can be registered to
receive the credential instead of dev_clone, if desired.

- Modify the MAC entry point mac_create_devfs_device() to accept an
optional credential pointer (may be NULL), so that MAC policies can
inspect and act on the label or other elements of the credential
when initializing the skeleton device protections.

- Modify tty_pty.c to register clone_dev_cred and invoke make_dev_cred(),
so that the pty clone credential is exposed to the MAC Framework.

While currently primarily focussed on MAC policies, this change is also
a prerequisite for changes to allow ptys to be instantiated with the UID
of the process looking up the pty. This requires further changes to the
pty driver -- in particular, to immediately recycle pty nodes on last
close so that the credential-related state can be recreated on next
lookup.

Submitted by: Andrew Reisse <andrew.reisse@sparta.com>
Obtained from: TrustedBSD Project
Sponsored by: SPAWAR, SPARTA
MFC after: 1 week
MFC note: Merge to 6.x, but not 5.x for ABI reasons


# 144389 31-Mar-2005 phk

Explicitly hold a reference to the cdev we have just cloned. This
closes the race where the cdev was reclaimed before it ever made it
back to devfs lookup.


# 142709 27-Feb-2005 phk

Use dynamic major number allocation.


# 139804 06-Jan-2005 imp

/* -> /*- for copyright notices, minor format tweaks as necessary


# 139205 22-Dec-2004 phk

Include uio.h
Check O_NONBLOCK instead if IO_NDELAY
Don't include vnode.h


# 136680 18-Oct-2004 phk

Add new function ttyinitmode() which sets our systemwide default
modes on a tty structure.

Both the ".init" and the current settings are initialized allowing
the function to be used both at attach and open time.

The function takes an argument to decide if echoing should be enabled.
Echoing should not be enabled for regular physical serial ports
unless they are consoles, in which case they should be configured
by ttyconsolemode() instead.

Use the new function throughout.


# 136553 15-Oct-2004 phk

Make pty's always come up in echo mode.


# 135622 23-Sep-2004 phk

Split the ioctl function in control and slave side, this eliminated
a troublesome devsw() call.


# 135298 16-Sep-2004 phk

Use the tty->t_sc field to find our softc.


# 132226 15-Jul-2004 phk

Preparation commit for the tty cleanups that will follow in the near
future:

rename ttyopen() -> tty_open() and ttyclose() -> tty_close().

We need the ttyopen() and ttyclose() for the new generic cdevsw
functions for tty devices in order to have consistent naming.


# 131115 25-Jun-2004 phk

Gah! commit from wrong tree.

Remove now unused variables from last commit.


# 131114 25-Jun-2004 phk

Retire the TIOC_REMOTE ioctl.

It was added 22 years ago for emacs to use, but emacs gave up on it
it 17 years ago.


# 130892 21-Jun-2004 phk

Put the pre FreeBSD-2.x tty compat code under BURN_BRIDGES.


# 130640 17-Jun-2004 phk

Second half of the dev_t cleanup.

The big lines are:
NODEV -> NULL
NOUDEV -> NODEV
udev_t -> dev_t
udev2dev() -> findcdev()

Various minor adjustments including handling of userland access to kernel
space struct cdev etc.


# 130585 16-Jun-2004 phk

Do the dreaded s/dev_t/struct cdev */
Bump __FreeBSD_version accordingly.


# 130344 11-Jun-2004 phk

Deorbit COMPAT_SUNOS.

We inherited this from the sparc32 port of BSD4.4-Lite1. We have neither
a sparc32 port nor a SunOS4.x compatibility desire these days.


# 130263 09-Jun-2004 phk

Rename struct pt_ioctl to "ptsc" and pointers to it from "pti" to "pt"


# 130262 09-Jun-2004 phk

Ditch K&R function style


# 130259 09-Jun-2004 phk

Move PTY private defines into PTY private files.


# 130077 04-Jun-2004 phk

Machine generated patch which changes linedisc calls from accessing
linesw[] directly to using the ttyld...() functions

The ttyld...() functions ar inline so there is no performance hit.


# 130054 04-Jun-2004 phk

Use ttymalloc() instead of ttyregister(). Use ttyioctl() instead of
direct calls to the linedisc.


# 129939 01-Jun-2004 phk

There is no need to explicitly call the stop function. In all likelyhood
->l_close() did it and ttyclose certainly will.


# 127911 05-Apr-2004 imp

Remove advertising clause from University of California Regent's license,
per letter dated July 22, 1999.

Approved by: core


# 126080 21-Feb-2004 phk

Device megapatch 4/6:

Introduce d_version field in struct cdevsw, this must always be
initialized to D_VERSION.

Flip sense of D_NOGIANT flag to D_NEEDGIANT, this involves removing
four D_NOGIANT flags and adding 145 D_NEEDGIANT flags.


# 126078 21-Feb-2004 phk

Device megapatch 3/6:

Add missing D_TTY flags to various drivers.

Complete asserts that dev_t's passed to ttyread(), ttywrite(),
ttypoll() and ttykqwrite() have (d_flags & D_TTY) and a struct tty
pointer.

Make ttyread(), ttywrite(), ttypoll() and ttykqwrite() the default
cdevsw methods for D_TTY drivers and remove the explicit initializations
in various drivers cdevsw structures.


# 125839 14-Feb-2004 rwatson

Remove excess brackets.


# 122352 09-Nov-2003 tanimura

- Implement selwakeuppri() which allows raising the priority of a
thread being waken up. The thread waken up can run at a priority as
high as after tsleep().

- Replace selwakeup()s with selwakeuppri()s and pass appropriate
priorities.

- Add cv_broadcastpri() which raises the priority of the broadcast
threads. Used by selwakeuppri() if collision occurs.

Not objected in: -arch, -current


# 120513 27-Sep-2003 phk

Don't use seltrue when that is not really what we mean.


# 116182 10-Jun-2003 obrien

Use __FBSDID().


# 115463 31-May-2003 phk

"break" rather than fall through to a break in the default clause.

Found by: FlexeLint


# 114983 13-May-2003 jhb

- Merge struct procsig with struct sigacts.
- Move struct sigacts out of the u-area and malloc() it using the
M_SUBPROC malloc bucket.
- Add a small sigacts_*() API for managing sigacts structures: sigacts_alloc(),
sigacts_free(), sigacts_copy(), sigacts_share(), and sigacts_shared().
- Remove the p_sigignore, p_sigacts, and p_sigcatch macros.
- Add a mutex to struct sigacts that protects all the members of the struct.
- Add sigacts locking.
- Remove Giant from nosys(), kill(), killpg(), and kern_sigaction() now
that sigacts is locked.
- Several in-kernel functions such as psignal(), tdsignal(), trapsignal(),
and thread_stopped() are now MP safe.

Reviewed by: arch@
Approved by: re (rwatson)


# 112888 31-Mar-2003 jeff

- Move p->p_sigmask to td->td_sigmask. Signal masks will be per thread with
a follow on commit to kern_sig.c
- signotify() now operates on a thread since unmasked pending signals are
stored in the thread.
- PS_NEEDSIGCHK moves to TDF_NEEDSIGCHK.


# 111899 05-Mar-2003 das

Make TTYHOG tunable.

Reviewed by: mike (mentor)


# 111821 03-Mar-2003 phk

Make nokqfilter() return the correct return value.

Ditch the D_KQFILTER flag which was used to prevent calling NULL pointers.


# 111815 03-Mar-2003 phk

Gigacommit to improve device-driver source compatibility between
branches:

Initialize struct cdevsw using C99 sparse initializtion and remove
all initializations to default values.

This patch is automatically generated and has been tested by compiling
LINT with all the fields in struct cdevsw in reverse order on alpha,
sparc64 and i386.

Approved by: re(scottl)


# 111742 02-Mar-2003 des

Clean up whitespace, s/register //, refrain from strong urge to ANSIfy.


# 111741 02-Mar-2003 des

uiomove-related caddr_t -> void * (just the low-hanging fruit)


# 111119 19-Feb-2003 imp

Back out M_* changes, per decision of the TRB.

Approved by: trb


# 109623 21-Jan-2003 alfred

Remove M_TRYWAIT/M_WAITOK/M_WAIT. Callers should use 0.
Merge M_NOWAIT/M_DONTWAIT into a single flag M_NOWAIT.


# 108363 28-Dec-2002 phk

Remove cdevsw_add calls, they are deprecated.


# 94860 16-Apr-2002 jhb

- Lock proctree_lock instead of pgrpsess_lock.
- Use temporary variables to hold a pointer to a pgrp while we dink with it
while not holding either the associated proc lock or proctree_lock. It
is in theory possible that p->p_pgrp could change out from under us.


# 93593 01-Apr-2002 jhb

Change the suser() API to take advantage of td_ucred as well as do a
general cleanup of the API. The entire API now consists of two functions
similar to the pre-KSE API. The suser() function takes a thread pointer
as its only argument. The td_ucred member of this thread must be valid
so the only valid thread pointers are curthread and a few kernel threads
such as thread0. The suser_cred() function takes a pointer to a struct
ucred as its first argument and an integer flag as its second argument.
The flag is currently only used for the PRISON_ROOT flag.

Discussed on: smp@


# 92723 19-Mar-2002 alfred

Remove __P.


# 91565 02-Mar-2002 tanimura

Fix lock leakage and late unlock.

Submitted by: bde


# 91406 27-Feb-2002 jhb

Simple p_ucred -> td_ucred changes to start using the per-thread ucred
reference.


# 91140 23-Feb-2002 tanimura

Lock struct pgrp, session and sigio.

New locks are:

- pgrpsess_lock which locks the whole pgrps and sessions,
- pg_mtx which protects the pgrp members, and
- s_mtx which protects the session members.

Please refer to sys/proc.h for the coverage of these locks.

Changes on the pgrp/session interface:

- pgfind() needs the pgrpsess_lock held.

- The caller of enterpgrp() is responsible to allocate a new pgrp and
session.

- Call enterthispgrp() in order to enter an existing pgrp.

- pgsignal() requires a pgrp lock held.

Reviewed by: jhb, alfred
Tested on: cvsup.jp.FreeBSD.org
(which is a quad-CPU machine running -current)


# 90831 18-Feb-2002 dillon

The ICANON flag is an lflag, not an iflag.

Submitted by: Neelkanth Natu <neelnatu@yahoo.com>
MFC after: 3 days


# 85844 01-Nov-2001 rwatson

o Move suser() calls in kern/ to using suser_xxx() with an explicit
credential selection, rather than reference via a thread or process
pointer. This is part of a gradual migration to suser() accepting
a struct ucred instead of a struct proc, simplifying the reference
and locking semantics of suser().

Obtained from: TrustedBSD Project


# 83803 21-Sep-2001 jhb

Use the passed in thread pointer instead of curthread in calls to
selrecord() in ptcpoll(). The pre-KSE code used the passed in proc pointer
rather than curproc, and an earlier seltrue() call uses the passed in
thread and not curthread.


# 83366 12-Sep-2001 julian

KSE Milestone 2
Note ALL MODULES MUST BE RECOMPILED
make the kernel aware that there are smaller units of scheduling than the
process. (but only allow one thread per process at this time).
This is functionally equivalent to teh previousl -current except
that there is a thread associated with each process.

Sorry john! (your next MFC will be a doosie!)

Reviewed by: peter@freebsd.org, dillon@freebsd.org

X-MFC after: ha ha ha ha


# 78405 18-Jun-2001 brian

Don't remove the SI_CHEAPCLONE for unsupported minors


# 77360 28-May-2001 phk

With the new kernel dev_t conversions done at release 4.X,
it becomes possible to trap in ptsstop() in kern/tty_pty.c
if the slave side has never been opened during the life of a kernel.

What happens is that calls to ttyflush() done from ptyioctl() for the
controlling side end up calling ptsstop() [via (*tp->t_stop)(tp, <X>)]
which evaluates the following:

struct pt_ioctl *pti = tp->t_dev->si_drv1;

In order for tp->t_dev to be set, the slave device must first be
opened in ttyopen() [kern/tty.c].

It appears that the only problem is calls to (*tp->t_stop)(tp, <n>),
so this could also happen with other ioctls initiated by the
controlling side before the slave has been opened.

PR: 27698
Submitted by: David Bein bein@netapp.com
MFC after: 6 days


# 77176 25-May-2001 phk

Make the PTY drivers cloning algorithm create "CHEAPCLONE" dev_t,
so that some twit cannot allocate all 256 PTY's with "ls -l".


# 74810 26-Mar-2001 phk

Send the remains (such as I have located) of "block major numbers" to
the bit-bucket.


# 72786 21-Feb-2001 rwatson

o Move per-process jail pointer (p->pr_prison) to inside of the subject
credential structure, ucred (cr->cr_prison).
o Allow jail inheritence to be a function of credential inheritence.
o Abstract prison structure reference counting behind pr_hold() and
pr_free(), invoked by the similarly named credential reference
management functions, removing this code from per-ABI fork/exit code.
o Modify various jail() functions to use struct ucred arguments instead
of struct proc arguments.
o Introduce jailed() function to determine if a credential is jailed,
rather than directly checking pointers all over the place.
o Convert PRISON_CHECK() macro to prison_check() function.
o Move jail() function prototypes to jail.h.
o Emulate the P_JAILED flag in fill_kinfo_proc() and no longer set the
flag in the process flags field itself.
o Eliminate that "const" qualifier from suser/p_can/etc to reflect
mutex use.

Notes:

o Some further cleanup of the linux/jail code is still required.
o It's now possible to consider resolving some of the process vs
credential based permission checking confusion in the socket code.
o Mutex protection of struct prison is still not present, and is
required to protect the reference count plus some fields in the
structure.

Reviewed by: freebsd-arch
Obtained from: TrustedBSD Project


# 72521 15-Feb-2001 jlemon

Extend kqueue down to the device layer.

Backwards compatible approach suggested by: peter


# 69781 08-Dec-2000 dwmalone

Convert more malloc+bzero to malloc+M_ZERO.

Submitted by: josh@zipperup.org
Submitted by: Robert Drehmel <robd@gmx.net>


# 69774 08-Dec-2000 phk

Staticize some malloc M_ instances.


# 66067 19-Sep-2000 phk

Rename lminor() to dev2unit(). This function gives a linear unit number
which hides the 'hole' in the minor bits.

Introduce unit2minor() to do the reverse operation.

Fix some some make_dev() calls which didn't use UID_* or GID_* macros.

Kill the v_hashchain alias macro, it hides the real relationship.

Introduce experimental SI_CHEAPCLONE flag set it on cloned bpfs.


# 65374 02-Sep-2000 phk

Avoid the modules madness I inadvertently introduced by making the
cloning infrastructure standard in kern_conf. Modules are now
the same with or without devfs support.

If you need to detect if devfs is present, in modules or elsewhere,
check the integer variable "devfs_present".

This happily removes an ugly hack from kern/vfs_conf.c.

This forces a rename of the eventhandler and the standard clone
helper function.

Include <sys/eventhandler.h> in <sys/conf.h>: it's a helper #include
like <sys/queue.h>

Remove all #includes of opt_devfs.h they no longer matter.


# 64880 20-Aug-2000 phk

Remove all traces of Julians DEVFS (incl from kern/subr_diskslice.c)

Remove old DEVFS support fields from dev_t.

Make uid, gid & mode members of dev_t and set them in make_dev().

Use correct uid, gid & mode in make_dev in disk minilayer.

Add support for registering alias names for a dev_t using the
new function make_dev_alias(). These will show up as symlinks
in DEVFS.

Use makedev() rather than make_dev() for MFSs magic devices to prevent
DEVFS from noticing this abuse.

Add a field for DEVFS inode number in dev_t.

Add new DEVFS in fs/devfs.

Add devfs cloning to:
disk minilayer (ie: ad(4), sd(4), cd(4) etc etc)
md(4), tun(4), bpf(4), fd(4)

If DEVFS add -d flag to /sbin/inits args to make it mount devfs.

Add commented out DEVFS to GENERIC


# 61473 10-Jun-2000 peter

Unused include: #include "pty.h"


# 59818 01-May-2000 ache

Since ptys are allocated dynamically, there is no needs to keep their
t_timeout across close, so move t_timeout initializing to ptcopen


# 59815 01-May-2000 ache

Set t_timeout to its default sysctl value only once in ttyopen
Initialize t_timeout to -1 for this reason

Pointed-by: bde


# 57070 09-Feb-2000 rwatson

Correct an oversight in jail() that allowed processes in jail to access
ptys in ways that might be unethical, especially towards processes not in
jail, or in other jails.

Submitted by: phk
Reviewed by: rwatson
Approved by: jkh


# 53483 21-Nov-1999 jkh

Revert peter's commit to remove cdevsw_add() - it was a bit premature
since things fail to function properly without it (pty allocation becomes
somewhat haphazard).


# 53336 18-Nov-1999 peter

Remove cdevsw_add() as the make_dev()'s are done in a clone-like fashion.
(ie: the next device is created with make_dev as the first is opened
and so on)


# 51791 29-Sep-1999 marcel

sigset_t change (part 2 of 5)
-----------------------------

The core of the signalling code has been rewritten to operate
on the new sigset_t. No methodological changes have been made.
Most references to a sigset_t object are through macros (see
signalvar.h) to create a level of abstraction and to provide
a basis for further improvements.

The NSIG constant has not been changed to reflect the maximum
number of signals possible. The reason is that it breaks
programs (especially shells) which assume that all signals
have a non-null name in sys_signame. See src/bin/sh/trap.c
for an example. Instead _SIG_MAXSIG has been introduced to
hold the maximum signal possible with the new sigset_t.

struct sigprop has been moved from signalvar.h to kern_sig.c
because a) it is only used there, and b) access must be done
though function sigprop(). The latter because the table doesn't
holds properties for all signals, but only for the first NSIG
signals.

signal.h has been reorganized to make reading easier and to
add the new and/or modified structures. The "old" structures
are moved to signalvar.h to prevent namespace polution.

Especially the coda filesystem suffers from the change, because
it contained lines like (p->p_sigmask == SIGIO), which is easy
to do for integral types, but not for compound types.

NOTE: kdump (and port linux_kdump) must be recompiled.

Thanks to Garrett Wollman and Daniel Eischen for pressing the
importance of changing sigreturn as well.


# 51658 25-Sep-1999 phk

Remove five now unused fields from struct cdevsw. They should never
have been there in the first place. A GENERIC kernel shrinks almost 1k.

Add a slightly different safetybelt under nostop for tty drivers.

Add some missing FreeBSD tags


# 51654 25-Sep-1999 phk

This patch clears the way for removing a number of tty related
fields in struct cdevsw:

d_stop moved to struct tty.
d_reset already unused.
d_devtotty linkage now provided by dev_t->si_tty.

These fields will be removed from struct cdevsw together with
d_params and d_maxio Real Soon Now.

The changes in this patch consist of:

initialize dev->si_tty in *_open()
initialize tty->t_stop
remove devtotty functions
rename ttpoll to ttypoll
a few adjustments to these changes in the generic code
a bump of __FreeBSD_version
add a couple of FreeBSD tags


# 50652 30-Aug-1999 phk

s/si_tty_tty/si_tty/g


# 50477 27-Aug-1999 peter

$Id$ -> $FreeBSD$


# 50254 23-Aug-1999 phk

Convert DEVFS hooks in (most) drivers to make_dev().

Diskslice/label code not yet handled.

Vinum, i4b, alpha, pc98 not dealt with (left to respective Maintainers)

Add the correct hook for devfs to kern_conf.c

The net result of this excercise is that a lot less files depends on DEVFS,
and devtoname() gets more sensible output in many cases.

A few drivers had minor additional cleanups performed relating to cdevsw
registration.

A few drivers don't register a cdevsw{} anymore, but only use make_dev().


# 50092 20-Aug-1999 julian

First small steps at merging DEVFS and PHK's Dev_t stuff.


# 49992 17-Aug-1999 julian

Devfs isn't quite dead yet... Add back devfs support to ptys..
When you use pty(N) it creates pty(N+1) ready for your use in the DEVFS,
so DEVFS is not cluttered up with hundreds of ptys you are never going to
use.


# 49540 08-Aug-1999 phk

Add new sysctl "kern.ttys" which return all the struct tty's which have
been registered with ttyregister().

register ptys with ttyregister().


# 49536 08-Aug-1999 phk

Make the pty driver as close to a cloning device as we can get for now,
we create the pty on the fly when it is first opened.

If you run out of ptys now, just MAKEDEV some more.

This also demonstrate the use of dev_t->si_tty_tty and dev_t->si_drv1
in a device driver.


# 47640 31-May-1999 phk

Simplify cdevsw registration.

The cdevsw_add() function now finds the major number(s) in the
struct cdevsw passed to it. cdevsw_add_generic() is no longer
needed, cdevsw_add() does the same thing.

cdevsw_add() will print an message if the d_maj field looks bogus.

Remove nblkdev and nchrdev variables. Most places they were used
bogusly. Instead check a dev_t for validity by seeing if devsw()
or bdevsw() returns NULL.

Move bdevsw() and devsw() functions to kern/kern_conf.c

Bump __FreeBSD_version to 400006

This commit removes:
72 bogus makedev() calls
26 bogus SYSINIT functions

if_xe.c bogusly accessed cdevsw[], author/maintainer please fix.

I4b and vinum not changed. Patches emailed to authors. LINT
probably broken until they catch up.


# 47625 30-May-1999 phk

This commit should be a extensive NO-OP:

Reformat and initialize correctly all "struct cdevsw".

Initialize the d_maj and d_bmaj fields.

The d_reset field was not removed, although it is never used.

I used a program to do most of this, so all the files now use the
same consistent format. Please keep it that way.

Vinum and i4b not modified, patches emailed to respective authors.


# 47301 18-May-1999 luoqi

TIOCEXT is also inapproriate before the slave is open, return EAGAIN when
these ioctls are attempted. Move a misplaced comment.

Pointed out by: Bruce


# 47203 14-May-1999 luoqi

Ignore some ioctls on the master until the slave is open.


# 46676 08-May-1999 phk

I got tired of seeing all the cdevsw[major(foo)] all over the place.

Made a new (inline) function devsw(dev_t dev) and substituted it.

Changed to the BDEV variant to this format as well: bdevsw(dev_t dev)

DEVFS will eventually benefit from this change too.


# 46112 27-Apr-1999 phk

Suser() simplification:

1:
s/suser/suser_xxx/

2:
Add new function: suser(struct proc *), prototyped in <sys/proc.h>.

3:
s/suser_xxx(\([a-zA-Z0-9_]*\)->p_ucred, \&\1->p_acflag)/suser(\1)/

The remaining suser_xxx() calls will be scrutinized and dealt with
later.

There may be some unneeded #include <sys/cred.h>, but they are left
as an exercise for Bruce.

More changes to the suser() API will come along with the "jail" code.


# 43425 30-Jan-1999 phk

Use suser() to check for super user rather than examining cr_uid directly.
Use TTYDEF_SPEED rather than 9600 a couple of places.

Reviewed by: bde, with a few grumbles.


# 38485 23-Aug-1998 bde

Added D_TTY to the cdevswitch flags for all tty drivers. This is required
for the Lite2 fix for always returning EIO in dead_read().

Cleaned up the cdevswitch initializers for all tty drivers.

Removed explicit calls to ttsetwater() from all (tty) drivers. ttsetwater()
is now called centrally for opens, not just for parameter changes.


# 37683 15-Jul-1998 bde

Changed %n to %r in devfs name format strings. %n has almost gone away.


# 36735 07-Jun-1998 dfr

This commit fixes various 64bit portability problems required for
FreeBSD/alpha. The most significant item is to change the command
argument to ioctl functions from int to u_long. This change brings us
inline with various other BSD versions. Driver writers may like to
use (__FreeBSD_version == 300003) to detect this change.

The prototype FreeBSD/alpha machdep will follow in a couple of days
time.


# 33826 25-Feb-1998 bde

Don't depend on "implicit int" or bloat the data section in the
declaration of ptc_devsw_installed.

Fixed a spelling error.


# 32726 24-Jan-1998 eivind

Make all file-system (MFS, FFS, NFS, LFS, DEVFS) related option new-style.

This introduce an xxxFS_BOOT for each of the rootable filesystems.
(Presently not required, but encouraged to allow a smooth move of option *FS
to opt_dontuse.h later.)

LFS is temporarily disabled, and will be re-enabled tomorrow.


# 31778 16-Dec-1997 eivind

Make COMPAT_43 and COMPAT_SUNOS new-style options.


# 31577 06-Dec-1997 bde

Use ENOIOCTL instead of -1 (= ERESTART) for tty ioctls that are
not handled at a particular level. This fixes mainly restarting
of interrupted TIOCDRAINs and TIOCSETA{W,F}s.


# 29506 16-Sep-1997 bde

Fixed gratuitous ANSIisms.


# 29354 14-Sep-1997 peter

Extend to use poll backend. If memory serves correctly, most of this was
adapted from NetBSD.. However, there are some differences in the tty
system that are big enough to cause their code to not fit comfortably.

Obtained from: NetBSD (I think)


# 29041 02-Sep-1997 bde

Removed unused #includes.


# 27770 30-Jul-1997 jmg

fix a few problems with pty. warn about how if you only have 1 pty
defined, your really getting 32. Also warn about how you can't have
more than 256 pty's when your using DEVFS (non DEVFS can use more, just
the makedev script doesn't know how to make >256). it also doesn't
allocate more memory than needed in this case.

Make sure that the signal passed in TIOCSIG isn't 0 as it might cause
a panic. I personally haven't seen this happen, but after a similar
bug in syscons crashed my machine, I'm acutely aware of this one. :)


# 24207 24-Mar-1997 bde

Don't include <sys/ioctl.h> in the kernel. Stage 5: include
<sys/ioctl_compat.h> and sometimes <sys/filio.h> instead of
<sys/ioctl.h> in tty-related files. <sys/ttycom.h> is still
usually imported bogusly via <sys/termios.h>.


# 24131 23-Mar-1997 bde

Don't #include <sys/fcntl.h> in <sys/file.h> if KERNEL is defined.
Fixed everything that depended on getting fcntl.h stuff from the wrong
place. Most things don't depend on file.h stuff at all.


# 22975 22-Feb-1997 peter

Back out part 1 of the MCFH that changed $Id$ to $FreeBSD$. We are not
ready for it yet.


# 21673 14-Jan-1997 jkh

Make the long-awaited change from $Id$ to $FreeBSD$

This will make a number of things easier in the future, as well as (finally!)
avoiding the Id-smashing problem which has plagued developers for so long.

Boy, I'm glad we're not using sup anymore. This update would have been
insane otherwise.


# 16322 12-Jun-1996 gpalmer

Clean up -Wunused warnings.

Reviewed by: bde


# 15199 11-Apr-1996 bde

Fixed the PF_REMOTE case of ptcwrite(). I broke it in rev.1.22. Output
was duplicated until the canq filled up, and write() normally returned 0.
This case is apparently rare. It was reported for Jove's shell buffer in
PR 1130.


# 14511 11-Mar-1996 hsu

Merge in Lite2: buf fix with comparison of wrong field against EXTPROC.
Did not accept change of second argument to ioctl from int to u_long.
Reviewed by: davidg & bde


# 13639 26-Jan-1996 phk

Fix a bug I made in the devfs.


# 13630 25-Jan-1996 phk

Avoid local sprintfs and other printf'isms.


# 12967 22-Dec-1995 bde

Fixed pty names. The control and slave names were back to front.

Fixed pty permissions.


# 12819 14-Dec-1995 phk

A Major staticize sweep. Generates a couple of warnings that I'll deal
with later.
A number of unused vars removed.
A number of unused procs removed or #ifdefed.


# 12813 13-Dec-1995 julian

devsw tables are now arrays of POINTERS to struct [cb]devsw
seems to work hre just fine though I can't check every file
that changed due to limmited h/w, however I've checked enught to be petty
happy withe hte code..

WARNING... struct lkm[mumble] has changed
so it might be an idea to recompile any lkm related programs


# 12731 10-Dec-1995 bde

Removed new alias d_size_t for d_psize_t.

Removed old aliases d_rdwr_t and d_ttycv_t for d_read_t/d_write_t and
d_devtotty_t.

Sorted declarations of switch functions into switch order.

Removed duplicated comments and declarations of nonexistent switch
functions.


# 12678 08-Dec-1995 phk

Julian forgot to make the *devsw structures static.


# 12675 08-Dec-1995 julian

Pass 3 of the great devsw changes
most devsw referenced functions are now static, as they are
in the same file as their devsw structure. I've also added DEVFS
support for nearly every device in the system, however
many of the devices have 'incorrect' names under DEVFS
because I couldn't quickly work out the correct naming conventions.
(but devfs won't be coming on line for a month or so anyhow so that doesn't
matter)

If you "OWN" a device which would normally have an entry in /dev
then search for the devfs_add_devsw() entries and munge to make them right..
check out similar devices to see what I might have done in them in you
can't see what's going on..
for a laugh compare conf.c conf.h defore and after... :)
I have not doen DEVFS entries for any DISKSLICE devices yet as that will be
a much more complicated job.. (pass 5 :)

pass 4 will be to make the devsw tables of type (cdevsw * )
rather than (cdevsw)
seems to work here..
complaints to the usual places.. :)


# 12567 02-Dec-1995 julian

I fixed this before than committed it on my machine and not on freefall.
(window confusion)


# 12564 02-Dec-1995 julian

Submitted by: Heikki Suonsivu

Made the pty devices creates in devfs match the present MAKEDEV naming


# 12521 29-Nov-1995 julian

If you're going to mechanically replicate something in 50 files
it's best to not have a (compiles cleanly) typo in it! (sigh)


# 12517 29-Nov-1995 julian

OK, that's it..
That's EVERY SINGLE driver that has an entry in conf.c..
my next trick will be to define cdevsw[] and bdevsw[]
as empty arrays and remove all those DAMNED defines as well..

Each of these drivers has a SYSINIT linker set entry
that comes in very early.. and asks teh driver to add it's own
entry to the two devsw[] tables.

some slight reworking of the commits from yesterday (added the SYSINIT
stuff and some usually wrong but token DEVFS entries to all these
devices.

BTW does anyone know where the 'ata' entries in conf.c actually reside?
seems we don't actually have a 'ataopen() etc...

If you want to add a new device in conf.c
please make sure I know
so I can keep it up to date too..

as before, this is all dependent on #if defined(JREMOD)
(and #ifdef DEVFS in parts)


# 12071 04-Nov-1995 bde

Moved prototypes for devswitch functions from conf.c and driver sources
to <machine/conf.h>. conf.h was mechanically generated by
`grep ^d_ conf.c >conf.h'. This accounts for part of its ugliness. The
prototypes should be moved back to the driver sources when the functions
are staticalized.


# 11941 30-Oct-1995 bde

Removed an annoying redundant declaration that I added in the previous
revision.


# 11789 25-Oct-1995 bde

Fixed data loss in writes to pty masters. Data was almost always lost
at the end of each write for writes of more than 1K.

Fixed handling of residual count for early returns in writes to pty masters.
It was only adjusted in 2 out of 6 cases.

Added prototypes.


# 10902 19-Sep-1995 bde

Don't clear the session pointer in ptcclose(). It must be left alone
until the session leader exits so that a SIGHUP gets sent to the process
group and the pty slave gets revoked.


# 10624 08-Sep-1995 bde

Fix benign type mismatches in devsw functions. 82 out of 299 devsw
functions were wrong.


# 9858 02-Aug-1995 ache

Back out predefined termios speeds check, it can cause troubles
with interaction pty <-> serial driver with non-standard speed.
So, nothing protect us from garbadge in speed field, expect
checking for < 0 left in tty.c :-(


# 9851 02-Aug-1995 ache

Check for valid speed values in pty drive
Check for negative speed values in tty drive
Back out valid speed values checking from tty drive
Suggested by: bde


# 9850 02-Aug-1995 bde

Don't set TS_ZOMBIE flag for non-open ptys. ptcclose() has always done
too much for non-open ptys, but there is normally no problem because the
l_modem(, 0) is a no-op for closed ptys provided the line discipline is
standard and MDMBUF isn't set.


# 9824 31-Jul-1995 bde

Obtained from: partly from ancient patches of mine via 1.1.5

Introduce TS_CONNECTED and TS_ZOMBIE states. TS_CONNECTED is set
while a connection is established. It is set while (TS_CARR_ON or
CLOCAL is set) and TS_ZOMBIE is clear. TS_ZOMBIE is set for on to
off transitions of TS_CARR_ON that occur when CLOCAL is clear and
is cleared for off to on transitions of CLOCAL. I/o can only occur
while TS_CONNECTED is set. TS_ZOMBIE prevents further i/o.

Split the input-event sleep address TSA_CARR_ON(tp) into TSA_CARR_ON(tp)
and TSA_HUP_OR_INPUT(tp). The former address is now used only for
off to on carrier transitions and equivalent CLOCAL transitions.
The latter is used for all input events, all carrier transitions
and certain CLOCAL transitions. There are some harmless extra
wakeups for rare connection- related events. Previously there were
too many extra wakeups for non-rare input events.

Drivers now call l_modem() instead of setting TS_CARR_ON directly
to handle even the initial off to on transition of carrier. They
should always have done this. l_modem() now handles TS_CONNECTED
and TS_ZOMBIE as well as TS_CARR_ON.

gnu/isdn/iitty.c:
Set TS_CONNECTED for first open ourself to go with bogusly setting
CLOCAL.

i386/isa/syscons.c, i386/isa/pcvt/pcvt_drv.c:
We fake carrier, so don't also fake CLOCAL.

kern/tty.c:
Testing TS_CONNECTED instead of TS_CARR_ON fixes TIOCCONS forgetting to
test CLOCAL. TS_ISOPEN was tested instead, but that broke when we disabled
the clearing of TS_ISOPEN for certain transitions of CLOCAL.

Testing TS_CONNECTED fixes ttyselect() returning false success for output
to devices in state !TS_CARR_ON && !CLOCAL.

Optimize the other selwakeup() call (this is not related to the other
changes).

kern/tty_pty.c:
ptcopen() can be declared in traditional C now that dev_t isn't short.


# 9639 22-Jul-1995 bde

Obtained from: partly from ancient patches of mine via 1.1.5

Give names to the magic tty i/o sleep addresses and use them. This makes
it easier to remember what the addresses are for and to keep them unique.


# 9626 21-Jul-1995 bde

Move the inline code for waking up writers to a new function
ttwwakeup(). The conditions for doing the wakeup will soon become
more complicated and I don't want them duplicated in all drivers.

It's probably not worth making ttwwakeup() a macro or an inline
function. The cost of the function call is relatively small when
there is a process to wake up. There is usually a process to wake
up for large writes and the system call overhead dwarfs the function
call overhead for small writes.


# 9624 21-Jul-1995 bde

Obtained from: partly from ancient patches by ache and me via 1.1.5

Nuke `symbolic sleep message strings'. Use unique literal messages so that
`ps l' shows unambiguously where processes are sleeping.


# 9619 21-Jul-1995 bde

Obtained from: partly from an ancient patch of mine via 1.1.5

Temporarily nuke TS_WOPEN. It was only used for the obscure MDMBUF
flow control option in the kernel and for informational purposes
in `pstat -t'. The latter worked properly only for ptys. In
general there may be multiple processes sleeping in open() and
multiple processes that successfully opened the tty by opening it
in O_NONBLOCK mode or during a window when CLOCAL was set. tty.c
doesn't have enough information to maintain the flag but always
cleared it in ttyopen().

TS_WOPEN should be restored someday just so that `pstat -t' can
display it (MDMBUF is already fixed). Fixing it requires counting
of processes sleeping in open() in too many serial drivers.


# 8876 30-May-1995 rgrimes

Remove trailing whitespace.


# 7730 09-Apr-1995 ache

Call ptsstop in ptsclose instead of ptcwakeup


# 7724 09-Apr-1995 ache

ptcwakeup() was called from wrong places


# 6782 27-Feb-1995 pst

Incorporate bde's code-review comments.

(a) bring back ttselect, now that we have xxxdevtotty() it isn't dangerous.
(b) remove all of the wrappers that have been replaced by ttselect
(c) fix formatting in syscons.c and definition in syscons.h
(d) add cxdevtotty

NOT DONE:
(e) make pcvt work... it was already broken...when someone fixes pcvt to
link properly, just rename get_pccons to xxxdevtotty and we're done


# 6712 25-Feb-1995 pst

(a) remove the pointer to each driver's tty structure array from cdevsw
(b) add a function callback vector to tty drivers that will return a pointer
to a valid tty structure based upon a dev_t
(c) make syscons structures the same size whether or not APM is enabled so
utilities don't crash if NAPM changes (and make the damn kernel compile!)
(d) rewrite /dev/snp ioctl interface so that it is device driver and i386
independant


# 3998 29-Oct-1994 ache

write ptys use _the_same_ tsleep/wakeup address as read ptys due to
mistype, fixed.


# 3308 02-Oct-1994 phk

All of this is cosmetic. prototypes, #includes, printfs and so on. Makes
GCC a lot more silent.


# 2807 15-Sep-1994 bde

Supply prototypes for some functions that were implicitly declared and
fix the resulting warnings.


# 1817 02-Aug-1994 dg

Added $Id$


# 1549 25-May-1994 rgrimes

The big 4.4BSD Lite to FreeBSD 2.0.0 (Development) patch.

Reviewed by: Rodney W. Grimes
Submitted by: John Dyson and David Greenman


# 1542 24-May-1994 rgrimes

This commit was generated by cvs2svn to compensate for changes in r1541,
which included commits to RCS files with non-trunk default branches.


# 1541 24-May-1994 rgrimes

BSD 4.4 Lite Kernel Sources