1: #ifndef lint
   2: static char sccsid[] = "@(#)df2.c	4.2 (Berkeley) 6/23/85";
   3: #endif
   4: 
   5: #include "../condevs.h"
   6: #ifdef DF02
   7: 
   8: /*
   9:  *	df2opn(ph, flds, dev)	dial remote machine
  10:  *
  11:  *	return codes:
  12:  *		file descriptor  -  succeeded
  13:  *		FAIL  -  failed
  14:  */
  15: df2opn(ph, flds, dev)
  16: char *ph;
  17: char *flds[];
  18: struct Devices *dev;
  19: {
  20:     char dcname[20], dnname[20], phone[MAXPH+2], c = 0;
  21: #ifdef  USG
  22:     struct termio ttbuf;
  23: #endif  USG
  24:     int dcf, dnf;
  25:     int nw, lt, pid, st, status;
  26:     unsigned timelim;
  27: #ifdef  TIOCFLUSH
  28:     int zero = 0;
  29: #endif	TIOCFLUSH
  30: 
  31:     sprintf(dnname, "/dev/%s", dev->D_calldev);
  32:     if (setjmp(Sjbuf)) {
  33:         logent(dnname, "CAN'T OPEN");
  34:         DEBUG(4, "%s Open timed out\n", dnname);
  35:         return CF_NODEV;
  36:     }
  37:     signal(SIGALRM, alarmtr);
  38:     getnextfd();
  39:     errno = 0;
  40:     alarm(10);
  41:     dnf = open(dnname, 2 );
  42:     alarm(0);
  43:     next_fd = -1;
  44:     if (dnf < 0 && errno == EACCES) {
  45:         logent(dnname, "CAN'T OPEN");
  46:         delock(dev->D_line);
  47:         logent("DEVICE", "NO");
  48:         return CF_NODEV;
  49:     }
  50:     fioclex(dnf);
  51: 
  52:     sprintf(dcname, "/dev/%s", dev->D_line);
  53:     fixline(dnf, dev->D_speed);
  54:     sprintf(phone, "\02%s", ph);
  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:         write(dnf, "\01", 1);
  78:         sleep(1);
  79:         nw = write(dnf, phone, lt = strlen(phone));
  80:         if (nw != lt) {
  81:             logent("DIALUP ACU write", _FAILED);
  82:             exit(1);
  83:         }
  84:         DEBUG(4, "ACU write ok%s\n", CNULL);
  85:         exit(0);
  86:     }
  87:     /*  open line - will return on carrier */
  88:     /* RT needs a sleep here because it returns immediately from open */
  89: 
  90: #if RT
  91:     sleep(15);
  92: #endif
  93: 
  94:     if (read(dnf, &c, 1) != 1 || c != 'A')
  95:         dcf = -1;
  96:     else
  97:         dcf = 0;
  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:     dcf = dnf;
 108:     dnf = 0;
 109:     while ((nw = wait(&lt)) != pid && nw != -1)
 110:         ;
 111: #ifdef  USG
 112:     ioctl(dcf, TCGETA, &ttbuf);
 113:     if(!(ttbuf.c_cflag & HUPCL)) {
 114:         ttbuf.c_cflag |= HUPCL;
 115:         ioctl(dcf, TCSETA, &ttbuf);
 116:     }
 117: #endif USG
 118:     alarm(0);
 119:     fflush(stdout);
 120:     fixline(dcf, dev->D_speed);
 121:     DEBUG(4, "Fork Stat %o\n", lt);
 122:     if (lt != 0) {
 123:         close(dcf);
 124:         if (dnf)
 125:             close(dnf);
 126:         delock(dev->D_line);
 127:         return CF_DIAL;
 128:     }
 129:     return dcf;
 130: }
 131: 
 132: /*
 133:  * df2cls()	close the DF02/DF03 call unit
 134:  *
 135:  *	return codes: none
 136:  */
 137: df2cls(fd)
 138: register int fd;
 139: {
 140:     if (fd > 0) {
 141:         close(fd);
 142:         sleep(5);
 143:         delock(devSel);
 144:     }
 145: }
 146: #endif DF02

Defined functions

df2cls defined in line 137; never used
df2opn defined in line 15; never used

Defined variables

sccsid defined in line 2; never used
Last modified: 1987-02-17
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1543
Valid CSS Valid XHTML 1.0 Strict