[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.16

1.16    ! nicm        1: /*     $OpenBSD: hunt.c,v 1.15 2010/06/29 17:42:35 nicm 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:
1.16    ! nicm       33: #include <util.h>
        !            34:
1.1       deraadt    35: #include "tip.h"
                     36:
                     37: static jmp_buf deadline;
                     38: static int deadfl;
                     39:
1.12      moritz     40: static void    dead(int);
                     41:
1.13      deraadt    42: /*ARGSUSED*/
1.12      moritz     43: static void
1.11      deraadt    44: dead(int signo)
1.1       deraadt    45: {
                     46:        deadfl = 1;
                     47:        longjmp(deadline, 1);
                     48: }
                     49:
                     50: long
1.11      deraadt    51: hunt(char *name)
1.1       deraadt    52: {
1.8       millert    53:        char *cp;
1.1       deraadt    54:        sig_t f;
                     55:
                     56:        f = signal(SIGALRM, dead);
1.6       deraadt    57:        while ((cp = getremote(name))) {
1.1       deraadt    58:                deadfl = 0;
1.7       deraadt    59:                uucplock = strrchr(cp, '/');
                     60:                if (uucplock == NULL)
                     61:                        uucplock = cp;
                     62:                else
                     63:                        uucplock++;
1.16    ! nicm       64:                if (uu_lock(uucplock) != UU_LOCK_OK)
1.1       deraadt    65:                        continue;
1.15      nicm       66:
1.1       deraadt    67:                if (setjmp(deadline) == 0) {
                     68:                        alarm(10);
1.5       millert    69:                        FD = open(cp, (O_RDWR |
1.11      deraadt    70:                            (boolean(value(DC)) ? O_NONBLOCK : 0)));
1.1       deraadt    71:                }
                     72:                alarm(0);
                     73:                if (FD < 0) {
                     74:                        perror(cp);
                     75:                        deadfl = 1;
                     76:                }
                     77:                if (!deadfl) {
1.2       deraadt    78:                        struct termios cntrl;
                     79:
                     80:                        tcgetattr(FD, &cntrl);
1.5       millert    81:                        if (!boolean(value(DC)))
                     82:                                cntrl.c_cflag |= HUPCL;
1.2       deraadt    83:                        tcsetattr(FD, TCSAFLUSH, &cntrl);
1.1       deraadt    84:                        ioctl(FD, TIOCEXCL, 0);
                     85:                        signal(SIGALRM, SIG_DFL);
                     86:                        return ((long)cp);
                     87:                }
1.15      nicm       88:
1.1       deraadt    89:                (void)uu_unlock(uucplock);
                     90:        }
                     91:        signal(SIGALRM, f);
                     92:        return (deadfl ? -1 : (long)cp);
                     93: }