summaryrefslogtreecommitdiff
path: root/bin/ksh
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2004-12-18 22:12:24 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2004-12-18 22:12:24 +0000
commitdb410d16f492f3893149595dc39abcb580283f6e (patch)
tree6b329aeae935294126157c15d1d0ac45e925d09b /bin/ksh
parent8912b2a077b7b75bd51cc89010a16926b3dd4be0 (diff)
Use struct termios instead of TTY_state typedef
Use tc[gs]etattr() instead of [gs]et_tty() abstraction
Diffstat (limited to 'bin/ksh')
-rw-r--r--bin/ksh/edit.c9
-rw-r--r--bin/ksh/jobs.c30
-rw-r--r--bin/ksh/tty.c22
-rw-r--r--bin/ksh/tty.h12
4 files changed, 21 insertions, 52 deletions
diff --git a/bin/ksh/edit.c b/bin/ksh/edit.c
index 99f8afd290a..7c56c6297c2 100644
--- a/bin/ksh/edit.c
+++ b/bin/ksh/edit.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: edit.c,v 1.22 2004/12/18 22:11:43 millert Exp $ */
+/* $OpenBSD: edit.c,v 1.23 2004/12/18 22:12:23 millert Exp $ */
/*
* Command line editing - common code
@@ -170,7 +170,7 @@ x_mode(onoff)
x_cur_mode = onoff;
if (onoff) {
- TTY_state cb;
+ struct termios cb;
X_chars oldchars;
oldchars = edchars;
@@ -191,7 +191,7 @@ x_mode(onoff)
cb.c_cc[VTIME] = 0;
cb.c_cc[VMIN] = 1;
- set_tty(tty_fd, &cb, TF_WAIT);
+ tcsetattr(tty_fd, TCSADRAIN, &cb);
/* Convert unset values to internal `unset' value */
if (edchars.erase == _POSIX_VDISABLE)
@@ -212,8 +212,7 @@ x_mode(onoff)
#endif
}
} else {
- /* TF_WAIT doesn't seem to be necessary when leaving xmode */
- set_tty(tty_fd, &tty_state, TF_NONE);
+ tcsetattr(tty_fd, TCSADRAIN, &tty_state);
}
return prev;
diff --git a/bin/ksh/jobs.c b/bin/ksh/jobs.c
index ea64017be25..2a077a276b7 100644
--- a/bin/ksh/jobs.c
+++ b/bin/ksh/jobs.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: jobs.c,v 1.25 2004/12/18 22:11:43 millert Exp $ */
+/* $OpenBSD: jobs.c,v 1.26 2004/12/18 22:12:23 millert Exp $ */
/*
* Process and job control
@@ -77,7 +77,7 @@ struct job {
Proc *last_proc; /* last process in list */
Coproc_id coproc_id; /* 0 or id of coprocess output pipe */
#ifdef JOBS
- TTY_state ttystate; /* saved tty state for stopped jobs */
+ struct termios ttystate;/* saved tty state for stopped jobs */
pid_t saved_ttypgrp; /* saved tty process group for stopped jobs */
#endif /* JOBS */
};
@@ -247,7 +247,7 @@ j_change()
int i;
if (Flag(FMONITOR)) {
- /* Don't call get_tty() 'til we own the tty process group */
+ /* Don't call tcgetattr() 'til we own the tty process group */
tty_init(FALSE);
/* no controlling tty, no SIGT* */
@@ -300,7 +300,7 @@ j_change()
if (!ttypgrp_ok)
warningf(FALSE, "warning: won't have full job control");
if (tty_fd >= 0)
- get_tty(tty_fd, &tty_state);
+ tcgetattr(tty_fd, &tty_state);
} else {
ttypgrp_ok = 0;
if (Flag(FTALKING))
@@ -698,14 +698,12 @@ j_resume(cp, bg)
# ifdef JOBS
/* attach tty to job */
if (j->state == PRUNNING) {
- if (ttypgrp_ok && (j->flags & JF_SAVEDTTY)) {
- set_tty(tty_fd, &j->ttystate, TF_NONE);
- }
+ if (ttypgrp_ok && (j->flags & JF_SAVEDTTY))
+ tcsetattr(tty_fd, TCSADRAIN, &j->ttystate);
/* See comment in j_waitj regarding saved_ttypgrp. */
if (ttypgrp_ok && tcsetpgrp(tty_fd, (j->flags & JF_SAVEDTTYPGRP) ? j->saved_ttypgrp : j->pgrp) < 0) {
- if (j->flags & JF_SAVEDTTY) {
- set_tty(tty_fd, &tty_state, TF_NONE);
- }
+ if (j->flags & JF_SAVEDTTY)
+ tcsetattr(tty_fd, TCSADRAIN, &tty_state);
sigprocmask(SIG_SETMASK, &omask,
(sigset_t *) 0);
bi_errorf("1st tcsetpgrp(%d, %d) failed: %s",
@@ -726,9 +724,8 @@ j_resume(cp, bg)
if (!bg) {
j->flags &= ~JF_FG;
# ifdef JOBS
- if (ttypgrp_ok && (j->flags & JF_SAVEDTTY)) {
- set_tty(tty_fd, &tty_state, TF_NONE);
- }
+ if (ttypgrp_ok && (j->flags & JF_SAVEDTTY))
+ tcsetattr(tty_fd, TCSADRAIN, &tty_state);
if (ttypgrp_ok && tcsetpgrp(tty_fd, our_pgrp) < 0) {
warningf(TRUE,
"fg: 2nd tcsetpgrp(%d, %d) failed: %s",
@@ -1019,7 +1016,7 @@ j_waitj(j, flags, where)
}
if (j->state == PSTOPPED) {
j->flags |= JF_SAVEDTTY;
- get_tty(tty_fd, &j->ttystate);
+ tcgetattr(tty_fd, &j->ttystate);
}
}
#endif /* JOBS */
@@ -1035,10 +1032,9 @@ j_waitj(j, flags, where)
if (j->state == PEXITED && j->status == 0
&& (j->flags & JF_USETTYMODE))
{
- get_tty(tty_fd, &tty_state);
+ tcgetattr(tty_fd, &tty_state);
} else {
- set_tty(tty_fd, &tty_state,
- (j->state == PEXITED) ? 0 : TF_MIPSKLUDGE);
+ tcsetattr(tty_fd, TCSADRAIN, &tty_state);
/* Don't use tty mode if job is stopped and
* later restarted and exits. Consider
* the sequence:
diff --git a/bin/ksh/tty.c b/bin/ksh/tty.c
index 3808563dc26..c71f464da23 100644
--- a/bin/ksh/tty.c
+++ b/bin/ksh/tty.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tty.c,v 1.3 2004/12/18 20:55:52 millert Exp $ */
+/* $OpenBSD: tty.c,v 1.4 2004/12/18 22:12:23 millert Exp $ */
#include "sh.h"
#include <sys/stat.h>
@@ -6,24 +6,6 @@
#include "tty.h"
#undef EXTERN
-int
-get_tty(fd, ts)
- int fd;
- TTY_state *ts;
-{
- return tcgetattr(fd, ts);
-}
-
-int
-set_tty(fd, ts, flags)
- int fd;
- TTY_state *ts;
- int flags;
-{
- return tcsetattr(fd, TCSADRAIN, ts);
-}
-
-
/* Initialize tty_fd. Used for saving/reseting tty modes upon
* foreground job completion and for setting up tty process group.
*/
@@ -70,7 +52,7 @@ tty_init(init_ttystate)
close(tty_fd);
tty_fd = -1;
} else if (init_ttystate)
- get_tty(tty_fd, &tty_state);
+ tcgetattr(tty_fd, &tty_state);
if (do_close)
close(tfd);
}
diff --git a/bin/ksh/tty.h b/bin/ksh/tty.h
index f51ee9a6235..e7935cdaa3c 100644
--- a/bin/ksh/tty.h
+++ b/bin/ksh/tty.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tty.h,v 1.3 2004/12/18 20:55:52 millert Exp $ */
+/* $OpenBSD: tty.h,v 1.4 2004/12/18 22:12:23 millert Exp $ */
/*
tty.h -- centralized definitions for a variety of terminal interfaces
@@ -21,19 +21,11 @@
#endif
#include <termios.h>
-typedef struct termios TTY_state;
-
-/* Flags for set_tty() */
-#define TF_NONE 0x00
-#define TF_WAIT 0x01 /* drain output, even it requires sleep() */
-#define TF_MIPSKLUDGE 0x02 /* kludge to unwedge RISC/os 5.0 tty driver */
EXTERN int tty_fd I__(-1); /* dup'd tty file descriptor */
EXTERN int tty_devtty; /* true if tty_fd is from /dev/tty */
-EXTERN TTY_state tty_state; /* saved tty state */
+EXTERN struct termios tty_state; /* saved tty state */
-extern int get_tty(int fd, TTY_state *ts);
-extern int set_tty(int fd, TTY_state *ts, int flags);
extern void tty_init(int init_ttystate);
extern void tty_close(void);