xref: /illumos-gate/usr/src/cmd/tip/hunt.c (revision 1e094e1b)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
37c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
47c478bd9Sstevel@tonic-gate  */
58d489c7aSmuffin 
67c478bd9Sstevel@tonic-gate /*
77c478bd9Sstevel@tonic-gate  * Copyright (c) 1983 Regents of the University of California.
87c478bd9Sstevel@tonic-gate  * All rights reserved. The Berkeley software License Agreement
97c478bd9Sstevel@tonic-gate  * specifies the terms and conditions for redistribution.
107c478bd9Sstevel@tonic-gate  */
117c478bd9Sstevel@tonic-gate 
128d489c7aSmuffin #include "tip.h"
137c478bd9Sstevel@tonic-gate 
14*1e094e1bSToomas Soome char *uucplock;
157c478bd9Sstevel@tonic-gate static	sigjmp_buf deadline;
167c478bd9Sstevel@tonic-gate static	int deadfl;
177c478bd9Sstevel@tonic-gate 
187c478bd9Sstevel@tonic-gate void
dead(void)198d489c7aSmuffin dead(void)
207c478bd9Sstevel@tonic-gate {
217c478bd9Sstevel@tonic-gate 
227c478bd9Sstevel@tonic-gate 	deadfl = 1;
237c478bd9Sstevel@tonic-gate 	siglongjmp(deadline, 1);
247c478bd9Sstevel@tonic-gate }
257c478bd9Sstevel@tonic-gate 
268d489c7aSmuffin int
hunt(char * name)278d489c7aSmuffin hunt(char *name)
287c478bd9Sstevel@tonic-gate {
298d489c7aSmuffin 	char *cp;
308d489c7aSmuffin 	sig_handler_t	f;
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate 	f = signal(SIGALRM, (sig_handler_t)dead);
337c478bd9Sstevel@tonic-gate 	while (cp = getremote(name)) {
347c478bd9Sstevel@tonic-gate 		deadfl = 0;
357c478bd9Sstevel@tonic-gate 		uucplock = cp;
368d489c7aSmuffin 		if (tip_mlock(uucplock) < 0) {
377c478bd9Sstevel@tonic-gate 			delock(uucplock);
387c478bd9Sstevel@tonic-gate 			continue;
397c478bd9Sstevel@tonic-gate 		}
407c478bd9Sstevel@tonic-gate 		/*
417c478bd9Sstevel@tonic-gate 		 * Straight through call units, such as the BIZCOMP,
427c478bd9Sstevel@tonic-gate 		 * VADIC and the DF, must indicate they're hardwired in
437c478bd9Sstevel@tonic-gate 		 *  order to get an open file descriptor placed in FD.
447c478bd9Sstevel@tonic-gate 		 * Otherwise, as for a DN-11, the open will have to
457c478bd9Sstevel@tonic-gate 		 *  be done in the "open" routine.
467c478bd9Sstevel@tonic-gate 		 */
477c478bd9Sstevel@tonic-gate 		if (!HW)
487c478bd9Sstevel@tonic-gate 			break;
497c478bd9Sstevel@tonic-gate 		if (sigsetjmp(deadline, 1) == 0) {
508d489c7aSmuffin 			(void) alarm(10);
517c478bd9Sstevel@tonic-gate 			if (!trusted_device)
527c478bd9Sstevel@tonic-gate 				userperm();
537c478bd9Sstevel@tonic-gate 			errno = 0;
547c478bd9Sstevel@tonic-gate 			if ((FD = open(cp, O_RDWR)) < 0 && errno != EBUSY) {
558d489c7aSmuffin 				(void) fprintf(stderr, "tip: ");
567c478bd9Sstevel@tonic-gate 				perror(cp);
577c478bd9Sstevel@tonic-gate 			}
587c478bd9Sstevel@tonic-gate 			if (!trusted_device)
597c478bd9Sstevel@tonic-gate 				myperm();
607c478bd9Sstevel@tonic-gate 			if (FD >= 0 && !isatty(FD)) {
618d489c7aSmuffin 				(void) fprintf(stderr, "tip: %s: not a tty\n",
628d489c7aSmuffin 				    cp);
638d489c7aSmuffin 				(void) close(FD);
647c478bd9Sstevel@tonic-gate 				FD = -1;
657c478bd9Sstevel@tonic-gate 			}
667c478bd9Sstevel@tonic-gate 		}
678d489c7aSmuffin 		(void) alarm(0);
687c478bd9Sstevel@tonic-gate 		if (!deadfl && FD >= 0) {
697c478bd9Sstevel@tonic-gate 			struct termios t;
707c478bd9Sstevel@tonic-gate 
718d489c7aSmuffin 			(void) ioctl(FD, TCGETS, &t);
727c478bd9Sstevel@tonic-gate 			t.c_cflag |= XCLUDE|HUPCL;
738d489c7aSmuffin 			(void) ioctl(FD, TCSETSF, &t);
748d489c7aSmuffin 			(void) signal(SIGALRM, f);
757c478bd9Sstevel@tonic-gate 			return ((int)cp);
767c478bd9Sstevel@tonic-gate 		}
777c478bd9Sstevel@tonic-gate 		delock(uucplock);
787c478bd9Sstevel@tonic-gate 	}
798d489c7aSmuffin 	(void) signal(SIGALRM, f);
807c478bd9Sstevel@tonic-gate 	return (deadfl ? -1 : (int)cp);
817c478bd9Sstevel@tonic-gate }
82