summaryrefslogtreecommitdiff
path: root/usr/src/cmd/tip/aculib/dn11.c
blob: d383fd53fbe1bbd70fe6da4f6877578a9af01d7c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
 * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

/*
 * Copyright (c) 1983 Regents of the University of California.
 * All rights reserved. The Berkeley software License Agreement
 * specifies the terms and conditions for redistribution.
 */

#pragma ident	"%Z%%M%	%I%	%E% SMI"

/*
 * Routines for dialing up on DN-11
 */
#include "tip.h"

void	alarmtr(void);

static sigjmp_buf	jmpbuf;
static int	child = -1, dn;

int
dn_dialer(char *num, char *acu)
{
	int lt, nw;
	int timelim;
	struct termios buf;

	if (boolean(value(VERBOSE)))
		(void) printf("\nstarting call...");
	if ((dn = open(acu, 1)) < 0) {
		if (errno == EBUSY)
			(void) printf("line busy...");
		else
			(void) printf("acu open error...");
		return (0);
	}
	if (sigsetjmp(jmpbuf, 1)) {
		(void) kill(child, SIGKILL);
		(void) close(dn);
		return (0);
	}
	(void) signal(SIGALRM, (sig_handler_t)alarmtr);
	timelim = 5 * strlen(num);
	(void) alarm(timelim < 30 ? 30 : timelim);
	if ((child = fork()) == 0) {
		/*
		 * ignore this stuff for aborts
		 */
		(void) signal(SIGALRM, SIG_IGN);
		(void) signal(SIGINT, SIG_IGN);
		(void) signal(SIGQUIT, SIG_IGN);
		(void) sleep(2);
		nw = write(dn, num, lt = strlen(num));
		exit(nw != lt);
	}
	/*
	 * open line - will return on carrier
	 */
	if ((FD = open(DV, 2)) < 0) {
		if (errno == EIO)
			(void) printf("lost carrier...");
		else
			(void) printf("dialup line open failed...");
		(void) alarm(0);
		(void) kill(child, SIGKILL);
		(void) close(dn);
		return (0);
	}
	(void) alarm(0);
	(void) ioctl(dn, TCGETS, &buf);
	buf.c_cflag |= HUPCL;
	(void) ioctl(dn, TCSETSF, &buf);
	(void) signal(SIGALRM, SIG_DFL);
	while ((nw = wait(&lt)) != child && nw != -1)
		;
	(void) fflush(stdout);
	(void) close(dn);
	if (lt != 0) {
		(void) close(FD);
		return (0);
	}
	return (1);
}

void
alarmtr(void)
{

	(void) alarm(0);
	siglongjmp(jmpbuf, 1);
}

/*
 * Insurance, for some reason we don't seem to be
 *  hanging up...
 */
void
dn_disconnect(void)
{
	int dtr = TIOCM_DTR;

	(void) sleep(2);
	if (FD > 0)
		(void) ioctl(FD, TIOCMBIC, &dtr);
	(void) close(FD);
}

void
dn_abort(void)
{
	int dtr = TIOCM_DTR;

	(void) sleep(2);
	if (child > 0)
		(void) kill(child, SIGKILL);
	if (dn > 0)
		(void) close(dn);
	if (FD > 0)
		(void) ioctl(FD, TIOCMBIC, &dtr);
	(void) close(FD);
}