xref: /titanic_52/usr/src/cmd/tip/hunt.c (revision 843e19887f64dde75055cf8842fc4db2171eff45)
1 /*
2  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 /*
7  * Copyright (c) 1983 Regents of the University of California.
8  * All rights reserved. The Berkeley software License Agreement
9  * specifies the terms and conditions for redistribution.
10  */
11 
12 #pragma ident	"%Z%%M%	%I%	%E% SMI"
13 
14 #include "tip.h"
15 
16 static	sigjmp_buf deadline;
17 static	int deadfl;
18 
19 void
20 dead(void)
21 {
22 
23 	deadfl = 1;
24 	siglongjmp(deadline, 1);
25 }
26 
27 int
28 hunt(char *name)
29 {
30 	char *cp;
31 	sig_handler_t	f;
32 
33 	f = signal(SIGALRM, (sig_handler_t)dead);
34 	while (cp = getremote(name)) {
35 		deadfl = 0;
36 		uucplock = cp;
37 		if (tip_mlock(uucplock) < 0) {
38 			delock(uucplock);
39 			continue;
40 		}
41 		/*
42 		 * Straight through call units, such as the BIZCOMP,
43 		 * VADIC and the DF, must indicate they're hardwired in
44 		 *  order to get an open file descriptor placed in FD.
45 		 * Otherwise, as for a DN-11, the open will have to
46 		 *  be done in the "open" routine.
47 		 */
48 		if (!HW)
49 			break;
50 		if (sigsetjmp(deadline, 1) == 0) {
51 			(void) alarm(10);
52 			if (!trusted_device)
53 				userperm();
54 			errno = 0;
55 			if ((FD = open(cp, O_RDWR)) < 0 && errno != EBUSY) {
56 				(void) fprintf(stderr, "tip: ");
57 				perror(cp);
58 			}
59 			if (!trusted_device)
60 				myperm();
61 			if (FD >= 0 && !isatty(FD)) {
62 				(void) fprintf(stderr, "tip: %s: not a tty\n",
63 				    cp);
64 				(void) close(FD);
65 				FD = -1;
66 			}
67 		}
68 		(void) alarm(0);
69 		if (!deadfl && FD >= 0) {
70 			struct termios t;
71 
72 			(void) ioctl(FD, TCGETS, &t);
73 			t.c_cflag |= XCLUDE|HUPCL;
74 			(void) ioctl(FD, TCSETSF, &t);
75 			(void) signal(SIGALRM, f);
76 			return ((int)cp);
77 		}
78 		delock(uucplock);
79 	}
80 	(void) signal(SIGALRM, f);
81 	return (deadfl ? -1 : (int)cp);
82 }
83