⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ckutio.c

📁 操作系统源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
			/* doexit(), then send status to continuation */			quo = pfm_$cleanup(clean);			if (quo.all == pfm_$cleanup_set)				doexit(pgm_$program_faulted);			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 *//*  S Y S I N I T  --  System-dependent program initialization.  */sysinit() {/* for now, nothing... */    return(0);}/*  S Y S C L E A N U P  --  System-dependent program cleanup.  */syscleanup() {/* for now, nothing... */    return(0);}/*  T T O P E N  --  Open a tty for exclusive access.  *//*  Returns 0 on success, -1 on failure.  *//*  If called with lcl < 0, sets value of lcl as follows:  0: the terminal named by ttname is the job's controlling terminal.  1: the terminal named by ttname is not the job's controlling terminal.  But watch out: if a line is already open, or if requested line can't  be opened, then lcl remains (and is returned as) -1.*/ttopen(ttname,lcl,modem) char *ttname; int *lcl, modem; {#ifdef UXIII#ifndef CIE    char *ctermid();			/* Wish they all had this! */#endif /* not cie */#endif /* uxiii */#ifdef CIE				/* CIE Regulus doesn't... */#define ctermid(x) strcpy(x,"")#endif    char *x; #ifndef MINIX    extern char* ttyname();#endif    char cname[DEVNAMLEN+4];    if (ttyfd > -1) return(0);		/* If already open, ignore this call */    ttmdm = modem;			/* Make this available to other fns */    xlocal = *lcl;			/* Make this available to other fns */#ifdef NEWUUCP    acucntrl("disable",ttname);		/* Open getty on line (4.3BSD) */#endif /* newuucp */#ifdef UXIII    /* if modem connection, don't wait for carrier */    ttyfd = open(ttname,O_RDWR | (modem ? O_NDELAY : 0) );#else    ttyfd = open(ttname,2);		/* Try to open for read/write */#endif /* uxiii */    if (ttyfd < 0) {			/* If couldn't open, fail. */	perror(ttname);	return(-1);    }#ifdef aegis    /* Apollo C runtime claims that console pads are tty devices, which     * is reasonable, but they aren't any good for packet transfer. */    ios_$inq_type_uid((short)ttyfd, ttyuid, st);    if (st.all != status_$ok) {	fprintf(stderr, "problem getting tty object type: ");	error_$print(st);    } else if (ttyuid != sio_$uid) { /* reject non-SIO lines */	close(ttyfd); ttyfd = -1;	errno = ENOTTY; perror(ttname);	return(-1);    }#endif /* aegis */    strncpy(ttnmsv,ttname,DEVNAMLEN);	/* Open, keep copy of name locally. *//* Caller wants us to figure out if line is controlling tty */    debug(F111,"ttopen ok",ttname,*lcl);    if (*lcl == -1) {	if (strcmp(ttname,CTTNAM) == 0) {   /* "/dev/tty" always remote */	    debug(F110," Same as CTTNAM",ttname,0);	    xlocal = 0;	} else if (isatty(0)) {		/* Else, if stdin not redirected */#ifndef MINIX	    x = ttyname(0);		/* then compare its device name */	    strncpy(cname,x,DEVNAMLEN);	/* (copy from internal static buf) */	    debug(F110," ttyname(0)",x,0);	    x = ttyname(ttyfd); 	/* ...with real name of ttname. */	    xlocal = (strncmp(x,cname,DEVNAMLEN) == 0) ? 0 : 1;	    debug(F111," ttyname",x,xlocal);#else	    xlocal = 1;   /* can't do this test in minix */#endif /* MINIX */	} else {			/* Else, if stdin redirected... */#ifdef UXIII/* Sys III/V provides nice ctermid() function to get name of controlling tty */    	    ctermid(cname);		/* Get name of controlling terminal */	    debug(F110," ctermid",cname,0);	    x = ttyname(ttyfd); 	/* Compare with name of comm line. */	    xlocal = (strncmp(x,cname,DEVNAMLEN) == 0) ? 0 : 1;	    debug(F111," ttyname",x,xlocal);#else/* Just assume local, so "set speed" and similar commands will work *//* If not really local, how could it work anyway?... */	    xlocal = 1;	    debug(F101," redirected stdin","",xlocal);#endif /* uxiii */        }    }    /* Now check if line is locked -- if so fail, else lock for ourselves */    lkf = 0;				/* Check lock */    if (xlocal > 0) {	if (ttlock(ttname) < 0) {	    fprintf(stderr,"Exclusive access to %s denied\n",ttname);	    close(ttyfd); ttyfd = -1;	    debug(F110," Access denied by lock",ttname,0);	    return(-1);			/* Not if already locked */    	} else lkf = 1;    }/* Got the line, now set the desired value for local. */    if (*lcl < 0) *lcl = xlocal;/* Some special stuff for v7... */#ifdef	V7#ifndef MINIX	if (kmem[TTY] < 0) {	/*  If open, then skip this.  */		qaddr[TTY] = initrawq(ttyfd);	/* Init the queue. */		if ((kmem[TTY] = open("/dev/kmem", 0)) < 0) {			fprintf(stderr, "Can't read /dev/kmem in ttopen.\n");			perror("/dev/kmem");			exit(1);		}	}#endif /* not MINIX */#endif /* v7 *//* Request exclusive access on systems that allow it. */#ifndef XENIX/* Xenix exclusive access prevents open(close(...)) from working... */#ifdef TIOCEXCL    	if (ioctl(ttyfd,TIOCEXCL, (char *) NULL) < 0)	    fprintf(stderr,"Warning, problem getting exclusive access\n");#endif /* tiocexcl */#endif /* xenix *//* Get tty device settings */#ifndef UXIII    tcgetattr(ttyfd,&ttold);		/* Get termios info */#ifdef aegis    sio_$control((short)ttyfd, sio_$raw_nl, false, st);    if (xlocal) {	/* ignore breaks from local line */	sio_$control((short)ttyfd, sio_$int_enable, false, st);	sio_$control((short)ttyfd, sio_$quit_enable, false, st);    }#endif /* aegis */    tcgetattr(ttyfd,&ttraw);		/* And a copy of it for packets*/    tcgetattr(ttyfd,&tttvt);		/* And one for virtual tty service */#else    ioctl(ttyfd,TCGETA,&ttold);		/* Same deal for Sys III, Sys V */#ifdef aegis    sio_$control((short)ttyfd, sio_$raw_nl, false, st);    if (xlocal) {	/* ignore breaks from local line */	sio_$control((short)ttyfd, sio_$int_enable, false, st);	sio_$control((short)ttyfd, sio_$quit_enable, false, st);    }#endif /* aegis */    ioctl(ttyfd,TCGETA,&ttraw);    ioctl(ttyfd,TCGETA,&tttvt);#endif /* not uxiii */#ifdef VXVE    ttraw.c_line = 0;			/* STTY line 0 for VX/VE */    ioctl(ttyfd,TCSETA,&ttraw);    tttvt.c_line = 0;			/* STTY line 0 for VX/VE */    ioctl(ttyfd,TCSETA,&tttvt);#endif /* vxve */    debug(F101,"ttopen, ttyfd","",ttyfd);    debug(F101," lcl","",*lcl);    debug(F111," lock file",flfnam,lkf);    return(0);}/*  T T C L O S  --  Close the TTY, releasing any lock.  */ttclos() {    if (ttyfd < 0) return(0);		/* Wasn't open. */    if (xlocal) {#ifdef notdef	if (tthang())			/* Hang up phone line */	    fprintf(stderr,"Warning, problem hanging up the phone\n");#endif    	if (ttunlck())			/* Release uucp-style lock */	    fprintf(stderr,"Warning, problem releasing lock\n");    }    ttold.c_cflag &= ~HUPCL;    ttres();				/* Reset modes. *//* Relinquish exclusive access if we might have had it... */#ifndef XENIX#ifdef TIOCEXCL#ifdef TIOCNXCL    if (ioctl(ttyfd, TIOCNXCL, (char *) NULL) < 0)    	fprintf(stderr,"Warning, problem relinquishing exclusive access\n");#endif /* tiocnxcl */#endif /* tiocexcl */#endif /* not xenix */    close(ttyfd);			/* Close it. */#ifdef NEWUUCP    acucntrl("enable",flfnam);		/* Close getty on line. */#endif /* newuucp */    ttyfd = -1;				/* Mark it as closed. */    return(0);}/*  T T H A N G -- Hangup phone line */tthang() {#ifdef UXIII#ifdef HPUX    unsigned long dtr_down = 00000000000,                  modem_rtn;#else    unsigned short ttc_save;#endif /* hpux */#endif /* uxiii */    if (ttyfd < 0) return(0);		/* Not open. */#ifdef aegis    sio_$control((short)ttyfd, sio_$dtr, false, st);	/* DTR down */    msleep(500);					/* pause */    sio_$control((short)ttyfd, sio_$dtr, true,  st);	/* DTR up */#else#ifdef ANYBSD    ioctl(ttyfd,TIOCCDTR,0);		/* Clear DTR */    msleep(500);			/* Let things settle */    ioctl(ttyfd,TIOCSDTR,0);		/* Restore DTR */#endif /* anybsd */#ifdef UXIII#ifdef HPUX   /* Hewlett Packard way of modem control  */    if (ioctl(ttyfd,MCSETAF,&dtr_down) < 0) return(-1); /* lower DTR */    msleep(500);    if (ioctl(ttyfd,MCGETA,&modem_rtn) < 0) return(-1); /* get line status */    if ((modem_rtn & MDCD) != 0) return(-1);        /* check if DCD is low */    modem_rtn = MRTS | MDTR;                        /* bits for RTS & DTR  */    if (ioctl(ttyfd,MCSETAF,&modem_rtn) < 0) return(-1);    /*  set lines  */#else    ttc_save = ttraw.c_cflag;    ttraw.c_cflag &= ~CBAUD;		/* swa: set baud rate to 0 to hangup */    if (ioctl(ttyfd,TCSETAF,&ttraw) < 0) return(-1); /* do it */    msleep(100);			/* let things settle */    ttraw.c_cflag = ttc_save;/* NOTE - The following #ifndef...#endif can be removed for SCO Xenix 2.1.3 *//* or later, but must keep for earlier versions, which can't do close/open. */#ifndef XENIX		/* xenix cannot do close/open when carrier drops */				/* following corrects a PC/IX defficiency */    ttc_save = fcntl(ttyfd,F_GETFL,0);    close(ttyfd);		/* close/reopen file descriptor */    if ((ttyfd = open(ttnmsv, ttc_save)) < 0) return(-1);#endif /* not xenix */    if (ioctl(ttyfd,TCSETAF,&ttraw) < 0) return(-1); /* un-do it */#endif /* uxiii */#endif /* hpux  */#endif /* aegis */    return (0);}/*  T T R E S  --  Restore terminal to "normal" mode.  */ttres() {				/* Restore the tty to normal. */    int x;    if (ttyfd < 0) return(-1);		/* Not open. */#ifndef UXIII				/* except for sIII, */    sleep(1);				/* Wait for pending i/o to finish. */#endif	/* uxiii */			/*   (sIII does wait in ioctls) */#ifdef UXIII    if (ioctl(ttyfd,TCSETAW,&ttold) < 0) return(-1); /* restore termio stuff */    if (fcntl(ttyfd,F_SETFL, fcntl(ttyfd, F_GETFL, 0) & ~O_NDELAY) < 0 )      return(-1);#else /* not uxiii */#ifdef FIONBIO    x = 0;    x = ioctl(ttyfd,FIONBIO,&x);    if (x < 0) {	perror("ttres ioctl");	debug(F101,"ttres ioctl","",x);    }#else /* not fionbio */#ifdef FNDELAY    x = (fcntl(ttyfd,F_SETFL,fcntl(ttyfd,F_GETFL,0) & ~FNDELAY) == -1);    debug(F101,"ttres fcntl","",x);    if (x < 0) perror("fcntl");#endif /* fndelay */#endif /* fionbio */    x = tcsetattr(ttyfd,TCSANOW,&ttold);	/* Restore termios stuff */    debug(F101,"ttres tcsetattr","",x);    if (x < 0) perror("tcsetattr");#endif /* uxiii */    return(x);}/* Exclusive uucp file locking control *//* by H. Fischer, creative non-Bell coding ! copyright rights for lock modules assigned to Columbia University*/static char *xxlast(s,c) char *s; char c; {		/* Equivalent to strrchr() */    int i;    for (i = strlen(s); i > 0; i--)    	if ( s[i-1] == c ) return( s + (i - 1) );    return(NULL);    }staticlook4lk(ttname) char *ttname; {    extern char *strcat(), *strcpy();    char *device, *devname;    char lockfil[50];			/* Max length for lock file name */#ifdef ISIII    char *lockdir = "/etc/locks";#else#ifdef ATT3BX    char *lockdir = "/usr/spool/locks";#else#ifdef NEWUUCP    char *lockdir = "/usr/spool/uucp/LCK";#else    char *lockdir = "/usr/spool/uucp";#endif /* newuucp */#endif /* att3bx */#endif /* isiii */    device = ( (devname=xxlast(ttname,'/')) != NULL ? devname+1 : ttname);#ifdef ISIII    (void) strcpy( lockfil, device );#else    strcat( strcpy( lockfil, "LCK.." ), device );#endif /* isiii */    if (access( lockdir, 04 ) < 0) {	/* read access denied on lock dir */	fprintf(stderr,"Warning, read access to lock directory denied\n");	return( 1 );			/* cannot check or set lock file */    }	    strcat(strcat(strcpy(flfnam,lockdir),"/"), lockfil);    debug(F110,"look4lk",flfnam,0);    if ( ! access( flfnam, 00 ) ) {	/* print out lock file entry */	char lckcmd[40] ;	strcat( strcpy(lckcmd, "ls -l ") , flfnam);	system(lckcmd);	if (access(flfnam,02) == 0)	    printf("(You may type \"! rm %s\" to remove this file)\n",flfnam);	return( -1 );    }    if ( access( lockdir, 02 ) < 0 ) {	/* lock file cannot be written */	fprintf(stderr,"Warning, write access to lock directory denied\n");	return( 1 );    }    return( 0 );			/* okay to go ahead and lock */}/*  T T L O C K  */staticttlock(ttfd) char *ttfd; {		/* lock uucp if possible */#ifndef aegis#ifdef ATT3BX    FILE *lck_fild;#endif /* att3bx */    int lck_fil, l4l;    int pid_buf = getpid();		/* pid to save in lock file */	    hasLock = 0;			/* not locked yet */    l4l = look4lk(ttfd);    if (l4l < 0) return (-1);		/* already locked */    if (l4l == 1) return (0);		/* can't read/write lock directory */    lck_fil = creat(flfnam, 0444);	/* create lock file ... */    if (lck_fil < 0) return (-1);	/* create of lockfile failed */		/* creat leaves file handle open for writing -- hf */#ifdef ATT3BX    fprintf((lck_fild = fdopen(lck_fil, "w")), "%10d\n", pid_buf);    fflush(lck_fild);#else    write (lck_fil, &pid_buf, sizeof(pid_buf) ); /* uucp expects int in file */#endif /* att3bx */    close (lck_fil);    hasLock = 1;			/* now is locked */#endif /* not aegis */    return(0);}/*  T T U N L O C K  */staticttunlck() {				/* kill uucp lock if possible */    if (hasLock) return( unlink( flfnam ) );    return(0);}/* New-style (4.3BSD) UUCP line direction control (Stan Barber, Rice U) */#ifdef NEWUUCPacucntrl(flag,ttname) char *flag, *ttname; {    char x[DEVNAMLEN+32], *device, *devname;    if (strcmp(ttname,CTTNAM) == 0 || xlocal == 0) /* If not local, */        return;				/* just return. */    device = ((devname = xxlast(ttname,'/')) != NULL ? devname+1 : ttname);    if (strncmp(device,"LCK..",4) == 0) device += 5;    sprintf(x,"/usr/lib/uucp/acucntrl %s %s",flag,device);    debug(F000,"called ",x,0);    system(x);}#endif /* newuucp *//*  T T P K T  --  Condition the communication line for packets. *//*		or for modem dialing */#define DIALING	4		/* flags (via flow) for modem handling */#define CONNECT 5/*  If called with speed > -1, also set the speed.  *//*  Returns 0 on success, -1 on failure.  */ttpkt(speed,flow,parity) int speed, flow, parity; {    int s, x;    if (ttyfd < 0) return(-1);		/* Not open. */    ttprty = parity;			/* Let other tt functions see this. */    debug(F101,"ttpkt setting ttprty","",ttprty);    s = ttsspd(speed);			/* Check the speed */#ifndef UXIII    if (flow == 1) ttraw.c_iflag |= (IXON|IXOFF);    if (flow == 0) ttraw.c_iflag &= ~(IXON|IXOFF);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -