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