📄 ckutio.c
字号:
#elsestatic jmp_buf sjbuf;#endif /* CK_POSIX_SIG */#ifdef V7static jmp_buf jjbuf;#endif /* V7 *//* static */ /* (Not static any more) */int ttyfd = -1; /* TTY file descriptor */#ifdef Plan9int ttyctlfd = -1; /* TTY control channel - What? UNIX doesn't have one? */int consctlfd = -1; /* Console control channel */int noisefd = -1; /* tone channel */static int ttylastspeed = -1; /* So we can lie about the speed */#endif /* Plan9 */int telnetfd = 0; /* File descriptor is for telnet */int x25fd = 0; /* File descriptor is for X.25 */static int lkf = 0, /* Line lock flag */ cgmf = 0, /* Flag that console modes saved */ xlocal = 0, /* Flag for tty local or remote */ curcarr = 0; /* Carrier mode: require/ignore. */static int netconn = 0; /* 1 if network connection active */static char escchr; /* Escape or attn character */#ifdef COHERENT#ifdef SELECT static struct timeval tv; /* Needed for -DSELECT in makefile */#endif /* SELECT */#endif /* COHERENT */#ifdef QNX static struct timeval tv; /* For getting time, from sys/time.h */ static struct timezone tz;#else#ifdef SOLARIS static struct timeval tv; /* For getting time, from sys/time.h */ static struct timezone tz;#else#ifdef HPUX static struct timeval tv; /* For getting time, from sys/time.h */ static struct timezone tz;#else#ifdef __linux__ static struct timeval tv; /* For getting time, from sys/time.h */ static struct timezone tz;#else#ifdef PS2AIX10 static struct timeval tv; /* For getting time, from sys/time.h */ static struct timezone tz;#else#ifdef AIXRS static struct timeval tv; /* For getting time, from sys/time.h */ static struct timezone tz;#else#ifdef BSD44 static struct timeval tv; /* For getting time, from sys/time.h */ static struct timezone tz;#else#ifdef BSD42 static struct timeval tv; /* For getting time, from sys/time.h */ static struct timezone tz;#ifdef OSF static struct timeb ftp; /* And from sys/timeb.h */#endif /* OSF */#else#ifdef OXOS static struct timeval tv; /* For getting time, from sys/time.h */ static struct timezone tz;#else#ifdef SELECT#ifndef BELLV10 static struct timeval tv; static struct timezone tz;#endif /* BELLV10 */#endif /* SELECT */#endif /* OXOS */#endif /* BSD42 */#endif /* BSD44 */#endif /* AIXRS */#endif /* PS2AIX10 */#endif /* __linux__ */#endif /* HPUX */#endif /* SOLARIS */#endif /* QNX */#ifdef BSD29 static long xclock; /* For getting time from sys/time.h */ static struct timeb ftp; /* And from sys/timeb.h */#endif /* BSD29 */#ifdef BSD41 static long xclock; /* For getting time from sys/time.h */ static struct timeb ftp; /* And from sys/timeb.h */#endif /* BSD41 */#ifdef BELLV10 static long xclock; /* For getting time from sys/time.h */ static struct timeb ftp; /* And from sys/timeb.h */#endif /* BELLV10 */#ifdef FT21 static long xclock; /* For getting time from sys/time.h */ static struct timeb ftp; /* And from sys/timeb.h */#endif /* FT21 */#ifdef TOWER1 static long xclock; /* For getting time from sys/time.h */ static struct timeb ftp; /* And from sys/timeb.h */#endif /* TOWER1 */#ifdef COHERENT static long xclock; /* For getting time from sys/time.h */ static struct timeb ftp; /* And from sys/timeb.h */#endif /* COHERENT */#ifdef V7 static long xclock;#endif /* V7 *//* sgtty/termio information... */#ifdef BSD44ORPOSIX /* POSIX or BSD44 */ static struct termios ttold, ttraw, tttvt, ttcur, ccold, ccraw, cccbrk;#else /* BSD, V7, etc */#ifdef COHERENT /* Hack alert... */#define ATTSV#endif /* COHERENT */#ifdef ATTSV static struct termio ttold = {0}; /* Init'd for word alignment, */ static struct termio ttraw = {0}; /* which is important for some */ static struct termio tttvt = {0}; /* systems, like Zilog... */ static struct termio ttcur = {0}; static struct termio ccold = {0}; static struct termio ccraw = {0}; static struct termio cccbrk = {0};#else static struct sgttyb /* sgtty info... */ ttold, ttraw, tttvt, ttcur, /* for communication line */ ccold, ccraw, cccbrk; /* and for console */#ifdef BELLV10 static struct ttydevb /* Device info... */ tdold, tdcur; /* for communication device */#endif /* BELLV10 */#ifdef TIOCGETC static struct tchars tchold, tchnoi; static int tcharf;#endif /* TIOCGETC */#ifdef TIOCGLTC static struct ltchars ltchold, ltchnoi; static int ltcharf;#endif /* TIOCGLTC */ int lmodef = 0; /* Local modes */ int lmode = 0;#endif /* ATTSV */#endif /* BSD44ORPOSIX */#ifdef PROVX1 static struct sgttyb ttbuf;#endif /* PROVX1 */#ifdef ultrix/* do we really need this? */ static struct sgttyb vanilla;#endif /* ultrix */#ifdef ATT7300static int attmodem = 0; /* ATT7300 internal-modem status */struct updata dialer = {0}; /* Condition dialer for data call */#endif /* ATT7300 */#ifndef NOUUCPchar flfnam[80]; /* UUCP lock file path name */#ifdef HPUX10char lock2[80]; /* Name of second lockfile */#endif /* HPUX10 */#elsechar flfnam[8];#endif /* NOUUCP */#ifdef RTAIXchar lkflfn[80]; /* and possible link to it */#endif /* RTAIX */int haslock = 0; /* =1 if this kermit locked uucp */#ifndef OXOS#ifdef SVORPOSIXstatic int conesc = 0; /* set to 1 if esc char (^\) typed */#else#ifdef V7static int conesc = 0;#else#ifdef C70static int conesc = 0;#endif /* C70 */#endif /* V7 */#endif /* SVORPOSIX */#endif /* OXOS */static char ttnmsv[DEVNAMLEN]; /* Copy of open path for tthang */#ifdef aegisstatic status_$t st; /* error status return value */static short concrp = 0; /* true if console is CRP pad */#define CONBUFSIZ 10static char conbuf[CONBUFSIZ]; /* console readahead buffer */static int conbufn = 0; /* # chars in readahead buffer */static char *conbufp; /* next char in readahead buffer */static uid_$t ttyuid; /* tty type uid */static uid_$t conuid; /* stdout type uid *//* APOLLO Aegis main() * establish acl usage and cleanup handling * this makes sure that CRP pads * get restored to a usable mode */main(argc,argv) int argc; char **argv; { status_$t status; pfm_$cleanup_rec dirty; PID_T pid = getpid(); /* acl usage according to invoking environment */ default_acl(USE_DEFENV); /* establish a cleanup continuation */ status = pfm_$cleanup(dirty); if (status.all != pfm_$cleanup_set) { /* only handle faults for the original process */ if (pid == getpid() && status.all > pgm_$max_severity) { /* blew up in main process */ status_$t quo; pfm_$cleanup_rec clean; /* restore the console in any case */ conres(); /* attempt a clean exit */ debug(F101, "cleanup fault status", "", status.all); /* doexit(), then send status to continuation */ quo = pfm_$cleanup(clean); if (quo.all == pfm_$cleanup_set) doexit(pgm_$program_faulted,-1); else if (quo.all > pgm_$max_severity) pfm_$signal(quo); /* blew up in doexit() */ } /* send to the original continuation */ pfm_$signal(status); /*NOTREACHED*/ } return(ckcmai(argc, argv));}#endif /* aegis *//* ANSI-style prototypes for internal functions. *//* Functions used outside this module are prototyped in ckcker.h. */#ifdef apollo_PROTOTYP( SIGTYP timerh, () );_PROTOTYP( SIGTYP cctrap, () );_PROTOTYP( SIGTYP esctrp, () );_PROTOTYP( SIGTYP sig_ign, () );#else_PROTOTYP( SIGTYP timerh, (int) );_PROTOTYP( SIGTYP cctrap, (int) );_PROTOTYP( SIGTYP esctrp, (int) );#endif /* apollo */_PROTOTYP( int do_open, (char *) );_PROTOTYP( static int in_chk, (int) );_PROTOTYP( static int ttrpid, (char *) );_PROTOTYP( static int ttlock, (char *) );_PROTOTYP( static int ttunlck, (void) );_PROTOTYP( int mygetbuf, (void) );_PROTOTYP( int myfillbuf, (void) );_PROTOTYP( VOID conbgt, (int) );#ifdef ACUCNTRL_PROTOTYP( VOID acucntrl, (char *, char *) );#endif /* ACUCNTRL */#ifdef BSD44ORPOSIX_PROTOTYP( int carrctl, (struct termios *, int) );#else#ifdef ATTSV_PROTOTYP( int carrctl, (struct termio *, int) );#else_PROTOTYP( int carrctl, (struct sgttyb *, int) );#endif /* ATTSV */#endif /* BSD44ORPOSIX */#ifdef ATT7300_PROTOTYP( int attdial, (char *, long, char *) );_PROTOTYP( int offgetty, (char *) );_PROTOTYP( int ongetty, (char *) );#endif /* ATT7300 */#ifdef BEBOX#ifdef BE_DR_7static double time_started = 0.0;#include <kernel/OS.h>struct ALARM_STRUCT { thread_id thread; int time;};static thread_id alarm_thread = -1;static struct ALARM_STRUCT alarm_struct;_PROTOTYP( long do_alarm, (void *) );_PROTOTYP( unsigned int alarm, (unsigned int) );_PROTOTYP( void alarm_expired, (void) );#endif /* BE_DR_7 */#endif /* BEBOX */#ifdef CK_ANSICstatic char *xxlast(char *s, char c)#elsestatic char *xxlast(s,c) char *s; char c;#endif /* CK_ANSIC *//* xxlast */ { /* Last occurrence of character c in string s. */ int i; for (i = (int)strlen(s); i > 0; i--) if ( s[i-1] == c ) return( s + (i - 1) ); return(NULL);}/* Timeout handler for communication line input functions */SIGTYPtimerh(foo) int foo; { ttimoff();#ifdef BEBOX alarm_expired();#endif /* BEBOX */#ifdef CK_POSIX_SIG siglongjmp(sjbuf,1);#else longjmp(sjbuf,1);#endif /* CK_POSIX_SIG */}/* Control-C trap for communication line input functions */int cc_int; /* Flag */SIGTYP (* occt)(); /* For saving old SIGINT handler */SIGTYPcctrap(foo) int foo; { /* Needs arg for ANSI C */ cc_int = 1; /* signal() prototype. */ return;}/* S Y S I N I T -- System-dependent program initialization. *//* * ttgwsiz() returns: * 1 tt_rows and tt_cols are known, both altered, both > 0 * 0 tt_rows and/or tt_cols are known, both altered, one or both <= 0 * -1 tt_rows and tt_cols are unknown and unaltered */intttgwsiz() {#ifndef NONAWS extern int tt_rows, tt_cols;#ifdef QNX/* NOTE: TIOCGWSIZ works here too, but only in the 32-bit version. This code works for both the 16- and 32-bit versions.*/ extern int dev_size(int, int, int, int *, int *); int r, c; if (dev_size(0, -1, -1, &r, &c) == 0) { debug(F101,"ttgwsiz QNX r","",r); debug(F101,"ttgwsiz QNX c","",c); tt_rows = r; tt_cols = c; return ((r > 0 && c > 0) ? 1 : 0); } else return(-1);#else /* QNX */#ifdef TIOCGWINSZ/* Note, this was M_UNIX, changed to XENIX to allow cross compilation... */#ifdef XENIX /* SCO UNIX 3.2v4.0 */#include <sys/stream.h> /* typedef mblk_t needed by ptem.h */#include <sys/ptem.h> /* for ttgwsiz() */#endif /* XENIX */#ifdef I386IX /* Ditto for Interactive */#include <sys/stream.h>#include <sys/ptem.h>#endif /* I386IX *//* Note, the above might be needed for some other older SVR3 Intel makes... */ struct winsize w; if (ioctl(0, (int)TIOCGWINSZ, (char *)&w) < 0) return(-1); else if (w.ws_row > 0 && w.ws_col > 0) { tt_rows = w.ws_row; tt_cols = w.ws_col; debug(F101,"ttgwsiz tt_rows","",tt_rows); debug(F101,"ttgwsiz tt_cols","",tt_cols); return(1); } else return(0);#endif /* TIOCGWINSZ */#endif /* QNX */#endif /* NONAWS */}intsysinit() { int x;/* BEFORE ANYTHING ELSE: Initialize the setuid package. Change to the user's real user and group ID. If this can't be done, don't run at all.*/ debug(F100,"sysinit calling priv_ini","",0); if (x = priv_ini()) { if (x & 1) fprintf(stderr,"Fatal: setuid failure.\n"); if (x & 2) fprintf(stderr,"Fatal: setgid failure.\n"); if (x & 4) fprintf(stderr,"Fatal: C-Kermit setuid to root!\n"); exit(1); }#ifndef NOJC/* Get the initial job control state. If it is SIG_IGN, that means the shell does not support job control, and so we'd better not suspend ourselves.*/#ifdef SIGTSTP jchdlr = signal(SIGTSTP,SIG_IGN); if (jchdlr == SIG_IGN) { jcshell = 0; debug(F100,"sysinit jchdlr: SIG_IGN","",0); } else if (jchdlr == SIG_DFL) { debug(F100,"sysinit jchdlr: SIG_DFL","",0); jcshell = 1; } else { debug(F100,"sysinit jchdlr: other","",0); jcshell = 3; } (VOID) signal(SIGTSTP,jchdlr); /* Put it back... */#endif /* SIGTSTP */#endif /* NOJC */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -