~siborgium/prelockdpp

1555ef89cd334f095815a154832be8511cf1d3eb — Sergey Smirnykh 2 years ago 4d2f50a
clarify certain ctx fields
1 files changed, 16 insertions(+), 3 deletions(-)

M main.cpp
M main.cpp => main.cpp +16 -3
@@ 142,23 142,36 @@ struct context {
    sc_info  info;
    config&  cfg;

    // now the tricky part
    // path_buf is used to store path
    // while paths, theoretically, can be very large,
    // we only need to store '/proc/PID/FILENAME,
    // where FILENAME is either stat, cgroup or maps
    // and PID is valid pid
    // pid is represented using `int` type,
    // so PID won't grow larger than length of decimal INT_MAX
    constexpr static auto path_buffer_size
        = proc_path.size()
        + std::numeric_limits<int>::digits10
        + std::max({ stat_path.size(), cgroup_path.size(), maps_path.size() })
        + 2;
    char path_buf[path_buffer_size];
    // these are used to mark where PID begins and ends
    // so that one could easily replace certain part of path
    char* const pid_begin;
    char*       pid_end;

    // buffers used to avoid re-allocating the same space
    std::string                     stat_buffer;
    std::string                     cgroup_buffer;

    // names (comms, actually, see comm in proc(5), /proc/[pid]/stat) of
    // programs we should lock
    std::unordered_set<std::string> name_set;

    void mlockall() {
        if (auto err = ::mlockall(MCL_FUTURE)) {
            int errno_ = errno;
            throw std::runtime_error{ concat("mlockall failed ", errno_) };
        if (::mlockall(MCL_FUTURE)) {
            throw std::runtime_error{ concat("mlockall failed ", errno) };
        }
    }
    auto get_clock_time(clockid_t id) {