aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib/src/vespa/vespalib/process/close_all_files.cpp
blob: 5cf20af58bac2bbf08cc272f92afd071fe606928 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "close_all_files.h"
#include <unistd.h>

namespace vespalib {

// this is what we want to do, when possible:
// 
// close_range(3, ~0U, CLOSE_RANGE_UNSHARE);

void close_all_files() {
    int fd_limit = sysconf(_SC_OPEN_MAX);
    for (int fd = STDERR_FILENO + 1; fd < fd_limit; ++fd) {
        close(fd);
    }
}

} // namespace vespalib