Skip to content

[package] boost/1.81.0: Apply patch to prevent deadlock in boost::log #17515

Open
@christapley

Description

@christapley

Description

I would like to submit a patch for boost in order to address boostorg/log#209 in conan's 1.81 recipe.

Package and Environment Details

  • Package Name/Version: boost/1.81.0
  • Operating System+version: Linux RHEL7
  • Compiler+version: GCC 12
  • Conan version: conan 1.59.0
  • Python version: Python 3.7.6

Conan profile

GCC_PATH=/opt/rh/devtoolset-12/root/usr/bin/

[settings]
os=Linux
arch=x86_64
compiler=gcc
compiler.version=12
compiler.libcxx=libstdc++11
build_type=RelWithDebInfo

[env]
PATH=[/opt/rh/devtoolset-12/root/usr/bin/:/opt/cmake-3.25.2/bin]

Steps to reproduce

Wasn't able to upload the sample sorry.

conanfile.py:

from conans import ConanFile, CMake


class BoostLogBugConan(ConanFile):
    name = "boost_log_bug"
    version = "1.0.0"
    license = "<Put the package license here>"
    author = "<Put your name here> <And your email here>"
    url = "<Package recipe repository url here, for issues about the package>"
    description = "<Description of BoostLogBug here>"
    topics = ("<Put some tag here>", "<here>", "<and here>")
    settings = "os", "compiler", "build_type", "arch"
    options = {"shared": [True, False], "fPIC": [True, False]}
    default_options = {"shared": False, "fPIC": True}
    generators = "cmake"
    exports_sources = "src/*"

    def requirements(self):
        self.requires('boost/1.81.0@')

    def config_options(self):
        if self.settings.os == "Windows":
            del self.options.fPIC

    def build(self):
        cmake = CMake(self)
        cmake.configure(source_folder="src")
        cmake.build()

        # Explicit way:
        # self.run('cmake %s/hello %s'
        #          % (self.source_folder, cmake.command_line))
        # self.run("cmake --build . %s" % cmake.build_config)

    def package(self):
        self.copy("*.h", dst="include", src="src")
        self.copy("*.lib", dst="lib", keep_path=False)
        self.copy("*.dll", dst="bin", keep_path=False)
        self.copy("*.dylib*", dst="lib", keep_path=False)
        self.copy("*.so", dst="lib", keep_path=False)
        self.copy("*.a", dst="lib", keep_path=False)

    def package_info(self):
        self.cpp_info.libs = ["boost_log_bug"]

src/CMakeLists.txt:

cmake_minimum_required(VERSION 3.1)
project(boost_log_bug CXX)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

find_package(Boost REQUIRED COMPONENTS log)

add_executable(boost_log_bug boost_log_bug.cpp)

target_link_libraries( boost_log_bug Boost::log )

src/boost_log_bug.cpp:

#include <vector>

#include <boost/log/core.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
#include <boost/log/utility/setup/file.hpp>

namespace logging = boost::log;
namespace keywords = boost::log::keywords;

void init_logging()
{
    logging::register_simple_formatter_factory<logging::trivial::severity_level, char>("Severity");

    auto file = logging::add_file_log(
        keywords::file_name        = "sample_%N.log",    //
        keywords::target           = "./",               //
        keywords::target_file_name = "sample_%N.log",    //
        keywords::open_mode        = std::ios_base::app, //
        keywords::auto_flush       = true,               //
        keywords::rotation_size    = 500*1024,           //
        keywords::max_size         = 6*1024*1024,        //
        keywords::max_files        = 6,
        keywords::format =
            "%LineID%. [%TimeStamp%][%ThreadID%] [%Severity%] - %Message%");

    file->locked_backend()->scan_for_files();

    logging::core::get()->set_filter(logging::trivial::severity >= logging::trivial::info);

    logging::add_common_attributes();
}

int main()
{
    init_logging();

    std::vector<char> value(static_cast<size_t>(1024*1024), 'a');
    value.push_back('\0');

    BOOST_LOG_TRIVIAL(info) << value.data();
    BOOST_LOG_TRIVIAL(info) << value.data();
    BOOST_LOG_TRIVIAL(info) << value.data();
    BOOST_LOG_TRIVIAL(info) << value.data();

}

build binary and run it and it will sit in an infinite loop creating empty log files.

Logs

N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions