10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
30Sstevel@tonic-gate * Use is subject to license terms.
40Sstevel@tonic-gate */
5*549Smuffin
60Sstevel@tonic-gate /*
70Sstevel@tonic-gate * Copyright (c) 1983 Regents of the University of California.
80Sstevel@tonic-gate * All rights reserved. The Berkeley software License Agreement
90Sstevel@tonic-gate * specifies the terms and conditions for redistribution.
100Sstevel@tonic-gate */
11*549Smuffin
12*549Smuffin #pragma ident "%Z%%M% %I% %E% SMI"
130Sstevel@tonic-gate
140Sstevel@tonic-gate #include "tip.h"
150Sstevel@tonic-gate
160Sstevel@tonic-gate static sigjmp_buf deadline;
170Sstevel@tonic-gate static int deadfl;
180Sstevel@tonic-gate
190Sstevel@tonic-gate void
dead(void)20*549Smuffin dead(void)
210Sstevel@tonic-gate {
220Sstevel@tonic-gate
230Sstevel@tonic-gate deadfl = 1;
240Sstevel@tonic-gate siglongjmp(deadline, 1);
250Sstevel@tonic-gate }
260Sstevel@tonic-gate
27*549Smuffin int
hunt(char * name)28*549Smuffin hunt(char *name)
290Sstevel@tonic-gate {
30*549Smuffin char *cp;
31*549Smuffin sig_handler_t f;
320Sstevel@tonic-gate
330Sstevel@tonic-gate f = signal(SIGALRM, (sig_handler_t)dead);
340Sstevel@tonic-gate while (cp = getremote(name)) {
350Sstevel@tonic-gate deadfl = 0;
360Sstevel@tonic-gate uucplock = cp;
37*549Smuffin if (tip_mlock(uucplock) < 0) {
380Sstevel@tonic-gate delock(uucplock);
390Sstevel@tonic-gate continue;
400Sstevel@tonic-gate }
410Sstevel@tonic-gate /*
420Sstevel@tonic-gate * Straight through call units, such as the BIZCOMP,
430Sstevel@tonic-gate * VADIC and the DF, must indicate they're hardwired in
440Sstevel@tonic-gate * order to get an open file descriptor placed in FD.
450Sstevel@tonic-gate * Otherwise, as for a DN-11, the open will have to
460Sstevel@tonic-gate * be done in the "open" routine.
470Sstevel@tonic-gate */
480Sstevel@tonic-gate if (!HW)
490Sstevel@tonic-gate break;
500Sstevel@tonic-gate if (sigsetjmp(deadline, 1) == 0) {
51*549Smuffin (void) alarm(10);
520Sstevel@tonic-gate if (!trusted_device)
530Sstevel@tonic-gate userperm();
540Sstevel@tonic-gate errno = 0;
550Sstevel@tonic-gate if ((FD = open(cp, O_RDWR)) < 0 && errno != EBUSY) {
56*549Smuffin (void) fprintf(stderr, "tip: ");
570Sstevel@tonic-gate perror(cp);
580Sstevel@tonic-gate }
590Sstevel@tonic-gate if (!trusted_device)
600Sstevel@tonic-gate myperm();
610Sstevel@tonic-gate if (FD >= 0 && !isatty(FD)) {
62*549Smuffin (void) fprintf(stderr, "tip: %s: not a tty\n",
63*549Smuffin cp);
64*549Smuffin (void) close(FD);
650Sstevel@tonic-gate FD = -1;
660Sstevel@tonic-gate }
670Sstevel@tonic-gate }
68*549Smuffin (void) alarm(0);
690Sstevel@tonic-gate if (!deadfl && FD >= 0) {
700Sstevel@tonic-gate struct termios t;
710Sstevel@tonic-gate
72*549Smuffin (void) ioctl(FD, TCGETS, &t);
730Sstevel@tonic-gate t.c_cflag |= XCLUDE|HUPCL;
74*549Smuffin (void) ioctl(FD, TCSETSF, &t);
75*549Smuffin (void) signal(SIGALRM, f);
760Sstevel@tonic-gate return ((int)cp);
770Sstevel@tonic-gate }
780Sstevel@tonic-gate delock(uucplock);
790Sstevel@tonic-gate }
80*549Smuffin (void) signal(SIGALRM, f);
810Sstevel@tonic-gate return (deadfl ? -1 : (int)cp);
820Sstevel@tonic-gate }
83