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

Annotation of src/usr.bin/ssh/closefrom.c, Revision 1.1.2.1

1.1.2.1 ! brad        1: /*
        !             2:  * Copyright (c) 2004 Todd C. Miller <Todd.Miller@courtesan.com>
        !             3:  *
        !             4:  * Permission to use, copy, modify, and distribute this software for any
        !             5:  * purpose with or without fee is hereby granted, provided that the above
        !             6:  * copyright notice and this permission notice appear in all copies.
        !             7:  *
        !             8:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
        !             9:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
        !            10:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
        !            11:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
        !            12:  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
        !            13:  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
        !            14:  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
        !            15:  */
        !            16:
        !            17: #include "includes.h"
        !            18:
        !            19: #include <sys/types.h>
        !            20: #include <sys/param.h>
        !            21: #include <unistd.h>
        !            22: #include <stdio.h>
        !            23: #include <limits.h>
        !            24: #include <stdlib.h>
        !            25: #include <stddef.h>
        !            26: #include <dirent.h>
        !            27:
        !            28: RCSID("$Id: bsd-closefrom.c,v 1.1 2004/08/15 08:41:00 djm Exp $");
        !            29:
        !            30: #ifndef lint
        !            31: static const char sudorcsid[] = "$Sudo: closefrom.c,v 1.6 2004/06/01 20:51:56 millert Exp $";
        !            32: #endif /* lint */
        !            33:
        !            34: /*
        !            35:  * Close all file descriptors greater than or equal to lowfd.
        !            36:  */
        !            37: void
        !            38: closefrom(int lowfd)
        !            39: {
        !            40:     long fd, maxfd;
        !            41:     {
        !            42:        /*
        !            43:         * Fall back on sysconf().  We avoid checking resource limits since
        !            44:         * it is possible to open a file descriptor and then drop the rlimit
        !            45:         * such that it is below the open fd.
        !            46:         */
        !            47:        maxfd = sysconf(_SC_OPEN_MAX);
        !            48:        if (maxfd < 0)
        !            49:            maxfd = OPEN_MAX;
        !            50:
        !            51:        for (fd = lowfd; fd < maxfd; fd++)
        !            52:            (void) close((int) fd);
        !            53:     }
        !            54: }