Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:50:07

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/move/move.hpp>
0014 #include <boost/winapi/handles.hpp>
0015 #include <boost/winapi/process.hpp>
0016 #include <boost/winapi/jobs.hpp>
0017 
0018 namespace boost { namespace process { namespace detail { namespace windows {
0019 
0020 typedef ::boost::winapi::DWORD_ pid_t;
0021 
0022 struct child_handle
0023 {
0024     ::boost::winapi::PROCESS_INFORMATION_ proc_info{nullptr, nullptr, 0,0};
0025 
0026     explicit child_handle(const ::boost::winapi::PROCESS_INFORMATION_ &pi) :
0027                                   proc_info(pi)
0028     {}
0029 
0030     explicit child_handle(pid_t pid) :
0031                                   proc_info{nullptr, nullptr, 0,0}
0032     {
0033         auto h = ::boost::winapi::OpenProcess(
0034                 ::boost::winapi::PROCESS_ALL_ACCESS_,
0035                 static_cast<::boost::winapi::BOOL_>(0),
0036                  pid);
0037 
0038         if (h == nullptr)
0039             throw_last_error("OpenProcess() failed");
0040         proc_info.hProcess = h;
0041         proc_info.dwProcessId = pid;
0042     }
0043 
0044     child_handle() = default;
0045     ~child_handle()
0046     {
0047         ::boost::winapi::CloseHandle(proc_info.hProcess);
0048         ::boost::winapi::CloseHandle(proc_info.hThread);
0049     }
0050     child_handle(const child_handle & c) = delete;
0051     child_handle(child_handle && c) : proc_info(c.proc_info)
0052     {
0053         c.proc_info.hProcess = ::boost::winapi::invalid_handle_value;
0054         c.proc_info.hThread  = ::boost::winapi::invalid_handle_value;
0055     }
0056     child_handle &operator=(const child_handle & c) = delete;
0057     child_handle &operator=(child_handle && c)
0058     {
0059         ::boost::winapi::CloseHandle(proc_info.hProcess);
0060         ::boost::winapi::CloseHandle(proc_info.hThread);
0061         proc_info = c.proc_info;
0062         c.proc_info.hProcess = ::boost::winapi::invalid_handle_value;
0063         c.proc_info.hThread  = ::boost::winapi::invalid_handle_value;
0064         return *this;
0065     }
0066 
0067     pid_t id() const
0068     {
0069         return static_cast<pid_t>(proc_info.dwProcessId);
0070     }
0071 
0072     typedef ::boost::winapi::HANDLE_ process_handle_t;
0073     process_handle_t process_handle() const { return proc_info.hProcess; }
0074 
0075     bool valid() const
0076     {
0077         return (proc_info.hProcess != nullptr) &&
0078                (proc_info.hProcess != ::boost::winapi::INVALID_HANDLE_VALUE_);
0079     }
0080     bool in_group() const
0081     {
0082         ::boost::winapi::BOOL_ value;
0083         if (!::boost::winapi::IsProcessInJob(proc_info.hProcess, nullptr, &value))
0084             throw_last_error("IsProcessInJob Failed");
0085         return value!=0;
0086     }
0087     bool in_group(std::error_code &ec) const noexcept
0088     {
0089         ::boost::winapi::BOOL_ value;
0090         if (!::boost::winapi::IsProcessInJob(proc_info.hProcess, nullptr, &value))
0091             ec = get_last_error();
0092         return value!=0;
0093     }
0094 };
0095 
0096 }}}}
0097 
0098 #endif