diff options
author | Marcus Brinkmann <marcus@gnu.org> | 2002-02-10 17:21:02 +0000 |
---|---|---|
committer | Marcus Brinkmann <marcus@gnu.org> | 2002-02-10 17:21:02 +0000 |
commit | e88c882ecc9557ea14734a418252c2c8a5d8caf9 (patch) | |
tree | efcd54ffc50bff4a6649b65bded400937532997f /term/users.c | |
parent | 00269c069be2a461363f905f19a02bb013e7debf (diff) | |
download | hurd-e88c882ecc9557ea14734a418252c2c8a5d8caf9.tar.gz hurd-e88c882ecc9557ea14734a418252c2c8a5d8caf9.tar.bz2 hurd-e88c882ecc9557ea14734a418252c2c8a5d8caf9.zip |
2002-02-10 Marcus Brinkmann <marcus@gnu.org>
* term.h: Include `hurd/hurd_types.h'.
(struct bottomhalf): Change the return types of the following
members from void to error_t: abandon_physical_output,
suspend_physical_output, notice_input_flushed, desert_dtr,
set_break, clear_break, start_output, set_bits (which now takes an
struct termios * as argument), mdmctl and mdmstate (which now
takes an int * as argument). Add new members init and type.
(bottom): Define as const.
(devio_bottom, ptyio_bottom): Declare as const.
(drop_output): Change return type from void to error_t.
(ptyio_init): Remove prototype.
* devio.c (devio_abandon_physical_output): Change return value to
error_t, and return 0.
(devio_suspend_physical_output): Likewise.
(devio_notice_input_flushed): Likewise.
(devio_desert_dtr): Likewise.
(devio_set_break): Likewise.
(devio_clear_break): Likewise.
(devio_start_output): Likewise.
(devio_set_bits): Likewise.
(devio_mdmctl): Likewise.
(devio_mdmstate): Likewise.
(init_devio): Rename to ...
(devio_init): ... this. Do not give constructor attribute.
Change return type to error_t, and return an error value, rather
than bailing out. Declare as static.
(devio_bottom): Add type TERM_ON_MACHDEV and init function
devio_init.
(devio_set_bits): Accept new argument STATE and use that to work
out the terminal state, rather than changing the global termstate.
(devio_mdmstate): Accept new argument STATE and use that to return
the bits.
* ptyio.c: Do not include `hurd/hurd_types.h'.
(ptyio_suspend_physical_output): Change return value to error_t,
and return 0. Likewise.
(ptyio_notice_input_flushed): Likewise.
(ptyio_desert_dtr): Likewise.
(ptyio_set_bits): Likewise.
(ptyio_set_break): Likewise.
(ptyio_clear_break): Likewise.
(ptyio_mdmctl): Likewise.
(ptyio_start_output): Likewise.
(ptyio_abandon_physical_output): Likewise.
(ptyio_mdmstate): Likewise, and accept new argument STATE.
(ptyio_init): Declare as static and change return type to error_t.
(ptyio_bottom): Add type TERM_ON_MASTERPTY and init function
ptyio_init.
(ptyio_set_bits): Accept new argument STATE and use that to work
out the terminal state, rather than changing the global termstate.
(ptyio_mdmstate): Accept new argument STATE and use that to return
the bits.
* munge.c (drop_output): Change return value to error_t. Only
clear queue if there was no error.
* users.c (S_term_get_bottom_type): Just return bottom->type.
(set_state): Rework logic to take possible errors into account,
and to delay changing the termstate until we know that we won't
fail.
(S_tioctl_tiocflush): Return errors properly, and clear queue only
if notice_input_flushed succeeded.
(open_hook): Save error value of set_bits. Save old termflags and
restore them if if set_bits failed. Call set_bits with correct
arguments.
(S_tioctl_tiocmods): Set err to result of mdmctl.
(S_tioctl_tiocmset): Likewise.
(S_tioctl_tiocmbic): Likewise.
(S_tioctl_tiocmbis): Likewise.
(S_tioctl_tioccdtr): Likewise.
(S_tioctl_tiocsdtr): Likewise.
(S_tioctl_tioccbrk): Likewise for clear_break.
(S_tioctl_tiocsbrk): Likewise for set_break.
(S_tioctl_tiocstart): Likewise for start_output. Save old
termflags and restore them if if start_output failed.
(S_tioctl_tiocstop): Likewise for stop_output.
(S_trivfs_io_write): Abort the operation if start_output fails.
Do not call start_output if it just failed, or if there was no
data to be written.
* main.c (main): Initialize bottom handler (rather than special
casing this for ptyio).
* users.c (open_hook): Use memcpy instead bcopy and memset instead
bzero.
(S_tioctl_tiocgeta): Likewise.
(set_state): Likewise.
(open_hook): Likewise.
* munge.c (rescan_inputq): Likewise.
Diffstat (limited to 'term/users.c')
-rw-r--r-- | term/users.c | 164 |
1 files changed, 80 insertions, 84 deletions
diff --git a/term/users.c b/term/users.c index 77af90d6..0d3297b2 100644 --- a/term/users.c +++ b/term/users.c @@ -1,5 +1,5 @@ /* - Copyright (C) 1995,96,97,98,99,2000,01 Free Software Foundation, Inc. + Copyright (C) 1995,96,97,98,99,2000,01,02 Free Software Foundation, Inc. Written by Michael I. Bushnell, p/BSG. This file is part of the GNU Hurd. @@ -152,7 +152,7 @@ open_hook (struct trivfs_control *cntl, if (!(termflags & TTY_OPEN)) { - bzero (&termstate, sizeof termstate); + memset (&termstate, 0, sizeof termstate); /* This is different from BSD: we don't turn on ISTRIP, and we use CS8 rather than CS7|PARENB. */ @@ -162,9 +162,9 @@ open_hook (struct trivfs_control *cntl, | ECHOE|ECHOKE|ECHOCTL); termstate.c_cflag |= CREAD | CS8 | HUPCL; - bcopy (ttydefchars, termstate.c_cc, NCCS); + memcpy (termstate.c_cc, ttydefchars, NCCS); - bzero (&window_size, sizeof window_size); + memset (&window_size, 0, sizeof window_size); termflags |= NO_OWNER; } @@ -212,8 +212,13 @@ open_hook (struct trivfs_control *cntl, if (!err) { - termflags |= TTY_OPEN; - (*bottom->set_bits) (); + struct termios state = termstate; + err = (*bottom->set_bits) (&state); + if (!err) + { + termstate = state; + termflags |= TTY_OPEN; + } } mutex_unlock (&global_lock); @@ -560,6 +565,7 @@ trivfs_S_io_write (struct trivfs_protid *cred, { int i; int cancel; + error_t err = 0; if (!cred) return EOPNOTSUPP; @@ -595,9 +601,14 @@ trivfs_S_io_write (struct trivfs_protid *cred, { while (!qavail (outputq) && !cancel) { - (*bottom->start_output) (); - if (!qavail (outputq)) - cancel = hurd_condition_wait (outputq->wait, &global_lock); + err = (*bottom->start_output) (); + if (err) + cancel = 1; + else + { + if (!qavail (outputq)) + cancel = hurd_condition_wait (outputq->wait, &global_lock); + } } if (cancel) break; @@ -607,7 +618,8 @@ trivfs_S_io_write (struct trivfs_protid *cred, *amt = i; - (*bottom->start_output) (); + if (!err && datalen) + (*bottom->start_output) (); trivfs_set_mtime (termctl); @@ -615,7 +627,7 @@ trivfs_S_io_write (struct trivfs_protid *cred, mutex_unlock (&global_lock); - return ((cancel && datalen && !*amt) ? EINTR : 0); + return ((cancel && datalen && !*amt) ? (err ?: EINTR) : 0); } /* Called for user reads from the terminal. */ @@ -882,6 +894,8 @@ S_tioctl_tiocmodg (io_t port, int *state) { struct trivfs_protid *cred = ports_lookup_port (term_bucket, port, 0); + error_t err = 0; + if (!cred) return EOPNOTSUPP; @@ -893,11 +907,11 @@ S_tioctl_tiocmodg (io_t port, } mutex_lock (&global_lock); - *state = (*bottom->mdmstate) (); + err = (*bottom->mdmstate) (state); mutex_unlock (&global_lock); ports_port_deref (cred); - return 0; + return err; } /* TIOCMODS ioctl -- Set modem state */ @@ -922,10 +936,7 @@ S_tioctl_tiocmods (io_t port, if (!(cred->po->openmodes & (O_READ|O_WRITE))) err = EBADF; else - { - (*bottom->mdmctl) (MDMCTL_SET, state); - err = 0; - } + err = (*bottom->mdmctl) (MDMCTL_SET, state); mutex_unlock (&global_lock); @@ -1001,8 +1012,8 @@ S_tioctl_tiocflush (io_t port, int flags) { struct trivfs_protid *cred = ports_lookup_port (term_bucket, port, 0); + error_t err = 0; - error_t err; if (!cred) return EOPNOTSUPP; @@ -1024,14 +1035,13 @@ S_tioctl_tiocflush (io_t port, if (flags & O_READ) { - clear_queue (inputq); - (*bottom->notice_input_flushed) (); + err = (*bottom->notice_input_flushed) (); + if (!err) + clear_queue (inputq); } - if (flags & O_WRITE) - drop_output (); - - err = 0; + if (!err && (flags & O_WRITE)) + err = drop_output (); } mutex_unlock (&global_lock); @@ -1063,7 +1073,7 @@ S_tioctl_tiocgeta (io_t port, modes[1] = termstate.c_oflag; modes[2] = termstate.c_cflag; modes[3] = termstate.c_lflag; - bcopy (termstate.c_cc, ccs, NCCS); + memcpy (ccs, termstate.c_cc, NCCS); speeds[0] = termstate.__ispeed; speeds[1] = termstate.__ospeed; mutex_unlock (&global_lock); @@ -1084,6 +1094,7 @@ set_state (io_t port, struct trivfs_protid *cred = ports_lookup_port (term_bucket, port, 0); error_t err; int oldlflag; + struct termios state; if (!cred) return EOPNOTSUPP; @@ -1105,42 +1116,47 @@ set_state (io_t port, { if (cred->pi.class == pty_class) { + err = (*bottom->abandon_physical_output) (); + if (err) + goto leave; clear_queue (outputq); - (*bottom->abandon_physical_output) (); } if (draino) { err = drain_output (); if (err) - { - mutex_unlock (&global_lock); - ports_port_deref (cred); - return err; - } + goto leave; } if (flushi) { + err = (*bottom->notice_input_flushed) (); + if (err) + goto leave; clear_queue (inputq); - (*bottom->notice_input_flushed) (); } - oldlflag = termstate.c_lflag; - termstate.c_iflag = modes[0]; - termstate.c_oflag = modes[1]; - termstate.c_cflag = modes[2]; - termstate.c_lflag = modes[3]; - bcopy (ccs, termstate.c_cc, NCCS); - termstate.__ispeed = speeds[0]; - termstate.__ospeed = speeds[1]; + state = termstate; + state.c_iflag = modes[0]; + state.c_oflag = modes[1]; + state.c_cflag = modes[2]; + state.c_lflag = modes[3]; + memcpy (state.c_cc, ccs, NCCS); + state.__ispeed = speeds[0]; + state.__ospeed = speeds[1]; if (external_processing) - termstate.c_lflag |= EXTPROC; + state.c_lflag |= EXTPROC; else - termstate.c_lflag &= ~EXTPROC; + state.c_lflag &= ~EXTPROC; + + err = (*bottom->set_bits) (&state); + if (err) + goto leave; - (*bottom->set_bits) (); + oldlflag = termstate.c_lflag; + termstate = state; if (oldlflag & ICANON) { @@ -1152,17 +1168,15 @@ set_state (io_t port, if (termstate.c_lflag & ICANON) rescan_inputq (); } - err = 0; } + leave: mutex_unlock (&global_lock); - ports_port_deref (cred); return err; } - /* TIOCSETA -- Set termios state */ kern_return_t S_tioctl_tiocseta (io_t port, @@ -1354,6 +1368,7 @@ S_tioctl_tiocmget (io_t port, int *bits) { struct trivfs_protid *cred = ports_lookup_port (term_bucket, port, 0); + error_t err = 0; if (!cred) return EOPNOTSUPP; @@ -1366,11 +1381,11 @@ S_tioctl_tiocmget (io_t port, } mutex_lock (&global_lock); - *bits = (*bottom->mdmstate) (); + err = (*bottom->mdmstate) (bits); mutex_unlock (&global_lock); ports_port_deref (cred); - return 0; + return err; } /* TIOCMSET -- Set all modem bits */ @@ -1395,10 +1410,7 @@ S_tioctl_tiocmset (io_t port, if (!(cred->po->openmodes & (O_READ|O_WRITE))) err = EBADF; else - { - (*bottom->mdmctl) (MDMCTL_SET, bits); - err = 0; - } + err = (*bottom->mdmctl) (MDMCTL_SET, bits); mutex_unlock (&global_lock); ports_port_deref (cred); @@ -1427,10 +1439,7 @@ S_tioctl_tiocmbic (io_t port, if (!(cred->po->openmodes & (O_READ|O_WRITE))) err = EBADF; else - { - (*bottom->mdmctl) (MDMCTL_BIC, bits); - err = 0; - } + err = (*bottom->mdmctl) (MDMCTL_BIC, bits); mutex_unlock (&global_lock); ports_port_deref (cred); @@ -1460,10 +1469,7 @@ S_tioctl_tiocmbis (io_t port, if (!(cred->po->openmodes & (O_READ|O_WRITE))) err = EBADF; else - { - (*bottom->mdmctl) (MDMCTL_BIS, bits); - err = 0; - } + err = (*bottom->mdmctl) (MDMCTL_BIS, bits); mutex_unlock (&global_lock); ports_port_deref (cred); return err; @@ -1492,9 +1498,12 @@ S_tioctl_tiocstart (io_t port) err = EBADF; else { + int old_termflags = termflags; + termflags &= ~USER_OUTPUT_SUSP; - (*bottom->start_output) (); - err = 0; + err = (*bottom->start_output) (); + if (err) + termflags = old_termflags; } mutex_unlock (&global_lock); @@ -1524,9 +1533,11 @@ S_tioctl_tiocstop (io_t port) err = EBADF; else { + int old_termflags = termflags; termflags |= USER_OUTPUT_SUSP; - (*bottom->suspend_physical_output) (); - err = 0; + err = (*bottom->suspend_physical_output) (); + if (err) + termflags = old_termflags; } mutex_unlock (&global_lock); @@ -1690,10 +1701,7 @@ S_tioctl_tioccdtr (io_t port) if (!(cred->po->openmodes & (O_READ|O_WRITE))) err = EBADF; else - { - (*bottom->mdmctl) (MDMCTL_BIC, TIOCM_DTR); - err = 0; - } + err = (*bottom->mdmctl) (MDMCTL_BIC, TIOCM_DTR); mutex_unlock (&global_lock); ports_port_deref (cred); @@ -1721,10 +1729,7 @@ S_tioctl_tiocsdtr (io_t port) if (!(cred->po->openmodes & (O_READ|O_WRITE))) err = EBADF; else - { - (*bottom->mdmctl) (MDMCTL_BIS, TIOCM_DTR); - err = 0; - } + err = (*bottom->mdmctl) (MDMCTL_BIS, TIOCM_DTR); mutex_unlock (&global_lock); ports_port_deref (cred); @@ -1752,10 +1757,7 @@ S_tioctl_tioccbrk (io_t port) if (!(cred->po->openmodes & (O_READ|O_WRITE))) err = EBADF; else - { - (*bottom->clear_break) (); - err = 0; - } + err = (*bottom->clear_break) (); mutex_unlock (&global_lock); ports_port_deref (cred); @@ -1783,10 +1785,7 @@ S_tioctl_tiocsbrk (io_t port) if (!(cred->po->openmodes & (O_READ|O_WRITE))) err = EBADF; else - { - (*bottom->set_break) (); - err = 0; - } + err = (*bottom->set_break) (); mutex_unlock (&global_lock); ports_port_deref (cred); @@ -2237,10 +2236,7 @@ S_term_get_bottom_type (io_t arg, return EOPNOTSUPP; ports_port_deref (cred); - if (bottom == &devio_bottom) - *ttype = TERM_ON_MACHDEV; - else - *ttype = TERM_ON_MASTERPTY; + *ttype = bottom->type; return 0; } |