From e6ace01f128f260b2e76ac2775ce9bf7fc35ba60 Mon Sep 17 00:00:00 2001 From: tg Date: Fri, 4 May 2012 22:18:27 +0000 Subject: [PATCH] last parts of Coherent patchkit: O_ACCMODE and termio --- Build.sh | 5 +++-- edit.c | 12 ++++++------ funcs.c | 6 +++--- jobs.c | 18 +++++++++--------- main.c | 4 ++-- sh.h | 25 ++++++++++++++++++++++--- 6 files changed, 45 insertions(+), 25 deletions(-) diff --git a/Build.sh b/Build.sh index f82c820..ba6240f 100644 --- a/Build.sh +++ b/Build.sh @@ -1,5 +1,5 @@ #!/bin/sh -srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.561 2012/05/04 22:04:58 tg Exp $' +srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.562 2012/05/04 22:18:22 tg Exp $' #- # Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, # 2011, 2012 @@ -1307,6 +1307,7 @@ ac_header paths.h ac_header stdint.h stdarg.h # include strings.h only if compatible with string.h ac_header strings.h sys/types.h string.h +ac_header termios.h ac_header ulimit.h sys/types.h ac_header values.h @@ -1409,7 +1410,7 @@ else #define EXTERN #define MKSH_INCLUDES_ONLY #include "sh.h" - __RCSID("$MirOS: src/bin/mksh/Build.sh,v 1.561 2012/05/04 22:04:58 tg Exp $"); + __RCSID("$MirOS: src/bin/mksh/Build.sh,v 1.562 2012/05/04 22:18:22 tg Exp $"); int main(void) { printf("Hello, World!\n"); return (0); } EOF case $cm in diff --git a/edit.c b/edit.c index c660e2f..030a90f 100644 --- a/edit.c +++ b/edit.c @@ -28,7 +28,7 @@ #ifndef MKSH_NO_CMDLINE_EDITING -__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.235 2012/05/04 20:49:01 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.236 2012/05/04 22:18:23 tg Exp $"); /* * in later versions we might use libtermcap for this, but since external @@ -3274,7 +3274,7 @@ x_mode(bool onoff) if (edchars.quit >= 0) bind_if_not_bound(0, edchars.quit, XFUNC_noop); } else - tcsetattr(tty_fd, TCSADRAIN, &tty_state); + mksh_tcset(tty_fd, &tty_state); } #if !MKSH_S_NOVI @@ -5369,12 +5369,12 @@ vi_macro_reset(void) #endif /* !MKSH_NO_CMDLINE_EDITING */ void -x_mkraw(int fd, struct termios *ocb, bool forread) +x_mkraw(int fd, mksh_ttyst *ocb, bool forread) { - struct termios cb; + mksh_ttyst cb; if (ocb) - tcgetattr(fd, ocb); + mksh_tcget(fd, ocb); else ocb = &tty_state; @@ -5396,5 +5396,5 @@ x_mkraw(int fd, struct termios *ocb, bool forread) cb.c_cc[VTIME] = 0; cb.c_cc[VMIN] = 1; - tcsetattr(fd, TCSADRAIN, &cb); + mksh_tcset(fd, &cb); } diff --git a/funcs.c b/funcs.c index 2880527..b36f735 100644 --- a/funcs.c +++ b/funcs.c @@ -38,7 +38,7 @@ #endif #endif -__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.217 2012/05/04 22:05:00 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.218 2012/05/04 22:18:24 tg Exp $"); #if HAVE_KILLPG /* @@ -1783,7 +1783,7 @@ c_read(const char **wp) const char *ccp; XString xs; ptrdiff_t xsave = 0; - struct termios tios; + mksh_ttyst tios; bool restore_tios = false; #if HAVE_SELECT bool hastimeout = false; @@ -2160,7 +2160,7 @@ c_read(const char **wp) afree(allocd, ATEMP); Xfree(xs, xp); if (restore_tios) - tcsetattr(fd, TCSADRAIN, &tios); + mksh_tcset(fd, &tios); return (rv); #undef is_ifsws } diff --git a/jobs.c b/jobs.c index 5c7b1dd..9d29984 100644 --- a/jobs.c +++ b/jobs.c @@ -22,7 +22,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.86 2012/05/04 21:48:29 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.87 2012/05/04 22:18:25 tg Exp $"); #if HAVE_KILLPG #define mksh_killpg killpg @@ -89,7 +89,7 @@ struct job { int32_t age; /* number of jobs started */ Coproc_id coproc_id; /* 0 or id of coprocess output pipe */ #ifndef MKSH_UNEMPLOYED - struct termios ttystat; /* saved tty state for stopped jobs */ + mksh_ttyst ttystat; /* saved tty state for stopped jobs */ pid_t saved_ttypgrp; /* saved tty process group for stopped jobs */ #endif }; @@ -333,7 +333,7 @@ j_change(void) warningf(false, "%s: %s", "warning", "won't have full job control"); if (tty_fd >= 0) - tcgetattr(tty_fd, &tty_state); + mksh_tcget(tty_fd, &tty_state); } else { ttypgrp_ok = false; if (Flag(FTALKING)) @@ -803,14 +803,14 @@ j_resume(const char *cp, int bg) /* attach tty to job */ if (j->state == PRUNNING) { if (ttypgrp_ok && (j->flags & JF_SAVEDTTY)) - tcsetattr(tty_fd, TCSADRAIN, &j->ttystat); + mksh_tcset(tty_fd, &j->ttystat); /* See comment in j_waitj regarding saved_ttypgrp. */ if (ttypgrp_ok && tcsetpgrp(tty_fd, (j->flags & JF_SAVEDTTYPGRP) ? j->saved_ttypgrp : j->pgrp) < 0) { rv = errno; if (j->flags & JF_SAVEDTTY) - tcsetattr(tty_fd, TCSADRAIN, &tty_state); + mksh_tcset(tty_fd, &tty_state); sigprocmask(SIG_SETMASK, &omask, NULL); bi_errorf("%s %s(%d, %ld) %s: %s", "1st", "tcsetpgrp", tty_fd, @@ -832,7 +832,7 @@ j_resume(const char *cp, int bg) if (!bg) { j->flags &= ~JF_FG; if (ttypgrp_ok && (j->flags & JF_SAVEDTTY)) - tcsetattr(tty_fd, TCSADRAIN, &tty_state); + mksh_tcset(tty_fd, &tty_state); if (ttypgrp_ok && tcsetpgrp(tty_fd, kshpgrp) < 0) warningf(true, "%s %s(%d, %ld) %s: %s", "fg: 2nd", "tcsetpgrp", tty_fd, @@ -1130,7 +1130,7 @@ j_waitj(Job *j, (long)kshpgrp, "failed", strerror(errno)); if (j->state == PSTOPPED) { j->flags |= JF_SAVEDTTY; - tcgetattr(tty_fd, &j->ttystat); + mksh_tcget(tty_fd, &j->ttystat); } } #endif @@ -1146,9 +1146,9 @@ j_waitj(Job *j, */ if (j->state == PEXITED && j->status == 0 && (j->flags & JF_USETTYMODE)) { - tcgetattr(tty_fd, &tty_state); + mksh_tcget(tty_fd, &tty_state); } else { - tcsetattr(tty_fd, TCSADRAIN, &tty_state); + mksh_tcset(tty_fd, &tty_state); /*- * Don't use tty mode if job is stopped and * later restarted and exits. Consider diff --git a/main.c b/main.c index df16896..50ab100 100644 --- a/main.c +++ b/main.c @@ -34,7 +34,7 @@ #include #endif -__RCSID("$MirOS: src/bin/mksh/main.c,v 1.219 2012/05/04 21:47:02 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/main.c,v 1.220 2012/05/04 22:18:26 tg Exp $"); extern char **environ; @@ -1076,7 +1076,7 @@ tty_init(bool init_ttystate, bool need_tty) close(tty_fd); tty_fd = -1; } else if (init_ttystate) - tcgetattr(tty_fd, &tty_state); + mksh_tcget(tty_fd, &tty_state); if (do_close) close(tfd); } diff --git a/sh.h b/sh.h index 965bfb1..14dc27a 100644 --- a/sh.h +++ b/sh.h @@ -79,7 +79,12 @@ #if HAVE_STRINGS_H #include #endif +#if HAVE_TERMIOS_H #include +#else +/* shudder */ +#include +#endif #include #if HAVE_ULIMIT_H #include @@ -152,7 +157,7 @@ #endif #ifdef EXTERN -__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.556 2012/05/04 22:05:02 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.557 2012/05/04 22:18:27 tg Exp $"); #endif #define MKSH_VERSION "R40 2012/04/27" @@ -350,6 +355,10 @@ extern int __cdecl setegid(gid_t); #endif #if defined(__COHERENT__) +#ifndef O_ACCMODE +/* this need not work everywhere, take care */ +#define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR) +#endif #define mksh_TIME(tv) do { \ (tv).tv_usec = 0; \ (tv).tv_sec = time(NULL); \ @@ -366,6 +375,16 @@ extern int __cdecl setegid(gid_t); #define mksh_lstat lstat #endif +#if HAVE_TERMIOS_H +#define mksh_ttyst struct termios +#define mksh_tcget(fd,st) tcgetattr((fd), (st)) +#define mksh_tcset(fd,st) tcsetattr((fd), TCSADRAIN, (st)) +#else +#define mksh_ttyst struct termio +#define mksh_tcget(fd,st) ioctl((fd), TCGETA, (st)) +#define mksh_tcset(fd,st) ioctl((fd), TCSETAW, (st)) +#endif + /* remove redundancies */ #if defined(MirBSD) && (MirBSD >= 0x08A8) && !defined(MKSH_OPTSTATIC) @@ -1569,7 +1588,7 @@ int x_bind(const char *, const char *, bool); void x_init(void); int x_read(char *, size_t); #endif -void x_mkraw(int, struct termios *, bool); +void x_mkraw(int, mksh_ttyst *, bool); /* eval.c */ char *substitute(const char *, int); char **eval(const char **, int); @@ -1955,7 +1974,7 @@ int test_parse(Test_env *); EXTERN int tty_fd E_INIT(-1); /* dup'd tty file descriptor */ EXTERN bool tty_devtty; /* true if tty_fd is from /dev/tty */ -EXTERN struct termios tty_state; /* saved tty state */ +EXTERN mksh_ttyst tty_state; /* saved tty state */ extern void tty_init(bool, bool); extern void tty_close(void);