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

📄 condevs.c

📁 <B>Digital的Unix操作系统VAX 4.2源码</B>
💻 C
📖 第 1 页 / 共 4 页
字号:
	    while(rddev(dfp, &dev) != FAIL) {		if (strcmp(flds[F_CLASS], dev.D_class) != SAME)		    continue;		if (snccmp(flds[F_LINE], dev.D_type) != SAME)		    continue;		havebrand = 0;		if (dev.D_brand[0] == '\0')		    logent("Acuopn","No 'brand' name on ACU");		else if (snccmp(dev.D_brand, cd->CU_brand) == SAME)		    havebrand = 1;		/* The havebrand game is necessary if the brand in L-devices		   is NOT in the condefs.c list of known devices. Thus		   the generic dialer can be called even if this brand		   does not have a 'subroutine' equivalent */		tcd = cd;		isgen = 0;#ifdef GENERIC		if(gendialer) {  /* See if we can use the generic routines */		      if(agetent(&gbuf[0],dev.D_brand) > 0) {			havebrand = 1;			isgen = 1;			for(gencd = condevs; gencd->CU_meth != NULL; gencd++)				if(prefix(gencd->CU_brand, "generic"))					cd = gencd;     /* the old switch-a-roo to generic */		      }		}#endif		if(!havebrand)			continue;		DEBUG(4,"correct brand %s\n", dev.D_brand);		if (mlock(dev.D_line) == FAIL) {		    cd = tcd;		    continue;		}		DEBUG(4, "Using %s\n", cd->CU_brand);		CU_end = cd->CU_clos;   /* point CU_end at close func */		fd = (*(cd->CU_open))(phone, flds, &dev);		if (fd > 0) {		    DEBUG(5, "open succeeded\n", "");		    fclose(dfp);		    strcpy(devSel, dev.D_line);   /* save for later unlock() */		    sprintf(msg, "%s, fd= %d, brand = %s %s",devSel, fd, dev.D_brand, isgen ? "- generic" : "");		    logent(msg, "using device");		    return(fd);		    }		ret = CF_DIAL;		CU_end = nulldev;		delock(dev.D_line);		}	    }	}    fclose(dfp);    return(ret);    }#ifdef DN11/*** *      dnopn(ph, flds, dev)    dial remote machine *      char *ph; *      char *flds[]; *      struct Devices *dev; * *      return codes: *              file descriptor  -  succeeded *              FAIL  -  failed */dnopn(ph, flds, dev)char *ph;char *flds[];struct Devices *dev;{	char dcname[20], dnname[20], phone[MAXPH+2], c = 0;#ifdef  SYSIII	struct termio ttbuf;#endif	int dnf, dcf;	int nw, lt, pid, status;	unsigned timelim;	sprintf(dnname, "/dev/%s", dev->D_calldev);	errno = 0;	if (setjmp(Sjbuf)) {		logent(dnname, "CAN'T OPEN");		DEBUG(4, "%s Open timed out\n", dnname);		return(CF_NODEV);	}	signal(SIGALRM, alarmtr);	getnextfd();	alarm(10);	dnf = open(dnname, 1);	alarm(0);	next_fd = -1;	if (dnf < 0 && errno == EACCES) {		logent(dnname, "CAN'T OPEN");		logent("DEVICE", "NO");		return(CF_NODEV);		}	if (ioctl(dnf, TIOCSINUSE)<0 && errno==EALREADY) {		logent(dnname, "SHARED LINE IN USE");		close(dnf);		return(FAIL);	}				}	/* rti!trt: avoid passing acu file descriptor to children */	fioclex(dnf);	sprintf(dcname, "/dev/%s", dev->D_line);	sprintf(phone, "%s%s", ph, ACULAST);	DEBUG(4, "dc - %s, ", dcname);	DEBUG(4, "acu - %s\n", dnname);	pid = 0;	if (setjmp(Sjbuf)) {		logent("DIALUP DN write", "TIMEOUT");		if (pid)			kill(pid, 9);		delock(dev->D_line);		if (dnf)			close(dnf);		return(FAIL);	}	signal(SIGALRM, alarmtr);	timelim = 5 * strlen(phone);	alarm(timelim < 30 ? 30 : timelim);	if ((pid = fork()) == 0) {		sleep(2);		fclose(stdin);		fclose(stdout);#ifdef  TIOCFLUSH		ioctl(dnf, TIOCFLUSH, STBNULL);#endif		nw = write(dnf, phone, lt = strlen(phone));		if (nw != lt) {			logent("DIALUP ACU write", "FAILED");			exit(1);		}		DEBUG(4, "ACU write ok%s\n", "");		exit(0);	}	/*  open line - will return on carrier */	/* RT needs a sleep here because it returns immediately from open */#if RT	sleep(15);#endif	getnextfd();	errno = 0;	dcf = open(dcname, 2);	next_fd = -1;	if (dcf < 0 && errno == EACCES)		logent(dcname, "CAN'T OPEN");	DEBUG(4, "dcf is %d\n", dcf);	if (dcf < 0) {		logent("DIALUP LINE open", "FAILED");		alarm(0);		kill(pid, 9);		close(dnf);		delock(dev->D_line);		return(FAIL);	}#ifdef ULTRIX	/* ensure correct process group if run in background by cron */	{	int pgrp = getpid(); /* XXX: was getpgrp(), not getpid() */	ret=setpgrp(pgrp, pgrp); /* XXX: first pgrp is really our pid */	if (ret < 0)		DEBUG(6,"setpgrp failed, errno=%d\n", errno);	ioctl(dcf, TIOCSPGRP, &pgrp);	}#endif	/* brl-bmd.351 (Doug Kingston) says the next ioctl is unneeded . *//*      ioctl(dcf, TIOCHPCL, STBNULL);*/	while ((nw = wait(&lt)) != pid && nw != -1)		;#ifdef  SYSIII	ioctl(dcf, TCGETA, &ttbuf);	if(!(ttbuf.c_cflag & HUPCL)) {		ttbuf.c_cflag |= HUPCL;		ioctl(dcf, TCSETA, &ttbuf);	}#endif	alarm(0);	fflush(stdout);	fixline(dcf, dev->D_speed);	DEBUG(4, "Fork Stat %o\n", lt);	if (lt != 0) {		close(dcf);		if (dnf)			close(dnf);		delock(dev->D_line);		return(FAIL);	}	return(dcf);}/*** *      dncls()         close dn type call unit * *      return codes:   None */dncls(fd)register int fd;{	if (fd > 0) {		close(fd);		sleep(5);		delock(devSel);		}}#endif DN11#ifdef GENERIC/****       Generic dialer routine written by lp@decvax. This routine*       calls a routine written for tip which trys to handle smart*       modems in a reasonable way. Rather than having different*       code for each "type" of modem we treat all modems which*       are activated by "initialization string, dial string,*       & disconnect string" the same. So far the gen_dialer() routine*       written for tip (& called below) has been able to handle*       all modems we have & should be able to handle just about*       any 'modern' modem.***/genopn(ph, flds, dev)char *ph, *flds[];struct Devices *dev;{	extern int generrno;	extern char gbuf[];	char msg[128], dnname[20];	int FD, ret;	sprintf(dnname, "/dev/%s", dev->D_calldev);	errno = 0;#ifdef V7M11#define O_RDWR 002#define O_WRONLY 001#endif#ifdef ONDELAY	FD = open(dnname, O_RDWR|O_NDELAY);#else	FD = open(dnname, O_RDWR);#endif	if (FD < 0 && errno == EACCES) {		delock(dev->D_line);		logent(dnname, "CAN'T OPEN");		return(CF_TRYANOTHER);	}	else if (FD < 0 && errno == EBUSY) {		logent(dnname, "ALREADY OPEN");		return(CF_TRYANOTHER);		/* dont remove lock if someone else has		 * this device (tip/cu).		 * tip/cu do not "refresh" lock files		 * so it is possible to remove a valid		 * lock file.  Fortunately tip uses		 * exclusive access so any further opens		 * should return EBUSY.		 */		}	if (FD<0) {		sprintf(msg,"Generic device=%s, errno = %d", dnname, errno);		logent(msg, "open failed");		return(FAIL);	}	if (ioctl(FD, TIOCSINUSE)<0 && errno==EALREADY) {		logent(dnname, "SHARED LINE IN USE");		close(FD);		return(FAIL);	}	Dcf=FD; /* so clsacu will work */  /* Use info gleaned from aculist to setup the gen_dialer data base */  /* gbuf is stored away in the getto routine of conn.c */	DEBUG(4,"Calling gen_setup", "");	ioctl(FD, TIOCNCAR);  /* ignore carrier while dialing number */	(void) gen_setup(&gbuf[0], FD);#ifdef ULTRIX	{	int pgrp = getpid(); /* XXX: was getpgrp(), not getpid() */	int temp = 0;	ret=setpgrp(pgrp, pgrp); /* XXX: first pgrp is really our pid */	if (ret < 0)		DEBUG(6,"setpgrp failed, errno=%d\n", errno);	/* ensure correct process group if run in background by cron */	ioctl(FD, TIOCSPGRP, &pgrp);	}#endif#ifdef V7M11	fixline(FD, 300);#else	fixline(FD, dev->D_speed);#endif	/* Call generic dialer */	generrno = 0;	ret = gen_dialer(ph, dev->D_brand);#define NOSYNC 1#define BADDIAL 2#define NOCARR 3	if(ret != 1) {		DEBUG(1, "Generic dialer error on %s\n", dnname);		clsacu();		delock(dev->D_line);		sprintf(msg, "Generic dialer failed - acu = %s, cause = %s", dnname, generrno == NOSYNC ? "can't sync" : generrno == BADDIAL ? "misdialed, try another" : "no carrier");		logent(msg, "ERROR");		return(generrno == NOSYNC ? CF_DIAL : generrno == BADDIAL ? CF_TRYANOTHER : FAIL);	}	/* else everything is cool so return the file discriptor */	fflush(stdout);	return(FD);}gencls(fd)int fd;{	char msg[20];	DEBUG(5, "close generic, Def = %d\n", fd);	gen_disconnect();	close(fd);	sprintf(msg,"fd=%d",fd);	logent(msg,"closed generic acu");	sleep(5);	delock(devSel);}#endif#ifdef DF0/*** *      df0opn(ph, flds, dev)   dial remote machine *                      with a df02 or df03. *      char *ph; *      char *flds[]; *      struct Devices *dev; * *      return codes: *              file descriptor  -  succeeded *              FAIL  -  failed * *      Modified 9/28/81 by Bill Shannon (DEC) */df0opn(ph, flds, dev)char *ph;char *flds[];struct Devices *dev;{	char  dnname[20], phone[MAXPH+2], c = 0;#ifdef  SYSIII	struct termio ttbuf;#endif	int status;	int nw, lt, pid, dnf;	int ret, df02, df03;	unsigned timelim;	char msg[50];	df02 = (strcmp(dev->D_brand, "DF02") == SAME);	df03 = (strcmp(dev->D_brand, "DF03") == SAME);	DEBUG(4, "df0 device is a %s\n", df02 ? "DF02" : "DF03");	sprintf(dnname, "/dev/%s", dev->D_calldev);	errno = 0;#ifdef V7M11#define O_RDWR 002#define O_WRONLY 001#endif#ifdef ONDELAY	dnf = open(dnname, (df02||df03 ? O_RDWR : O_WRONLY)|O_NDELAY);#else	dnf = open(dnname, (df02||df03 ? O_RDWR : O_WRONLY));#endif	if (dnf < 0 && errno == EACCES) {		delock(dev->D_line);		logent(dnname, "CAN'T OPEN");		return(CF_TRYANOTHER);	}	else if (dnf < 0 && errno == EBUSY) {		logent(dnname, "ALREADY OPEN");		return(CF_TRYANOTHER);		/* dont remove lock if someone else has		 * this device (tip/cu).		 * tip/cu do not "refresh" lock files		 * so it is possible to remove a valid		 * lock file.  Fortunately tip uses		 * exclusive access so any further opens		 * should return EBUSY.		 */		}	if (dnf<0) {		sprintf(msg,"device=%s, errno = %d", dnname, errno);		logent(msg, "open failed");		return(FAIL);	}	if (ioctl(dnf, TIOCSINUSE)<0 && errno==EALREADY) {		logent(dnname, "SHARED LINE IN USE");		close(dnf);		return(FAIL);	}	Dcf=dnf; /* so clsacu will work */#ifdef ULTRIX	{	int pgrp = getpid(); /* XXX: was getpgrp(), not getpid() */	int temp = 0;	ret=setpgrp(pgrp, pgrp); /* XXX: first pgrp is really our pid */	if (ret < 0)		DEBUG(6,"setpgrp failed, errno=%d\n", errno);	/* ensure correct process group if run in background by cron */	ioctl(dnf, TIOCSPGRP, &pgrp);#ifdef ONDELAY	ret = ioctl(dnf, TIOCMODEM, &temp);  /* we are attatched to a modem */	if (ret < 0)		DEBUG(6, "ioctl(TIOCMODEM) - errno=%d\n", errno);	ioctl(dnf, TIOCNCAR);  /* ignore carrier while dialing number */#endif	}#endif/* Changed from TIOCMSET to TIOCMBIS by rti!trt */#ifdef TIOCMBIS	if (df03) {		/* set secondary transmit to mark (idle) state on dh's		 * and dz32's (the regular DZ does not have ST).		 * On devices with rate select (dmf/z) this translates to		 * select the high speed rate for 1200 bps.		 */		int st=TIOCM_ST;		fixline(dnf, 1200);		if (dev->D_speed != 1200)			ioctl(dnf, TIOCMBIC, &st);		else			ioctl(dnf, TIOCMBIS, &st);	} else#endif#ifdef V7M11			fixline(dnf, 300);#else			fixline(dnf, dev->D_speed);#endif	sprintf(phone, "\02%s", ph);	DEBUG(4, "acu - %s\n", dnname);	if (setjmp(Sjbuf)) {		DEBUG(1, "DN write %s\n", "timeout");		sprintf(msg, "DIALUP DN write - dnf=%d",dnf);		logent(msg, "TIMEOUT");		delock(dev->D_line);		clsacu();		return(FAIL);	}	signal(SIGALRM, alarmtr);	timelim = 5 * strlen(phone);	alarm(timelim < 30 ? 30 : timelim);	/*  open line - will return on carrier */	/* RT needs a sleep here because it returns immediately from open */#if RT	sleep(15);#endif#ifdef  TIOCFLUSH	ioctl(dnf, TIOCFLUSH, 0);#endif	write(dnf, "\01", 1);	sleep(1);	nw = write(dnf, phone, lt = strlen(phone));	if (nw != lt) {		DEBUG(1, "DF0 write %s\n", "error");		clsacu();		delock(dev->D_line);		logent("DIALUP DF0 write", "FAILED");		return(CF_DIAL);	}	DEBUG(4, "DF0 write ok%s\n", "");	errno=0;	sprintf(msg,"FAILED acu=%s, char=%o, errno=%d",		dnname, c, errno);	if (read(dnf, &c, 1) < 0) {		/* acu in strange state */		clsacu();		/* give this acu a rest, try another */		logent(msg, "df02/df03 illegal return");		delock(dev->D_line);		return(CF_TRYANOTHER);	}#ifndef ONDELAY	if (c != 'A') {		alarm(0);		clsacu();		delock(dev->D_line);		logent(msg, "FAILED-read on df02/3");		DEBUG(4,"FAILED-%s\n", msg);		return(CF_TRYANOTHER);	}#endif#ifdef V7M11	fixline(dnf, dev->D_speed);#endif#ifdef ONDELAY	ioctl(dnf, TIOCCAR);  /* dont ignore carrier anymore */	alarm(40);  /* find a better timeout value */	if (setjmp(Sjbuf)) {		DEBUG(1, "no carrier", "timeout");		sprintf(msg, "no carrier - dnf=%d",dnf);		logent(msg, "TIMEOUT");		delock(dev->D_line);		clsacu();		return(FAIL);	}	ioctl(dnf, TIOCWONLINE); /* wait for carrier */	alarm(0);#endif#ifdef  SYSIII	ioctl(dnf, TCGETA, &ttbuf);	if(!(ttbuf.c_cflag & HUPCL)) {

⌨️ 快捷键说明

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