[BACK]Return to hunt.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / tip

Annotation of src/usr.bin/tip/hunt.c, Revision 1.15

1.15    ! nicm        1: /*     $OpenBSD: hunt.c,v 1.14 2009/10/27 23:59:44 deraadt Exp $       */
1.5       millert     2: /*     $NetBSD: hunt.c,v 1.6 1997/04/20 00:02:10 mellon Exp $  */
1.1       deraadt     3:
                      4: /*
                      5:  * Copyright (c) 1983, 1993
                      6:  *     The Regents of the University of California.  All rights reserved.
                      7:  *
                      8:  * Redistribution and use in source and binary forms, with or without
                      9:  * modification, are permitted provided that the following conditions
                     10:  * are met:
                     11:  * 1. Redistributions of source code must retain the above copyright
                     12:  *    notice, this list of conditions and the following disclaimer.
                     13:  * 2. Redistributions in binary form must reproduce the above copyright
                     14:  *    notice, this list of conditions and the following disclaimer in the
                     15:  *    documentation and/or other materials provided with the distribution.
1.10      millert    16:  * 3. Neither the name of the University nor the names of its contributors
1.1       deraadt    17:  *    may be used to endorse or promote products derived from this software
                     18:  *    without specific prior written permission.
                     19:  *
                     20:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     21:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     22:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     23:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     24:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     25:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     26:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     27:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     28:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     29:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     30:  * SUCH DAMAGE.
                     31:  */
                     32:
                     33: #include "tip.h"
                     34:
                     35: static jmp_buf deadline;
                     36: static int deadfl;
                     37:
1.12      moritz     38: static void    dead(int);
                     39:
1.13      deraadt    40: /*ARGSUSED*/
1.12      moritz     41: static void
1.11      deraadt    42: dead(int signo)
1.1       deraadt    43: {
                     44:        deadfl = 1;
                     45:        longjmp(deadline, 1);
                     46: }
                     47:
                     48: long
1.11      deraadt    49: hunt(char *name)
1.1       deraadt    50: {
1.8       millert    51:        char *cp;
1.1       deraadt    52:        sig_t f;
                     53:
                     54:        f = signal(SIGALRM, dead);
1.6       deraadt    55:        while ((cp = getremote(name))) {
1.1       deraadt    56:                deadfl = 0;
1.7       deraadt    57:                uucplock = strrchr(cp, '/');
                     58:                if (uucplock == NULL)
                     59:                        uucplock = cp;
                     60:                else
                     61:                        uucplock++;
1.1       deraadt    62:                if (uu_lock(uucplock) < 0)
                     63:                        continue;
1.15    ! nicm       64:
1.1       deraadt    65:                if (setjmp(deadline) == 0) {
                     66:                        alarm(10);
1.5       millert    67:                        FD = open(cp, (O_RDWR |
1.11      deraadt    68:                            (boolean(value(DC)) ? O_NONBLOCK : 0)));
1.1       deraadt    69:                }
                     70:                alarm(0);
                     71:                if (FD < 0) {
                     72:                        perror(cp);
                     73:                        deadfl = 1;
                     74:                }
                     75:                if (!deadfl) {
1.2       deraadt    76:                        struct termios cntrl;
                     77:
                     78:                        tcgetattr(FD, &cntrl);
1.5       millert    79:                        if (!boolean(value(DC)))
                     80:                                cntrl.c_cflag |= HUPCL;
1.2       deraadt    81:                        tcsetattr(FD, TCSAFLUSH, &cntrl);
1.1       deraadt    82:                        ioctl(FD, TIOCEXCL, 0);
                     83:                        signal(SIGALRM, SIG_DFL);
                     84:                        return ((long)cp);
                     85:                }
1.15    ! nicm       86:
1.1       deraadt    87:                (void)uu_unlock(uucplock);
                     88:        }
                     89:        signal(SIGALRM, f);
                     90:        return (deadfl ? -1 : (long)cp);
                     91: }