1: #ifndef lint
   2: static char sccsid[] = "@(#)dn.c	4.2 (Berkeley) 6/23/85";
   3: #endif
   4: 
   5: #include "../condevs.h"
   6: #ifdef DN11
   7: #define ACULAST "-<"
   8: 
   9: /***
  10:  *	dnopn(ph, flds, dev)	dial remote machine
  11:  *
  12:  *	return codes:
  13:  *		file descriptor  -  succeeded
  14:  *		FAIL  -  failed
  15:  */
  16: dnopn(ph, flds, dev)
  17: char *ph;
  18: char *flds[];
  19: struct Devices *dev;
  20: {
  21:     char dcname[20], dnname[20], phone[MAXPH+2], c = 0;
  22: #ifdef  USG
  23:     struct termio ttbuf;
  24: #endif 	USG
  25:     int dnf, dcf;
  26:     int nw, lt, pid, status;
  27:     unsigned timelim;
  28: #ifdef TIOCFLUSH
  29:     int zero = 0;
  30: #endif TIOCFLUSH
  31: 
  32:     sprintf(dnname, "/dev/%s", dev->D_calldev);
  33:     errno = 0;
  34: 
  35:     if (setjmp(Sjbuf)) {
  36:         logent(dnname, "CAN'T OPEN");
  37:         DEBUG(4, "%s Open timed out\n", dnname);
  38:         return(CF_NODEV);
  39:     }
  40:     signal(SIGALRM, alarmtr);
  41:     getnextfd();
  42:     alarm(10);
  43:     dnf = open(dnname, 1);
  44:     alarm(0);
  45:     next_fd = -1;
  46:     if (dnf < 0 && errno == EACCES) {
  47:         logent(dnname, "CAN'T OPEN");
  48:         logent("DEVICE", "NO");
  49:         return CF_NODEV;
  50:     }
  51:     fioclex(dnf);
  52: 
  53:     sprintf(dcname, "/dev/%s", dev->D_line);
  54:     sprintf(phone, "%s%s", ph, ACULAST);
  55:     DEBUG(4, "dc - %s, ", dcname);
  56:     DEBUG(4, "acu - %s\n", dnname);
  57:     pid = 0;
  58:     if (setjmp(Sjbuf)) {
  59:         logent("DIALUP DN write", "TIMEOUT");
  60:         if (pid)
  61:             kill(pid, 9);
  62:         delock(dev->D_line);
  63:         if (dnf)
  64:             close(dnf);
  65:         return CF_DIAL;
  66:     }
  67:     signal(SIGALRM, alarmtr);
  68:     timelim = 5 * strlen(phone);
  69:     alarm(timelim < 30 ? 30 : timelim);
  70:     if ((pid = fork()) == 0) {
  71:         sleep(2);
  72:         fclose(stdin);
  73:         fclose(stdout);
  74: #ifdef  TIOCFLUSH
  75:         ioctl(dnf, TIOCFLUSH, &zero);
  76: #endif	TIOCFLUSH
  77:         nw = write(dnf, phone, lt = strlen(phone));
  78:         if (nw != lt) {
  79:             logent("DIALUP ACU write", _FAILED);
  80:             exit(1);
  81:         }
  82:         DEBUG(4, "ACU write ok\n", CNULL);
  83:         exit(0);
  84:     }
  85:     /*  open line - will return on carrier */
  86:     /* RT needs a sleep here because it returns immediately from open */
  87: 
  88: #if RT
  89:     sleep(15);
  90: #endif
  91: 
  92:     getnextfd();
  93:     errno = 0;
  94:     dcf = open(dcname, 2);
  95:     next_fd = -1;
  96:     if (dcf < 0 && errno == EACCES)
  97:         logent(dcname, "CAN'T OPEN");
  98:     DEBUG(4, "dcf is %d\n", dcf);
  99:     if (dcf < 0) {
 100:         logent("DIALUP LINE open", _FAILED);
 101:         alarm(0);
 102:         kill(pid, 9);
 103:         close(dnf);
 104:         delock(dev->D_line);
 105:         return CF_DIAL;
 106:     }
 107:     while ((nw = wait(&lt)) != pid && nw != -1)
 108:         ;
 109: #ifdef  USG
 110:     ioctl(dcf, TCGETA, &ttbuf);
 111:     if(!(ttbuf.c_cflag & HUPCL)) {
 112:         ttbuf.c_cflag |= HUPCL;
 113:         ioctl(dcf, TCSETA, &ttbuf);
 114:     }
 115: #endif USG
 116:     alarm(0);
 117:     fflush(stdout);
 118:     fixline(dcf, dev->D_speed);
 119:     DEBUG(4, "Fork Stat %o\n", lt);
 120:     if (lt != 0) {
 121:         close(dcf);
 122:         if (dnf)
 123:             close(dnf);
 124:         delock(dev->D_line);
 125:         return CF_DIAL;
 126:     }
 127:     return dcf;
 128: }
 129: 
 130: /***
 131:  *	dncls()		close dn type call unit
 132:  *
 133:  *	return codes:	None
 134:  */
 135: dncls(fd)
 136: register int fd;
 137: {
 138:     if (fd > 0) {
 139:         close(fd);
 140:         sleep(5);
 141:         delock(devSel);
 142:     }
 143: }
 144: #endif DN11

Defined functions

dncls defined in line 135; never used
dnopn defined in line 16; never used

Defined variables

sccsid defined in line 2; never used

Defined macros

ACULAST defined in line 7; used 1 times
  • in line 54
Last modified: 1987-02-17
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 3391
Valid CSS Valid XHTML 1.0 Strict