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 */
5*8d489c7aSmuffin
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 */
11*8d489c7aSmuffin
12*8d489c7aSmuffin #pragma ident "%Z%%M% %I% %E% SMI"
137c478bd9Sstevel@tonic-gate
147c478bd9Sstevel@tonic-gate #include "tip.h"
157c478bd9Sstevel@tonic-gate
167c478bd9Sstevel@tonic-gate static sigjmp_buf deadline;
177c478bd9Sstevel@tonic-gate static int deadfl;
187c478bd9Sstevel@tonic-gate
197c478bd9Sstevel@tonic-gate void
dead(void)20*8d489c7aSmuffin dead(void)
217c478bd9Sstevel@tonic-gate {
227c478bd9Sstevel@tonic-gate
237c478bd9Sstevel@tonic-gate deadfl = 1;
247c478bd9Sstevel@tonic-gate siglongjmp(deadline, 1);
257c478bd9Sstevel@tonic-gate }
267c478bd9Sstevel@tonic-gate
27*8d489c7aSmuffin int
hunt(char * name)28*8d489c7aSmuffin hunt(char *name)
297c478bd9Sstevel@tonic-gate {
30*8d489c7aSmuffin char *cp;
31*8d489c7aSmuffin sig_handler_t f;
327c478bd9Sstevel@tonic-gate
337c478bd9Sstevel@tonic-gate f = signal(SIGALRM, (sig_handler_t)dead);
347c478bd9Sstevel@tonic-gate while (cp = getremote(name)) {
357c478bd9Sstevel@tonic-gate deadfl = 0;
367c478bd9Sstevel@tonic-gate uucplock = cp;
37*8d489c7aSmuffin if (tip_mlock(uucplock) < 0) {
387c478bd9Sstevel@tonic-gate delock(uucplock);
397c478bd9Sstevel@tonic-gate continue;
407c478bd9Sstevel@tonic-gate }
417c478bd9Sstevel@tonic-gate /*
427c478bd9Sstevel@tonic-gate * Straight through call units, such as the BIZCOMP,
437c478bd9Sstevel@tonic-gate * VADIC and the DF, must indicate they're hardwired in
447c478bd9Sstevel@tonic-gate * order to get an open file descriptor placed in FD.
457c478bd9Sstevel@tonic-gate * Otherwise, as for a DN-11, the open will have to
467c478bd9Sstevel@tonic-gate * be done in the "open" routine.
477c478bd9Sstevel@tonic-gate */
487c478bd9Sstevel@tonic-gate if (!HW)
497c478bd9Sstevel@tonic-gate break;
507c478bd9Sstevel@tonic-gate if (sigsetjmp(deadline, 1) == 0) {
51*8d489c7aSmuffin (void) alarm(10);
527c478bd9Sstevel@tonic-gate if (!trusted_device)
537c478bd9Sstevel@tonic-gate userperm();
547c478bd9Sstevel@tonic-gate errno = 0;
557c478bd9Sstevel@tonic-gate if ((FD = open(cp, O_RDWR)) < 0 && errno != EBUSY) {
56*8d489c7aSmuffin (void) fprintf(stderr, "tip: ");
577c478bd9Sstevel@tonic-gate perror(cp);
587c478bd9Sstevel@tonic-gate }
597c478bd9Sstevel@tonic-gate if (!trusted_device)
607c478bd9Sstevel@tonic-gate myperm();
617c478bd9Sstevel@tonic-gate if (FD >= 0 && !isatty(FD)) {
62*8d489c7aSmuffin (void) fprintf(stderr, "tip: %s: not a tty\n",
63*8d489c7aSmuffin cp);
64*8d489c7aSmuffin (void) close(FD);
657c478bd9Sstevel@tonic-gate FD = -1;
667c478bd9Sstevel@tonic-gate }
677c478bd9Sstevel@tonic-gate }
68*8d489c7aSmuffin (void) alarm(0);
697c478bd9Sstevel@tonic-gate if (!deadfl && FD >= 0) {
707c478bd9Sstevel@tonic-gate struct termios t;
717c478bd9Sstevel@tonic-gate
72*8d489c7aSmuffin (void) ioctl(FD, TCGETS, &t);
737c478bd9Sstevel@tonic-gate t.c_cflag |= XCLUDE|HUPCL;
74*8d489c7aSmuffin (void) ioctl(FD, TCSETSF, &t);
75*8d489c7aSmuffin (void) signal(SIGALRM, f);
767c478bd9Sstevel@tonic-gate return ((int)cp);
777c478bd9Sstevel@tonic-gate }
787c478bd9Sstevel@tonic-gate delock(uucplock);
797c478bd9Sstevel@tonic-gate }
80*8d489c7aSmuffin (void) signal(SIGALRM, f);
817c478bd9Sstevel@tonic-gate return (deadfl ? -1 : (int)cp);
827c478bd9Sstevel@tonic-gate }
83