Annotation of src/usr.bin/tip/hunt.c, Revision 1.3
1.3 ! deraadt 1: /* $OpenBSD: hunt.c,v 1.5 1995/10/29 00:49:40 pk Exp $ */
1.2 deraadt 2: /* $NetBSD: hunt.c,v 1.5 1995/10/29 00:49:40 pk Exp $ */
1.1 deraadt 3:
4: /*
5: * Copyright (c) 1983, 1993
6: * The Regents of the University of California. All rights reserved.
7: *
8: * Redistribution and use in source and binary forms, with or without
9: * modification, are permitted provided that the following conditions
10: * are met:
11: * 1. Redistributions of source code must retain the above copyright
12: * notice, this list of conditions and the following disclaimer.
13: * 2. Redistributions in binary form must reproduce the above copyright
14: * notice, this list of conditions and the following disclaimer in the
15: * documentation and/or other materials provided with the distribution.
16: * 3. All advertising materials mentioning features or use of this software
17: * must display the following acknowledgement:
18: * This product includes software developed by the University of
19: * California, Berkeley and its contributors.
20: * 4. Neither the name of the University nor the names of its contributors
21: * may be used to endorse or promote products derived from this software
22: * without specific prior written permission.
23: *
24: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34: * SUCH DAMAGE.
35: */
36:
37: #ifndef lint
38: #if 0
39: static char sccsid[] = "@(#)hunt.c 8.1 (Berkeley) 6/6/93";
40: #endif
1.3 ! deraadt 41: static char rcsid[] = "$OpenBSD: hunt.c,v 1.5 1995/10/29 00:49:40 pk Exp $";
1.1 deraadt 42: #endif /* not lint */
43:
44: #include "tip.h"
45:
46: extern char *getremote();
47: extern char *rindex();
48:
49: static jmp_buf deadline;
50: static int deadfl;
51:
52: void
53: dead()
54: {
55: deadfl = 1;
56: longjmp(deadline, 1);
57: }
58:
59: long
60: hunt(name)
61: char *name;
62: {
63: register char *cp;
64: sig_t f;
65:
66: f = signal(SIGALRM, dead);
67: while (cp = getremote(name)) {
68: deadfl = 0;
69: uucplock = rindex(cp, '/')+1;
70: if (uu_lock(uucplock) < 0)
71: continue;
72: /*
73: * Straight through call units, such as the BIZCOMP,
74: * VADIC and the DF, must indicate they're hardwired in
75: * order to get an open file descriptor placed in FD.
76: * Otherwise, as for a DN-11, the open will have to
77: * be done in the "open" routine.
78: */
79: if (!HW)
80: break;
81: if (setjmp(deadline) == 0) {
82: alarm(10);
83: FD = open(cp, O_RDWR);
84: }
85: alarm(0);
86: if (FD < 0) {
87: perror(cp);
88: deadfl = 1;
89: }
90: if (!deadfl) {
1.2 deraadt 91: struct termios cntrl;
92:
93: tcgetattr(FD, &cntrl);
94: cntrl.c_cflag |= HUPCL;
95: tcsetattr(FD, TCSAFLUSH, &cntrl);
1.1 deraadt 96: ioctl(FD, TIOCEXCL, 0);
97: signal(SIGALRM, SIG_DFL);
98: return ((long)cp);
99: }
100: (void)uu_unlock(uucplock);
101: }
102: signal(SIGALRM, f);
103: return (deadfl ? -1 : (long)cp);
104: }