]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/process/example/posix.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / process / example / posix.cpp
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 #include <boost/process.hpp>
11 #include <boost/process/posix.hpp>
12 #include <boost/process/extend.hpp>
13 #include <iostream>
14 #include <fstream>
15 #include <unistd.h>
16 #include <errno.h>
17
18 namespace bp = boost::process;
19
20 int main()
21 {
22
23 //duplicate our pipe descriptor into literal position 4
24 bp::pipe p;
25 bp::system("test", bp::posix::fd.bind(4, p.native_sink()));
26
27
28 //close file-descriptor from explicit integral value
29 bp::system("test", bp::posix::fd.close(STDIN_FILENO));
30
31 //close file-descriptors from explicit integral values
32 bp::system("test", bp::posix::fd.close({STDIN_FILENO, STDOUT_FILENO}));
33
34 //add custom handlers
35 const char *env[2] = { 0 };
36 env[0] = "LANG=de";
37 bp::system("test",
38 bp::extend::on_setup([env](auto &e) { e.env = const_cast<char**>(env); }),
39 bp::extend::on_fork_error([](auto&, const std::error_code & ec)
40 { std::cerr << errno << std::endl; }),
41 bp::extend::on_exec_setup([](auto&)
42 { ::chroot("/new/root/directory/"); }),
43 bp::extend::on_exec_error([](auto&, const std::error_code & ec)
44 { std::ofstream ofs("log.txt"); if (ofs) ofs << errno; })
45 );
46
47 }