xref: /src/contrib/kyua/utils/process/system.cpp (revision b0d29bc47dba79f6f38e67eabadfb4b32ffd9390)
108334c51SBrooks Davis // Copyright 2010 The Kyua Authors.
208334c51SBrooks Davis // All rights reserved.
308334c51SBrooks Davis //
408334c51SBrooks Davis // Redistribution and use in source and binary forms, with or without
508334c51SBrooks Davis // modification, are permitted provided that the following conditions are
608334c51SBrooks Davis // met:
708334c51SBrooks Davis //
808334c51SBrooks Davis // * Redistributions of source code must retain the above copyright
908334c51SBrooks Davis //   notice, this list of conditions and the following disclaimer.
1008334c51SBrooks Davis // * Redistributions in binary form must reproduce the above copyright
1108334c51SBrooks Davis //   notice, this list of conditions and the following disclaimer in the
1208334c51SBrooks Davis //   documentation and/or other materials provided with the distribution.
1308334c51SBrooks Davis // * Neither the name of Google Inc. nor the names of its contributors
1408334c51SBrooks Davis //   may be used to endorse or promote products derived from this software
1508334c51SBrooks Davis //   without specific prior written permission.
1608334c51SBrooks Davis //
1708334c51SBrooks Davis // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1808334c51SBrooks Davis // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1908334c51SBrooks Davis // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2008334c51SBrooks Davis // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2108334c51SBrooks Davis // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2208334c51SBrooks Davis // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2308334c51SBrooks Davis // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2408334c51SBrooks Davis // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2508334c51SBrooks Davis // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2608334c51SBrooks Davis // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2708334c51SBrooks Davis // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2808334c51SBrooks Davis 
2908334c51SBrooks Davis #include "utils/process/system.hpp"
3008334c51SBrooks Davis 
3108334c51SBrooks Davis extern "C" {
3208334c51SBrooks Davis #include <sys/types.h>
3308334c51SBrooks Davis #include <sys/wait.h>
3408334c51SBrooks Davis 
3508334c51SBrooks Davis #include <fcntl.h>
3608334c51SBrooks Davis #include <unistd.h>
3708334c51SBrooks Davis }
3808334c51SBrooks Davis 
3908334c51SBrooks Davis namespace detail = utils::process::detail;
4008334c51SBrooks Davis 
4108334c51SBrooks Davis 
4208334c51SBrooks Davis /// Indirection to execute the dup2(2) system call.
4308334c51SBrooks Davis int (*detail::syscall_dup2)(const int, const int) = ::dup2;
4408334c51SBrooks Davis 
4508334c51SBrooks Davis 
4608334c51SBrooks Davis /// Indirection to execute the fork(2) system call.
4708334c51SBrooks Davis pid_t (*detail::syscall_fork)(void) = ::fork;
4808334c51SBrooks Davis 
4908334c51SBrooks Davis 
5008334c51SBrooks Davis /// Indirection to execute the open(2) system call.
5108334c51SBrooks Davis int (*detail::syscall_open)(const char*, const int, ...) = ::open;
5208334c51SBrooks Davis 
5308334c51SBrooks Davis 
5408334c51SBrooks Davis /// Indirection to execute the pipe(2) system call.
5508334c51SBrooks Davis int (*detail::syscall_pipe)(int[2]) = ::pipe;
5608334c51SBrooks Davis 
5708334c51SBrooks Davis 
5808334c51SBrooks Davis /// Indirection to execute the waitpid(2) system call.
5908334c51SBrooks Davis pid_t (*detail::syscall_waitpid)(const pid_t, int*, const int) = ::waitpid;
60