1 // Copyright 2012 Google Inc.
2 // All rights reserved.
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of Google Inc. nor the names of its contributors
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 /// Structures and functions to run a program in an isolated manner.
32 /// Pretty much all the functions of this module (ab)use global variables to
33 /// store their state. This means that they are not reentrant, but this is by
34 /// design: the whole point of implementing standalone testers is to simplify
35 /// the writing of this code by being able to make such assumptions.
37 #if !defined(KYUA_RUN_H)
44 #include "error_fwd.h"
48 extern const char* kyua_run_tmpdir
;
51 /// Parameters that indicate how to isolate a subprocess.
53 /// In the name of simplicity, the fields of this structure can be considered
55 struct kyua_run_params
{
56 /// Execution deadline for the subprocess.
57 unsigned long timeout_seconds
;
59 /// Work directory for the subprocess to use.
60 const char* work_directory
;
62 /// UID of the user to switch to before running the subprocess.
63 uid_t unprivileged_user
;
65 /// GID of the group to switch to before running the subprocess.
66 gid_t unprivileged_group
;
70 void kyua_run_params_init(kyua_run_params_t
*);
73 void kyua_run_exec(const char*, const char* const*) KYUA_DEFS_NORETURN
;
76 kyua_error_t
kyua_run_fork(const kyua_run_params_t
*, pid_t
* const);
77 kyua_error_t
kyua_run_wait(const pid_t
, int*, bool*);
80 kyua_error_t
kyua_run_work_directory_enter(const char*, const uid_t
,
82 kyua_error_t
kyua_run_work_directory_leave(char**);
85 #endif // !defined(KYUA_RUN_H)