diff options
Diffstat (limited to 'boost/process/detail/windows')
-rw-r--r-- | boost/process/detail/windows/basic_cmd.hpp | 9 | ||||
-rw-r--r-- | boost/process/detail/windows/basic_pipe.hpp | 2 | ||||
-rw-r--r-- | boost/process/detail/windows/child_handle.hpp | 2 | ||||
-rw-r--r-- | boost/process/detail/windows/environment.hpp | 12 | ||||
-rw-r--r-- | boost/process/detail/windows/file_descriptor.hpp | 5 | ||||
-rw-r--r-- | boost/process/detail/windows/handle_workaround.hpp | 10 | ||||
-rw-r--r-- | boost/process/detail/windows/handles.hpp | 6 | ||||
-rw-r--r-- | boost/process/detail/windows/io_context_ref.hpp | 16 | ||||
-rw-r--r-- | boost/process/detail/windows/is_running.hpp | 3 | ||||
-rw-r--r-- | boost/process/detail/windows/on_exit.hpp | 15 | ||||
-rw-r--r-- | boost/process/detail/windows/pipe_in.hpp | 2 | ||||
-rw-r--r-- | boost/process/detail/windows/pipe_out.hpp | 4 | ||||
-rw-r--r-- | boost/process/detail/windows/search_path.hpp | 25 | ||||
-rw-r--r-- | boost/process/detail/windows/shell_path.hpp | 10 |
14 files changed, 80 insertions, 41 deletions
diff --git a/boost/process/detail/windows/basic_cmd.hpp b/boost/process/detail/windows/basic_cmd.hpp index 53ea9931d1..656c89b70f 100644 --- a/boost/process/detail/windows/basic_cmd.hpp +++ b/boost/process/detail/windows/basic_cmd.hpp @@ -62,7 +62,7 @@ inline std::string build_args(const std::string & exe, std::vector<std::string> } } - if (!st.empty())//first one does not need a preceeding space + if (!st.empty())//first one does not need a preceding space st += ' '; st += arg; @@ -106,7 +106,7 @@ inline std::wstring build_args(const std::wstring & exe, std::vector<std::wstrin } } - if (!st.empty())//first one does not need a preceeding space + if (!st.empty())//first one does not need a preceding space st += L' '; st += arg; @@ -159,8 +159,13 @@ struct exe_cmd_init : handler_base_ext return exe_cmd_init<Char>(std::move(sh), std::move(args_)); } +#ifdef BOOST_PROCESS_USE_STD_FS + static std:: string get_shell(char) {return shell(). string(); } + static std::wstring get_shell(wchar_t) {return shell().wstring(); } +#else static std:: string get_shell(char) {return shell(). string(codecvt()); } static std::wstring get_shell(wchar_t) {return shell().wstring(codecvt());} +#endif static exe_cmd_init<Char> cmd_shell(string_type&& cmd) { diff --git a/boost/process/detail/windows/basic_pipe.hpp b/boost/process/detail/windows/basic_pipe.hpp index 3cf9044747..0fe524d216 100644 --- a/boost/process/detail/windows/basic_pipe.hpp +++ b/boost/process/detail/windows/basic_pipe.hpp @@ -158,7 +158,7 @@ basic_pipe<Char, Traits>::basic_pipe(const std::string & name) ::boost::process::detail::throw_last_error("create_named_pipe() failed"); ::boost::winapi::HANDLE_ sink = boost::winapi::create_file( - name.c_str(), + name_.c_str(), ::boost::winapi::GENERIC_WRITE_, 0, nullptr, OPEN_EXISTING_, FILE_FLAG_OVERLAPPED_, //to allow read diff --git a/boost/process/detail/windows/child_handle.hpp b/boost/process/detail/windows/child_handle.hpp index d14c931e43..b7f46db916 100644 --- a/boost/process/detail/windows/child_handle.hpp +++ b/boost/process/detail/windows/child_handle.hpp @@ -81,7 +81,7 @@ struct child_handle { ::boost::winapi::BOOL_ value; if (!::boost::winapi::IsProcessInJob(proc_info.hProcess, nullptr, &value)) - throw_last_error("IsProcessinJob Failed"); + throw_last_error("IsProcessInJob Failed"); return value!=0; } bool in_group(std::error_code &ec) const noexcept diff --git a/boost/process/detail/windows/environment.hpp b/boost/process/detail/windows/environment.hpp index 13aa587da8..4215579856 100644 --- a/boost/process/detail/windows/environment.hpp +++ b/boost/process/detail/windows/environment.hpp @@ -73,8 +73,8 @@ inline auto native_environment_impl<Char>::get(const pointer_type id) -> string_ if (size == sizeof(buf)) //the return size gives the size without the null, so I know this went wrong { - /*limit defined here https://msdn.microsoft.com/en-us/library/windows/desktop/ms683188(v=vs.85).aspx - * but I used 32768 so it is a multiple of 4096. + /* limit defined here https://msdn.microsoft.com/en-us/library/windows/desktop/ms683188(v=vs.85).aspx + * but I used 32768, so it is a multiple of 4096. */ constexpr static std::size_t max_size = 32768; //Handle variables longer then buf. @@ -90,12 +90,12 @@ inline auto native_environment_impl<Char>::get(const pointer_type id) -> string_ ::boost::process::detail::throw_last_error("GetEnvironmentVariable() failed"); else return std::basic_string<Char>( - buf.data(), buf.data()+ size + 1); + buf.data(), buf.data()+ size); } } - return std::basic_string<Char>(buf, buf+size+1); + return std::basic_string<Char>(buf, buf+size); } template<typename Char> @@ -232,6 +232,8 @@ basic_environment_impl<Char>::basic_environment_impl(const native_environment_im template<typename Char> inline auto basic_environment_impl<Char>::get(const string_type &id) -> string_type { + if (id.size() >= _data.size()) //ok, so it is impossible id is in there. + return string_type(_data.data()); if (std::equal(id.begin(), id.end(), _data.begin()) && (_data[id.size()] == equal_sign<Char>())) return string_type(_data.data()); //null-char is handled by the string. @@ -271,7 +273,7 @@ template<typename Char> inline void basic_environment_impl<Char>::reset(const string_type &id) { //ok, we need to check the size of data first - if (id.size() >= _data.size()) //ok, so it's impossible id is in there. + if (id.size() >= _data.size()) //ok, so it is impossible id is in there. return; //check if it's the first one, spares us the search. diff --git a/boost/process/detail/windows/file_descriptor.hpp b/boost/process/detail/windows/file_descriptor.hpp index e00c96d107..033df02884 100644 --- a/boost/process/detail/windows/file_descriptor.hpp +++ b/boost/process/detail/windows/file_descriptor.hpp @@ -10,7 +10,7 @@ #include <boost/winapi/handles.hpp> #include <boost/winapi/file_management.hpp> #include <string> -#include <boost/filesystem/path.hpp> +#include <boost/process/filesystem.hpp> #include <boost/core/exchange.hpp> namespace boost { namespace process { namespace detail { namespace windows { @@ -40,7 +40,7 @@ struct file_descriptor } file_descriptor() = default; - file_descriptor(const boost::filesystem::path& p, mode_t mode = read_write) + file_descriptor(const boost::process::filesystem::path& p, mode_t mode = read_write) : file_descriptor(p.native(), mode) { } @@ -102,6 +102,7 @@ struct file_descriptor if (_handle != ::boost::winapi::INVALID_HANDLE_VALUE_) ::boost::winapi::CloseHandle(_handle); _handle = boost::exchange(other._handle, ::boost::winapi::INVALID_HANDLE_VALUE_); + return *this; } ~file_descriptor() diff --git a/boost/process/detail/windows/handle_workaround.hpp b/boost/process/detail/windows/handle_workaround.hpp index a6414ae3f6..c288bec83c 100644 --- a/boost/process/detail/windows/handle_workaround.hpp +++ b/boost/process/detail/windows/handle_workaround.hpp @@ -12,7 +12,7 @@ //#define BOOST_USE_WINDOWS_H 1 #if defined( BOOST_USE_WINDOWS_H ) -#include <Winternl.h> +#include <winternl.h> #endif @@ -198,20 +198,20 @@ typedef struct _OBJECT_TYPE_INFORMATION_ { /* -__kernel_entry NTSTATUS NtQuerySystemInformation( +NTSTATUS NtQuerySystemInformation( IN SYSTEM_INFORMATION_CLASS SystemInformationClass, OUT PVOID SystemInformation, IN ULONG SystemInformationLength, OUT PULONG ReturnLength ); */ -typedef ::boost::winapi::NTSTATUS_ (__kernel_entry *nt_system_query_information_p )( +typedef ::boost::winapi::NTSTATUS_ (*nt_system_query_information_p )( SYSTEM_INFORMATION_CLASS_, void *, ::boost::winapi::ULONG_, ::boost::winapi::PULONG_); /* -__kernel_entry NTSYSCALLAPI NTSTATUS NtQueryObject( +NTSYSCALLAPI NTSTATUS NtQueryObject( HANDLE Handle, OBJECT_INFORMATION_CLASS ObjectInformationClass, PVOID ObjectInformation, @@ -220,7 +220,7 @@ __kernel_entry NTSYSCALLAPI NTSTATUS NtQueryObject( ); */ -typedef ::boost::winapi::NTSTATUS_ (__kernel_entry *nt_query_object_p )( +typedef ::boost::winapi::NTSTATUS_ (*nt_query_object_p )( ::boost::winapi::HANDLE_, OBJECT_INFORMATION_CLASS_, void *, diff --git a/boost/process/detail/windows/handles.hpp b/boost/process/detail/windows/handles.hpp index 451c02fc40..901b339a4f 100644 --- a/boost/process/detail/windows/handles.hpp +++ b/boost/process/detail/windows/handles.hpp @@ -11,6 +11,8 @@ #include <boost/process/detail/windows/handle_workaround.hpp> #include <boost/process/detail/windows/handler.hpp> #include <boost/winapi/get_current_process_id.hpp> +#include <boost/winapi/handles.hpp> +#include <boost/winapi/handle_info.hpp> namespace boost { namespace process { namespace detail { @@ -136,7 +138,7 @@ struct limit_handles_ : handler_base_ext [&](::boost::winapi::HANDLE_ handle) { auto itr = std::find(all_handles.begin(), all_handles .end(), handle); - DWORD flags = 0u; + ::boost::winapi::DWORD_ flags = 0u; if (itr != all_handles.end()) *itr = ::boost::winapi::INVALID_HANDLE_VALUE_; else if ((::boost::winapi::GetHandleInformation(*itr, &flags) != 0) @@ -162,7 +164,7 @@ struct limit_handles_ : handler_base_ext } template<typename Executor> - void on_sucess(Executor & exec) const + void on_success(Executor & exec) const { for (auto handle : handles_with_inherit_flag) ::boost::winapi::SetHandleInformation(handle, ::boost::winapi::HANDLE_FLAG_INHERIT_, ::boost::winapi::HANDLE_FLAG_INHERIT_); diff --git a/boost/process/detail/windows/io_context_ref.hpp b/boost/process/detail/windows/io_context_ref.hpp index 783c3179e4..3722ff12ac 100644 --- a/boost/process/detail/windows/io_context_ref.hpp +++ b/boost/process/detail/windows/io_context_ref.hpp @@ -8,7 +8,9 @@ #include <boost/process/detail/handler_base.hpp> #include <boost/process/detail/windows/async_handler.hpp> +#include <boost/process/detail/windows/is_running.hpp> #include <boost/asio/io_context.hpp> +#include <boost/asio/post.hpp> #include <boost/asio/windows/object_handle.hpp> #include <boost/winapi/process.hpp> #include <boost/winapi/handles.hpp> @@ -114,6 +116,15 @@ struct io_context_ref : boost::process::detail::handler_base wait_handler wh(std::move(funcs), ios, process_handle, exec.exit_status); + ::boost::winapi::DWORD_ code; + if(::boost::winapi::GetExitCodeProcess(process_handle, &code) + && code != still_active) + { + ::boost::asio::post(wh.handle->get_executor(), std::move(wh)); + return; + } + + auto handle_p = wh.handle.get(); handle_p->async_wait(std::move(wh)); } @@ -130,12 +141,13 @@ struct io_context_ref : boost::process::detail::handler_base boost::asio::io_context & ios, void * handle, const std::shared_ptr<std::atomic<int>> &exit_status) : funcs(std::move(funcs)), - handle(new boost::asio::windows::object_handle(ios.get_executor(), handle)), + handle(new boost::asio::windows::object_handle( + asio::prefer(ios.get_executor(), asio::execution::outstanding_work.tracked), handle)), exit_status(exit_status) { } - void operator()(const boost::system::error_code & ec_in) + void operator()(const boost::system::error_code & ec_in = {}) { std::error_code ec; if (ec_in) diff --git a/boost/process/detail/windows/is_running.hpp b/boost/process/detail/windows/is_running.hpp index d8e5a6fb7c..f1115cdc65 100644 --- a/boost/process/detail/windows/is_running.hpp +++ b/boost/process/detail/windows/is_running.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2106 Klemens D. Morgenstern +// Copyright (c) 2016 Klemens D. Morgenstern // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -7,6 +7,7 @@ #define BOOST_PROCESS_WINDOWS_IS_RUNNING_HPP #include <boost/process/detail/config.hpp> +#include <boost/process/detail/windows/child_handle.hpp> #include <system_error> #include <cstdlib> #include <boost/winapi/process.hpp> diff --git a/boost/process/detail/windows/on_exit.hpp b/boost/process/detail/windows/on_exit.hpp index 227485c489..c98f8d09d3 100644 --- a/boost/process/detail/windows/on_exit.hpp +++ b/boost/process/detail/windows/on_exit.hpp @@ -6,13 +6,20 @@ #ifndef BOOST_PROCESS_WINDOWS_ON_EXIT_HPP_ #define BOOST_PROCESS_WINDOWS_ON_EXIT_HPP_ +#include <boost/process/async.hpp> #include <boost/process/detail/config.hpp> #include <boost/process/detail/handler_base.hpp> #include <boost/process/detail/windows/async_handler.hpp> +#include <boost/asio/execution.hpp> #include <system_error> #include <functional> -namespace boost { namespace process { namespace detail { namespace windows { +namespace boost { namespace process { namespace detail { + +template<typename Tuple> +inline asio::io_context& get_io_context(const Tuple & tup); + +namespace windows { struct on_exit_ : boost::process::detail::windows::async_handler { @@ -23,10 +30,12 @@ struct on_exit_ : boost::process::detail::windows::async_handler } template<typename Executor> - std::function<void(int, const std::error_code&)> on_exit_handler(Executor&) + std::function<void(int, const std::error_code&)> on_exit_handler(Executor& exec) { + auto v = boost::asio::prefer(boost::process::detail::get_io_context(exec.seq).get_executor(), + boost::asio::execution::outstanding_work.tracked); auto handler_ = this->handler; - return [handler_](int exit_code, const std::error_code & ec) + return [v, handler_](int exit_code, const std::error_code & ec) { handler_(static_cast<int>(exit_code), ec); }; diff --git a/boost/process/detail/windows/pipe_in.hpp b/boost/process/detail/windows/pipe_in.hpp index 39546eae62..1ef2152793 100644 --- a/boost/process/detail/windows/pipe_in.hpp +++ b/boost/process/detail/windows/pipe_in.hpp @@ -14,6 +14,8 @@ #include <boost/winapi/handles.hpp> #include <boost/process/detail/used_handles.hpp> #include <boost/process/detail/handler_base.hpp> +#include <boost/system/error_code.hpp> + namespace boost { namespace process { namespace detail { namespace windows { diff --git a/boost/process/detail/windows/pipe_out.hpp b/boost/process/detail/windows/pipe_out.hpp index 125a34862d..24cd6a82a4 100644 --- a/boost/process/detail/windows/pipe_out.hpp +++ b/boost/process/detail/windows/pipe_out.hpp @@ -15,10 +15,10 @@ #include <boost/winapi/handles.hpp> #include <boost/process/detail/used_handles.hpp> #include <boost/process/detail/handler_base.hpp> - -namespace boost { namespace process { namespace detail { namespace windows { +#include <boost/system/error_code.hpp> +namespace boost { namespace process { namespace detail { namespace windows { template<int p1, int p2> struct pipe_out : public ::boost::process::detail::handler_base, ::boost::process::detail::uses_handles diff --git a/boost/process/detail/windows/search_path.hpp b/boost/process/detail/windows/search_path.hpp index fe267bdf7e..5817a304fe 100644 --- a/boost/process/detail/windows/search_path.hpp +++ b/boost/process/detail/windows/search_path.hpp @@ -11,8 +11,7 @@ #define BOOST_PROCESS_WINDOWS_SEARCH_PATH_HPP #include <boost/process/detail/config.hpp> -#include <boost/filesystem/path.hpp> -#include <boost/filesystem/operations.hpp> +#include <boost/process/filesystem.hpp> #include <boost/system/error_code.hpp> #include <string> #include <stdexcept> @@ -24,9 +23,9 @@ namespace boost { namespace process { namespace detail { namespace windows { -inline boost::filesystem::path search_path( - const boost::filesystem::path &filename, - const std::vector<boost::filesystem::path> &path) +inline boost::process::filesystem::path search_path( + const boost::process::filesystem::path &filename, + const std::vector<boost::process::filesystem::path> &path) { const ::boost::process::wnative_environment ne{}; typedef typename ::boost::process::wnative_environment::const_entry_type value_type; @@ -36,7 +35,9 @@ inline boost::filesystem::path search_path( [&](const value_type & e) {return id == ::boost::to_upper_copy(e.get_name(), ::boost::process::detail::process_locale());}); - auto extensions_in = itr->to_vector(); + std::vector<std::wstring> extensions_in; + if (itr != ne.cend()) + extensions_in = itr->to_vector(); std::vector<std::wstring> extensions((extensions_in.size() * 2) + 1); @@ -55,15 +56,19 @@ inline boost::filesystem::path search_path( for (auto & ext : extensions) boost::to_lower(ext); - for (const boost::filesystem::path & pp_ : path) + for (const boost::process::filesystem::path & pp_ : path) { auto p = pp_ / filename; - for (boost::filesystem::path ext : extensions) + for (boost::process::filesystem::path ext : extensions) { - boost::filesystem::path pp_ext = p; + boost::process::filesystem::path pp_ext = p; pp_ext += ext; +#if defined(BOOST_PROCESS_USE_STD_FS) + std::error_code ec; +#else boost::system::error_code ec; - bool file = boost::filesystem::is_regular_file(pp_ext, ec); +#endif + bool file = boost::process::filesystem::is_regular_file(pp_ext, ec); if (!ec && file && ::boost::winapi::sh_get_file_info(pp_ext.native().c_str(), 0, 0, 0, ::boost::winapi::SHGFI_EXETYPE_)) { diff --git a/boost/process/detail/windows/shell_path.hpp b/boost/process/detail/windows/shell_path.hpp index 263a410541..bb150c9446 100644 --- a/boost/process/detail/windows/shell_path.hpp +++ b/boost/process/detail/windows/shell_path.hpp @@ -12,29 +12,29 @@ #include <boost/process/detail/config.hpp> #include <system_error> -#include <boost/filesystem/path.hpp> +#include <boost/process/filesystem.hpp> #include <boost/winapi/basic_types.hpp> #include <boost/winapi/get_system_directory.hpp> namespace boost { namespace process { namespace detail { namespace windows { -inline boost::filesystem::path shell_path() +inline boost::process::filesystem::path shell_path() { ::boost::winapi::WCHAR_ sysdir[260]; unsigned int size = ::boost::winapi::get_system_directory(sysdir, sizeof(sysdir)); if (!size) throw_last_error("GetSystemDirectory() failed"); - boost::filesystem::path p = sysdir; + boost::process::filesystem::path p = sysdir; return p / "cmd.exe"; } -inline boost::filesystem::path shell_path(std::error_code &ec) noexcept +inline boost::process::filesystem::path shell_path(std::error_code &ec) noexcept { ::boost::winapi::WCHAR_ sysdir[260]; unsigned int size = ::boost::winapi::get_system_directory(sysdir, sizeof(sysdir)); - boost::filesystem::path p; + boost::process::filesystem::path p; if (!size) ec = std::error_code( ::boost::winapi::GetLastError(), |