xref: /csrg-svn/usr.bin/tip/hunt.c (revision 13138)
1 /*	hunt.c	4.6	83/06/15	*/
2 #include "tip.h"
3 #include <sys/stat.h>
4 
5 #define RD	04
6 #define EX	01
7 
8 static char *sccsid = "@(#)hunt.c	4.6 06/15/83";
9 extern char *getremote();
10 extern char *rindex();
11 
12 int deadfl;
13 
14 dead()
15 {
16 	deadfl = 1;
17 }
18 
19 hunt(name)
20 	char *name;
21 {
22 	register char *cp;
23 	char string[100];
24 	struct stat	statbuf;
25 
26 	deadfl = 0;
27 	signal(SIGALRM, dead);
28 	while (cp = getremote(name)) {
29 		uucplock = rindex(cp, '/')+1;
30 		if(strncmp(uucplock,"ttyd",4) == 0){
31 			/* reverse dialin line */
32 			if((stat(cp,&statbuf) != 0) ||
33 			((statbuf.st_mode & EX) == 0))
34 				continue;
35 			sprintf(string,"/usr/lib/uucp/disable %s",uucplock);
36 			if(system(string)) continue;
37 			sleep(5); /* insure that phone line is dropped */
38 		}
39 		if (mlock(uucplock) < 0) {
40 			delock(uucplock);
41 			continue;
42 		}
43 		/*
44 		 * Straight through call units, such as the BIZCOMP,
45 		 * VADIC and the DF, must indicate they're hardwired in
46 		 *  order to get an open file descriptor placed in FD.
47 		 * Otherwise, as for a DN-11, the open will have to
48 		 *  be done in the "open" routine.
49 		 */
50 		if (!HW)
51 			break;
52 		alarm(10);
53 		if ((FD = open(cp, 2)) >= 0){
54 			alarm(0);
55 			if (!deadfl) {
56 				ioctl(FD, TIOCEXCL, 0);
57 				ioctl(FD, TIOCHPCL, 0);
58 				signal(SIGALRM, SIG_DFL);
59 				return ((int)cp);
60 			}
61 		}
62 		alarm(0);
63 		signal(SIGALRM, dead);
64 		delock(uucplock);
65 	}
66 	signal(SIGALRM, SIG_DFL);
67 	return (deadfl ? -1 : (int)cp);
68 }
69