OpenVPN 3 Core Library
Loading...
Searching...
No Matches
logrotate.hpp
Go to the documentation of this file.
1// OpenVPN -- An application to securely tunnel IP networks
2// over a single port, with support for SSL/TLS-based
3// session authentication and key exchange,
4// packet encryption, packet authentication, and
5// packet compression.
6//
7// Copyright (C) 2012- OpenVPN Inc.
8//
9// SPDX-License-Identifier: MPL-2.0 OR AGPL-3.0-only WITH openvpn3-openssl-exception
10//
11
12#ifndef OPENVPN_COMMON_LOGROTATE_H
13#define OPENVPN_COMMON_LOGROTATE_H
14
15#include <stdio.h> // for rename()
16
18
19namespace openvpn {
20inline void log_rotate(const std::string &fn, const int max_versions)
21{
22 for (int i = max_versions - 1; i >= 0; --i)
23 {
24 std::string src;
25 if (i)
26 src = fn + '.' + to_string(i);
27 else
28 src = fn;
29 std::string dest = fn + '.' + to_string(i + 1);
30 ::rename(src.c_str(), dest.c_str());
31 }
32}
33} // namespace openvpn
34
35#endif
Support deferred server-side state creation when client connects.
Definition ovpncli.cpp:95
std::string to_string(T value)
Definition to_string.hpp:33
void log_rotate(const std::string &fn, const int max_versions)
Definition logrotate.hpp:20