Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-04-19 08:42:37

0001 // Copyright (c) 2006, 2007 Julio M. Merino Vidal
0002 // Copyright (c) 2008 Ilya Sokolov, Boris Schaeling
0003 // Copyright (c) 2009 Boris Schaeling
0004 // Copyright (c) 2010 Felipe Tanus, Boris Schaeling
0005 // Copyright (c) 2011, 2012 Jeff Flinn, Boris Schaeling
0006 //
0007 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0008 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0009 
0010 #ifndef BOOST_PROCESS_WINDOWS_CHILD_HPP
0011 #define BOOST_PROCESS_WINDOWS_CHILD_HPP
0012 
0013 #include <boost/process/v1/detail/config.hpp>
0014 #include <boost/move/move.hpp>
0015 #include <boost/winapi/handles.hpp>
0016 #include <boost/winapi/process.hpp>
0017 #include <boost/winapi/jobs.hpp>
0018 
0019 namespace boost { namespace process { BOOST_PROCESS_V1_INLINE namespace v1 { namespace detail { namespace windows {
0020 
0021 typedef ::boost::winapi::DWORD_ pid_t;
0022 
0023 struct child_handle
0024 {
0025     ::boost::winapi::PROCESS_INFORMATION_ proc_info{nullptr, nullptr, 0,0};
0026 
0027     explicit child_handle(const ::boost::winapi::PROCESS_INFORMATION_ &pi) :
0028                                   proc_info(pi)
0029     {}
0030 
0031     explicit child_handle(pid_t pid) :
0032                                   proc_info{nullptr, nullptr, 0,0}
0033     {
0034         auto h = ::boost::winapi::OpenProcess(
0035                 ::boost::winapi::PROCESS_ALL_ACCESS_,
0036                 static_cast<::boost::winapi::BOOL_>(0),
0037                  pid);
0038 
0039         if (h == nullptr)
0040             throw_last_error("OpenProcess() failed");
0041         proc_info.hProcess = h;
0042         proc_info.dwProcessId = pid;
0043     }
0044 
0045     child_handle() = default;
0046     ~child_handle()
0047     {
0048         ::boost::winapi::CloseHandle(proc_info.hProcess);
0049         ::boost::winapi::CloseHandle(proc_info.hThread);
0050     }
0051     child_handle(const child_handle & c) = delete;
0052     child_handle(child_handle && c) : proc_info(c.proc_info)
0053     {
0054         c.proc_info.hProcess = ::boost::winapi::invalid_handle_value;
0055         c.proc_info.hThread  = ::boost::winapi::invalid_handle_value;
0056     }
0057     child_handle &operator=(const child_handle & c) = delete;
0058     child_handle &operator=(child_handle && c)
0059     {
0060         ::boost::winapi::CloseHandle(proc_info.hProcess);
0061         ::boost::winapi::CloseHandle(proc_info.hThread);
0062         proc_info = c.proc_info;
0063         c.proc_info.hProcess = ::boost::winapi::invalid_handle_value;
0064         c.proc_info.hThread  = ::boost::winapi::invalid_handle_value;
0065         return *this;
0066     }
0067 
0068     pid_t id() const
0069     {
0070         return static_cast<pid_t>(proc_info.dwProcessId);
0071     }
0072 
0073     typedef ::boost::winapi::HANDLE_ process_handle_t;
0074     process_handle_t process_handle() const { return proc_info.hProcess; }
0075 
0076     bool valid() const
0077     {
0078         return (proc_info.hProcess != nullptr) &&
0079                (proc_info.hProcess != ::boost::winapi::INVALID_HANDLE_VALUE_);
0080     }
0081     bool in_group() const
0082     {
0083         ::boost::winapi::BOOL_ value;
0084         if (!::boost::winapi::IsProcessInJob(proc_info.hProcess, nullptr, &value))
0085             throw_last_error("IsProcessInJob Failed");
0086         return value!=0;
0087     }
0088     bool in_group(std::error_code &ec) const noexcept
0089     {
0090         ::boost::winapi::BOOL_ value;
0091         if (!::boost::winapi::IsProcessInJob(proc_info.hProcess, nullptr, &value))
0092             ec = get_last_error();
0093         return value!=0;
0094     }
0095 };
0096 
0097 }}}}}
0098 
0099 #endif