throw_on_error.hpp
Go to the documentation of this file.
1 // Copyright (c) 2006, 2007 Julio M. Merino Vidal
2 // Copyright (c) 2008 Ilya Sokolov, Boris Schaeling
3 // Copyright (c) 2009 Boris Schaeling
4 // Copyright (c) 2010 Felipe Tanus, Boris Schaeling
5 // Copyright (c) 2011, 2012 Jeff Flinn, Boris Schaeling
6 //
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 
10 #pragma once
11 
12 #include <boost/process/config.hpp>
14 #include <boost/system/error_code.hpp>
15 #include <boost/system/system_error.hpp>
16 #include <unistd.h>
17 #include <fcntl.h>
18 #include <errno.h>
19 
21 {
22 
24  {
25  public:
26  template <class PosixExecutor>
27  void on_fork_setup(PosixExecutor&) const
28  {
29  if (::pipe(fds_) == -1)
30  {
31  BOOST_PROCESS_THROW_LAST_SYSTEM_ERROR("pipe(2) failed");
32  }
33  if (::fcntl(fds_[1], F_SETFD, FD_CLOEXEC) == -1)
34  {
35  int e = errno;
36  ::close(fds_[0]);
37  ::close(fds_[1]);
38  BOOST_PROCESS_THROW(boost::system::system_error(
39  boost::system::error_code(e, boost::system::system_category()),
40  BOOST_PROCESS_SOURCE_LOCATION "fcntl(2) failed"));
41  }
42  }
43 
44  template <class PosixExecutor>
45  void on_fork_error(PosixExecutor&) const
46  {
47  int e = errno;
48  ::close(fds_[0]);
49  ::close(fds_[1]);
50  BOOST_PROCESS_THROW(boost::system::system_error(
51  boost::system::error_code(e, boost::system::system_category()),
52  BOOST_PROCESS_SOURCE_LOCATION "fork(2) failed"));
53  }
54 
55  template <class PosixExecutor>
56  void on_fork_success(PosixExecutor&) const
57  {
58  ::close(fds_[1]);
59  int code;
60  if (::read(fds_[0], &code, sizeof(int)) > 0)
61  {
62  ::close(fds_[0]);
63  BOOST_PROCESS_THROW(boost::system::system_error(
64  boost::system::error_code(code,
65  boost::system::system_category()),
66  BOOST_PROCESS_SOURCE_LOCATION "execve(2) failed"));
67  }
68  ::close(fds_[0]);
69  }
70 
71  template <class PosixExecutor>
72  void on_exec_setup(PosixExecutor&) const
73  {
74  ::close(fds_[0]);
75  }
76 
77  template <class PosixExecutor>
78  void on_exec_error(PosixExecutor&) const
79  {
80  int e = errno;
81  while (::write(fds_[1], &e, sizeof(int)) == -1 && errno == EINTR)
82  ;
83  ::close(fds_[1]);
84  }
85 
86  private:
87  mutable int fds_[2];
88  };
89 
90 }
boost::process::posix::initializers::throw_on_error::on_exec_error
void on_exec_error(PosixExecutor &) const
Definition: throw_on_error.hpp:78
config.hpp
BOOST_PROCESS_THROW
#define BOOST_PROCESS_THROW(EX)
Definition: config.hpp:64
initializer_base.hpp
boost::process::posix::initializers::throw_on_error::on_exec_setup
void on_exec_setup(PosixExecutor &) const
Definition: throw_on_error.hpp:72
boost::process::posix::initializers::throw_on_error::on_fork_success
void on_fork_success(PosixExecutor &) const
Definition: throw_on_error.hpp:56
boost::process::posix::initializers::throw_on_error::on_fork_setup
void on_fork_setup(PosixExecutor &) const
Definition: throw_on_error.hpp:27
boost::process::posix::pipe
Definition: pipe.hpp:15
boost::process::posix::initializers
Definition: bind_fd.hpp:15
armarx::read
void read(auto &eigen, auto *table)
Definition: FTSensorCalibrationGuiWidgetController.cpp:462
boost::process::posix::initializers::initializer_base
Definition: initializer_base.hpp:15
boost::process::posix::initializers::throw_on_error::on_fork_error
void on_fork_error(PosixExecutor &) const
Definition: throw_on_error.hpp:45
boost::process::posix::initializers::throw_on_error
Definition: throw_on_error.hpp:23
armarx::aron::write
requires data::isWriter< WriterT > void write(WriterT &aron_w, const Eigen::Matrix< EigenT, rows, cols, options > &input, typename WriterT::ReturnType &ret, const armarx::aron::Path &aron_p=armarx::aron::Path())
Definition: eigen.h:134