clean y.tab.h
[unix-history] / usr / src / usr.bin / tip / hunt.c
CommitLineData
051b1e55 1/*
c9686c12
KB
2 * Copyright (c) 1983 The Regents of the University of California.
3 * All rights reserved.
4 *
cb956e54 5 * %sccs.include.redist.c%
051b1e55
DF
6 */
7
05862919 8#ifndef lint
cb956e54 9static char sccsid[] = "@(#)hunt.c 5.6 (Berkeley) %G%";
c9686c12 10#endif /* not lint */
60d5f7dd 11
05862919 12#include "tip.h"
60d5f7dd
BJ
13
14extern char *getremote();
15extern char *rindex();
16
05862919
SL
17static jmp_buf deadline;
18static int deadfl;
60d5f7dd 19
981fd33c 20void
60d5f7dd
BJ
21dead()
22{
23 deadfl = 1;
05862919 24 longjmp(deadline, 1);
60d5f7dd
BJ
25}
26
27hunt(name)
d8feebc2 28 char *name;
60d5f7dd
BJ
29{
30 register char *cp;
981fd33c 31 sig_t f;
60d5f7dd 32
05862919 33 f = signal(SIGALRM, dead);
3f48242d 34 while (cp = getremote(name)) {
8f1963b9 35 deadfl = 0;
60d5f7dd 36 uucplock = rindex(cp, '/')+1;
5d369851 37 if (uu_lock(uucplock) < 0)
60d5f7dd 38 continue;
f0211bf2 39 /*
6b46907f
RC
40 * Straight through call units, such as the BIZCOMP,
41 * VADIC and the DF, must indicate they're hardwired in
f0211bf2
SL
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;
05862919
SL
48 if (setjmp(deadline) == 0) {
49 alarm(10);
50 FD = open(cp, O_RDWR);
60d5f7dd
BJ
51 }
52 alarm(0);
274c3d56
MK
53 if (FD < 0) {
54 perror(cp);
55 deadfl = 1;
56 }
05862919
SL
57 if (!deadfl) {
58 ioctl(FD, TIOCEXCL, 0);
59 ioctl(FD, TIOCHPCL, 0);
60 signal(SIGALRM, SIG_DFL);
61 return ((int)cp);
62 }
5d369851 63 (void)uu_unlock(uucplock);
60d5f7dd 64 }
05862919 65 signal(SIGALRM, f);
3f48242d 66 return (deadfl ? -1 : (int)cp);
60d5f7dd 67}