BSD 4_2 release
[unix-history] / usr / src / usr.bin / tip / hunt.c
CommitLineData
05862919 1#ifndef lint
0f4556f1 2static char sccsid[] = "@(#)hunt.c 4.8 (Berkeley) 10/20/83";
05862919 3#endif
60d5f7dd 4
05862919 5#include "tip.h"
60d5f7dd
BJ
6
7extern char *getremote();
8extern char *rindex();
9
05862919
SL
10static jmp_buf deadline;
11static int deadfl;
60d5f7dd
BJ
12
13dead()
14{
05862919 15
60d5f7dd 16 deadfl = 1;
05862919 17 longjmp(deadline, 1);
60d5f7dd
BJ
18}
19
20hunt(name)
d8feebc2 21 char *name;
60d5f7dd
BJ
22{
23 register char *cp;
05862919 24 int (*f)();
60d5f7dd 25
05862919 26 f = signal(SIGALRM, dead);
60d5f7dd 27 deadfl = 0;
3f48242d 28 while (cp = getremote(name)) {
60d5f7dd
BJ
29 uucplock = rindex(cp, '/')+1;
30 if (mlock(uucplock) < 0) {
31 delock(uucplock);
32 continue;
33 }
f0211bf2 34 /*
6b46907f
RC
35 * Straight through call units, such as the BIZCOMP,
36 * VADIC and the DF, must indicate they're hardwired in
f0211bf2
SL
37 * order to get an open file descriptor placed in FD.
38 * Otherwise, as for a DN-11, the open will have to
39 * be done in the "open" routine.
40 */
41 if (!HW)
42 break;
05862919
SL
43 if (setjmp(deadline) == 0) {
44 alarm(10);
45 FD = open(cp, O_RDWR);
60d5f7dd
BJ
46 }
47 alarm(0);
0f4556f1
C
48 if (FD < 0) {
49 perror(cp);
50 deadfl = 1;
51 }
05862919
SL
52 if (!deadfl) {
53 ioctl(FD, TIOCEXCL, 0);
54 ioctl(FD, TIOCHPCL, 0);
55 signal(SIGALRM, SIG_DFL);
56 return ((int)cp);
57 }
673be859 58 delock(uucplock);
60d5f7dd 59 }
05862919 60 signal(SIGALRM, f);
3f48242d 61 return (deadfl ? -1 : (int)cp);
60d5f7dd 62}