4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 1994 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 #pragma ident "%Z%%M% %I% %E% SMI"
34 * create a Datakit connection to a remote destination
37 static char SCCSID
[] = "@(#)dkdial.c 2.7+BNU DKHOST 87/03/09";
40 * COMMKIT(TM) Software - Datakit(R) VCS Interface Release 2.0 V1
53 #define DK_DEFWAIT 89 /* default time to wait for dial return */
54 #define DK_MAXWAIT 600 /* maximum wait to allow the caller - 10 min */
57 GLOBAL
unsigned int dk_timewait
= DK_DEFWAIT
; /* Caller to dkdial might modify */
59 static char Conn_Msg
[] = "Can't connect to %s: %s\n";
60 static char Resp_Msg
[] = "No response from Datakit";
62 static SIGRTN
timout(); /* Alarm signal handler */
63 static void setalarm(), usralarm();
65 static int Elapsed
; /* Alarm time elapsed during dial */
66 static int Timer
; /* Current alarm setting */
67 static short TimeErr
; /* Alarm clock rang */
69 extern char *getenv();
70 EXTERN
int dk_verbose
, dk_errno
;
76 return(dkndial(dest
, atoi(getenv("DKINTF"))));
83 short fd
; /* Channel Descriptor */
84 SIGRTN (*SigWas
)(); /* Caller's alarm handler */
85 unsigned int TimWas
; /* Caller's alarm clock */
94 sprintf(dial_dev
, "/dev/dk/dial%d", intf
);
97 ** Clear our elapsed time and save caller's alarm stuff.
101 SigWas
= signal(SIGALRM
, timout
);
105 ** If requested timeout interval is unreasonable, use the default.
108 if ((dk_timewait
== 0) || (dk_timewait
> DK_MAXWAIT
))
109 dk_timewait
= DK_DEFWAIT
;
112 ** Do an alarm protected open of the dial device
115 setalarm(dk_timewait
);
117 if ((fd
= open(dial_dev
, O_RDWR
)) < 0) {
120 fprintf(stderr
, "dkdial: Can't open %s\n", dial_dev
);
121 usralarm(TimWas
, SigWas
);
123 return(dk_errno
= -EX_TEMPFAIL
);
125 return(dk_errno
= -EX_OSFILE
);
129 ** If the caller has a DKKEY, use it.
132 if((key
= getenv("DKKEY")) != NULL
&& getuid() == geteuid())
133 sprintf(ioreq
.dialstring
, "%s\n%s", dest
, key
);
135 strcpy(ioreq
.dialstring
, dest
);
137 ioreq
.iocb
.req_traffic
= 0;
138 ioreq
.iocb
.req_1param
= 0;
139 ioreq
.iocb
.req_2param
= 0;
142 ** Try to dial the call. If the alarm expires during the ioctl,
143 ** the ioctl will return in error.
146 if (ioctl(fd
, DKIODIAL
, &ioreq
) < 0) {
150 fprintf(stderr
, Conn_Msg
, Resp_Msg
, ioreq
.dialstring
);
152 fprintf(stderr
, Conn_Msg
, ioreq
.dialstring
, dkerr(ioreq
.iocb
.req_error
));
154 setalarm(2); /* Don't wait forever on close */
156 usralarm(TimWas
, SigWas
);
158 return(-dkerrmap(dk_errno
= -EX_TEMPFAIL
));
160 return(-dkerrmap(dk_errno
= ioreq
.iocb
.req_error
));
162 usralarm(TimWas
, SigWas
);
167 ** timout() is the alarm clock signal handling routine. It is called
168 ** whenever the alarm clock expires during dial processing.
180 ** setalarm() is called to request an alarm at a future time. The residual
181 ** from the previous alarm (if any) is added to the elapsed time counter.
188 (void) signal(SIGALRM
, timout
);
189 Elapsed
+= Timer
- alarm(Seconds
);
194 ** usralarm() is used to restore the alarm service for the caller.
198 usralarm(TimWas
, SigWas
)
199 int TimWas
; /* Caller's alarm clock */
200 SIGRTN (*SigWas
)(); /* Caller's alarm handler */
202 Elapsed
+= Timer
- alarm(0);
203 (void) signal(SIGALRM
, SigWas
);