1275988Sngie/* Copyright (c) 2008 The NetBSD Foundation, Inc.
2240116Smarcel * All rights reserved.
3240116Smarcel *
4240116Smarcel * Redistribution and use in source and binary forms, with or without
5240116Smarcel * modification, are permitted provided that the following conditions
6240116Smarcel * are met:
7240116Smarcel * 1. Redistributions of source code must retain the above copyright
8240116Smarcel *    notice, this list of conditions and the following disclaimer.
9240116Smarcel * 2. Redistributions in binary form must reproduce the above copyright
10240116Smarcel *    notice, this list of conditions and the following disclaimer in the
11240116Smarcel *    documentation and/or other materials provided with the distribution.
12240116Smarcel *
13240116Smarcel * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
14240116Smarcel * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
15240116Smarcel * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
16240116Smarcel * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17240116Smarcel * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
18240116Smarcel * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19240116Smarcel * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
20240116Smarcel * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21240116Smarcel * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
22240116Smarcel * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23240116Smarcel * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
24275988Sngie * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  */
25240116Smarcel
26275988Sngie#if !defined(ATF_C_DETAIL_PROCESS_H)
27275988Sngie#define ATF_C_DETAIL_PROCESS_H
28240116Smarcel
29240116Smarcel#include <sys/types.h>
30240116Smarcel
31240116Smarcel#include <stdbool.h>
32240116Smarcel
33275988Sngie#include <atf-c/detail/fs.h>
34275988Sngie#include <atf-c/detail/list.h>
35240116Smarcel#include <atf-c/error_fwd.h>
36240116Smarcel
37240116Smarcel/* ---------------------------------------------------------------------
38240116Smarcel * The "atf_process_stream" type.
39240116Smarcel * --------------------------------------------------------------------- */
40240116Smarcel
41240116Smarcelstruct atf_process_stream {
42240116Smarcel    int m_type;
43240116Smarcel
44240116Smarcel    /* Valid if m_type == connect. */
45240116Smarcel    int m_src_fd;
46240116Smarcel    int m_tgt_fd;
47240116Smarcel
48240116Smarcel    /* Valid if m_type == redirect_fd. */
49240116Smarcel    int m_fd;
50240116Smarcel
51240116Smarcel    /* Valid if m_type == redirect_path. */
52240116Smarcel    const atf_fs_path_t *m_path;
53240116Smarcel};
54240116Smarceltypedef struct atf_process_stream atf_process_stream_t;
55240116Smarcel
56240116Smarcelextern const int atf_process_stream_type_capture;
57240116Smarcelextern const int atf_process_stream_type_connect;
58240116Smarcelextern const int atf_process_stream_type_inherit;
59240116Smarcelextern const int atf_process_stream_type_redirect_fd;
60240116Smarcelextern const int atf_process_stream_type_redirect_path;
61240116Smarcel
62240116Smarcelatf_error_t atf_process_stream_init_capture(atf_process_stream_t *);
63240116Smarcelatf_error_t atf_process_stream_init_connect(atf_process_stream_t *,
64240116Smarcel                                            const int, const int);
65240116Smarcelatf_error_t atf_process_stream_init_inherit(atf_process_stream_t *);
66240116Smarcelatf_error_t atf_process_stream_init_redirect_fd(atf_process_stream_t *,
67240116Smarcel                                                const int fd);
68240116Smarcelatf_error_t atf_process_stream_init_redirect_path(atf_process_stream_t *,
69240116Smarcel                                                  const atf_fs_path_t *);
70240116Smarcelvoid atf_process_stream_fini(atf_process_stream_t *);
71240116Smarcel
72240116Smarcelint atf_process_stream_type(const atf_process_stream_t *);
73240116Smarcel
74240116Smarcel/* ---------------------------------------------------------------------
75240116Smarcel * The "atf_process_status" type.
76240116Smarcel * --------------------------------------------------------------------- */
77240116Smarcel
78240116Smarcelstruct atf_process_status {
79240116Smarcel    int m_status;
80240116Smarcel};
81240116Smarceltypedef struct atf_process_status atf_process_status_t;
82240116Smarcel
83240116Smarcelvoid atf_process_status_fini(atf_process_status_t *);
84240116Smarcel
85240116Smarcelbool atf_process_status_exited(const atf_process_status_t *);
86240116Smarcelint atf_process_status_exitstatus(const atf_process_status_t *);
87240116Smarcelbool atf_process_status_signaled(const atf_process_status_t *);
88240116Smarcelint atf_process_status_termsig(const atf_process_status_t *);
89240116Smarcelbool atf_process_status_coredump(const atf_process_status_t *);
90240116Smarcel
91240116Smarcel/* ---------------------------------------------------------------------
92240116Smarcel * The "atf_process_child" type.
93240116Smarcel * --------------------------------------------------------------------- */
94240116Smarcel
95240116Smarcelstruct atf_process_child {
96240116Smarcel    pid_t m_pid;
97240116Smarcel
98240116Smarcel    int m_stdout;
99240116Smarcel    int m_stderr;
100240116Smarcel};
101240116Smarceltypedef struct atf_process_child atf_process_child_t;
102240116Smarcel
103240116Smarcelatf_error_t atf_process_child_wait(atf_process_child_t *,
104240116Smarcel                                   atf_process_status_t *);
105240116Smarcelpid_t atf_process_child_pid(const atf_process_child_t *);
106240116Smarcelint atf_process_child_stdout(atf_process_child_t *);
107240116Smarcelint atf_process_child_stderr(atf_process_child_t *);
108240116Smarcel
109240116Smarcel/* ---------------------------------------------------------------------
110240116Smarcel * Free functions.
111240116Smarcel * --------------------------------------------------------------------- */
112240116Smarcel
113240116Smarcelatf_error_t atf_process_fork(atf_process_child_t *,
114240116Smarcel                             void (*)(void *),
115240116Smarcel                             const atf_process_stream_t *,
116240116Smarcel                             const atf_process_stream_t *,
117240116Smarcel                             void *);
118240116Smarcelatf_error_t atf_process_exec_array(atf_process_status_t *,
119240116Smarcel                                   const atf_fs_path_t *,
120240116Smarcel                                   const char *const *,
121240116Smarcel                                   const atf_process_stream_t *,
122240116Smarcel                                   const atf_process_stream_t *,
123240116Smarcel                                   void (*)(void));
124240116Smarcelatf_error_t atf_process_exec_list(atf_process_status_t *,
125240116Smarcel                                  const atf_fs_path_t *,
126240116Smarcel                                  const atf_list_t *,
127240116Smarcel                                  const atf_process_stream_t *,
128240116Smarcel                                  const atf_process_stream_t *,
129240116Smarcel                                  void (*)(void));
130240116Smarcel
131275988Sngie#endif /* !defined(ATF_C_DETAIL_PROCESS_H) */
132