xref: /original-bsd/usr.bin/tip/hunt.c (revision c3e32dec)
1 /*
2  * Copyright (c) 1983, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #ifndef lint
9 static char sccsid[] = "@(#)hunt.c	8.1 (Berkeley) 06/06/93";
10 #endif /* not lint */
11 
12 #include "tip.h"
13 
14 extern char *getremote();
15 extern char *rindex();
16 
17 static	jmp_buf deadline;
18 static	int deadfl;
19 
20 void
21 dead()
22 {
23 	deadfl = 1;
24 	longjmp(deadline, 1);
25 }
26 
27 hunt(name)
28 	char *name;
29 {
30 	register char *cp;
31 	sig_t f;
32 
33 	f = signal(SIGALRM, dead);
34 	while (cp = getremote(name)) {
35 		deadfl = 0;
36 		uucplock = rindex(cp, '/')+1;
37 		if (uu_lock(uucplock) < 0)
38 			continue;
39 		/*
40 		 * Straight through call units, such as the BIZCOMP,
41 		 * VADIC and the DF, must indicate they're hardwired in
42 		 *  order to get an open file descriptor placed in FD.
43 		 * Otherwise, as for a DN-11, the open will have to
44 		 *  be done in the "open" routine.
45 		 */
46 		if (!HW)
47 			break;
48 		if (setjmp(deadline) == 0) {
49 			alarm(10);
50 			FD = open(cp, O_RDWR);
51 		}
52 		alarm(0);
53 		if (FD < 0) {
54 			perror(cp);
55 			deadfl = 1;
56 		}
57 		if (!deadfl) {
58 			ioctl(FD, TIOCEXCL, 0);
59 			ioctl(FD, TIOCHPCL, 0);
60 			signal(SIGALRM, SIG_DFL);
61 			return ((int)cp);
62 		}
63 		(void)uu_unlock(uucplock);
64 	}
65 	signal(SIGALRM, f);
66 	return (deadfl ? -1 : (int)cp);
67 }
68