xref: /freebsd/contrib/atf/atf-c/detail/process.h (revision 2f02600abfddfc4e9f20dd384a2e729b451e16bd)
1 /*
2  * Automated Testing Framework (atf)
3  *
4  * Copyright (c) 2008 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
17  * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #if !defined(ATF_C_PROCESS_H)
31 #define ATF_C_PROCESS_H
32 
33 #include <sys/types.h>
34 
35 #include <stdbool.h>
36 
37 #include <atf-c/error_fwd.h>
38 
39 #include "fs.h"
40 #include "list.h"
41 
42 /* ---------------------------------------------------------------------
43  * The "atf_process_stream" type.
44  * --------------------------------------------------------------------- */
45 
46 struct atf_process_stream {
47     int m_type;
48 
49     /* Valid if m_type == connect. */
50     int m_src_fd;
51     int m_tgt_fd;
52 
53     /* Valid if m_type == redirect_fd. */
54     int m_fd;
55 
56     /* Valid if m_type == redirect_path. */
57     const atf_fs_path_t *m_path;
58 };
59 typedef struct atf_process_stream atf_process_stream_t;
60 
61 extern const int atf_process_stream_type_capture;
62 extern const int atf_process_stream_type_connect;
63 extern const int atf_process_stream_type_inherit;
64 extern const int atf_process_stream_type_redirect_fd;
65 extern const int atf_process_stream_type_redirect_path;
66 
67 atf_error_t atf_process_stream_init_capture(atf_process_stream_t *);
68 atf_error_t atf_process_stream_init_connect(atf_process_stream_t *,
69                                             const int, const int);
70 atf_error_t atf_process_stream_init_inherit(atf_process_stream_t *);
71 atf_error_t atf_process_stream_init_redirect_fd(atf_process_stream_t *,
72                                                 const int fd);
73 atf_error_t atf_process_stream_init_redirect_path(atf_process_stream_t *,
74                                                   const atf_fs_path_t *);
75 void atf_process_stream_fini(atf_process_stream_t *);
76 
77 int atf_process_stream_type(const atf_process_stream_t *);
78 
79 /* ---------------------------------------------------------------------
80  * The "atf_process_status" type.
81  * --------------------------------------------------------------------- */
82 
83 struct atf_process_status {
84     int m_status;
85 };
86 typedef struct atf_process_status atf_process_status_t;
87 
88 void atf_process_status_fini(atf_process_status_t *);
89 
90 bool atf_process_status_exited(const atf_process_status_t *);
91 int atf_process_status_exitstatus(const atf_process_status_t *);
92 bool atf_process_status_signaled(const atf_process_status_t *);
93 int atf_process_status_termsig(const atf_process_status_t *);
94 bool atf_process_status_coredump(const atf_process_status_t *);
95 
96 /* ---------------------------------------------------------------------
97  * The "atf_process_child" type.
98  * --------------------------------------------------------------------- */
99 
100 struct atf_process_child {
101     pid_t m_pid;
102 
103     int m_stdout;
104     int m_stderr;
105 };
106 typedef struct atf_process_child atf_process_child_t;
107 
108 atf_error_t atf_process_child_wait(atf_process_child_t *,
109                                    atf_process_status_t *);
110 pid_t atf_process_child_pid(const atf_process_child_t *);
111 int atf_process_child_stdout(atf_process_child_t *);
112 int atf_process_child_stderr(atf_process_child_t *);
113 
114 /* ---------------------------------------------------------------------
115  * Free functions.
116  * --------------------------------------------------------------------- */
117 
118 atf_error_t atf_process_fork(atf_process_child_t *,
119                              void (*)(void *),
120                              const atf_process_stream_t *,
121                              const atf_process_stream_t *,
122                              void *);
123 atf_error_t atf_process_exec_array(atf_process_status_t *,
124                                    const atf_fs_path_t *,
125                                    const char *const *,
126                                    const atf_process_stream_t *,
127                                    const atf_process_stream_t *,
128                                    void (*)(void));
129 atf_error_t atf_process_exec_list(atf_process_status_t *,
130                                   const atf_fs_path_t *,
131                                   const atf_list_t *,
132                                   const atf_process_stream_t *,
133                                   const atf_process_stream_t *,
134                                   void (*)(void));
135 
136 #endif /* !defined(ATF_C_PROCESS_H) */
137