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