Path: blob/main/contrib/atf/atf-c/detail/process.h
39507 views
/* Copyright (c) 2008 The NetBSD Foundation, Inc.1* All rights reserved.2*3* Redistribution and use in source and binary forms, with or without4* modification, are permitted provided that the following conditions5* are met:6* 1. Redistributions of source code must retain the above copyright7* notice, this list of conditions and the following disclaimer.8* 2. Redistributions in binary form must reproduce the above copyright9* notice, this list of conditions and the following disclaimer in the10* documentation and/or other materials provided with the distribution.11*12* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND13* CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,14* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF15* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.16* IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY17* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL18* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE19* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS20* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER21* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR22* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN23* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */2425#if !defined(ATF_C_DETAIL_PROCESS_H)26#define ATF_C_DETAIL_PROCESS_H2728#include <sys/types.h>2930#include <stdbool.h>3132#include <atf-c/detail/fs.h>33#include <atf-c/detail/list.h>34#include <atf-c/error_fwd.h>3536/* ---------------------------------------------------------------------37* The "atf_process_stream" type.38* --------------------------------------------------------------------- */3940struct atf_process_stream {41int m_type;4243/* Valid if m_type == connect. */44int m_src_fd;45int m_tgt_fd;4647/* Valid if m_type == redirect_fd. */48int m_fd;4950/* Valid if m_type == redirect_path. */51const atf_fs_path_t *m_path;52};53typedef struct atf_process_stream atf_process_stream_t;5455extern const int atf_process_stream_type_capture;56extern const int atf_process_stream_type_connect;57extern const int atf_process_stream_type_inherit;58extern const int atf_process_stream_type_redirect_fd;59extern const int atf_process_stream_type_redirect_path;6061atf_error_t atf_process_stream_init_capture(atf_process_stream_t *);62atf_error_t atf_process_stream_init_connect(atf_process_stream_t *,63const int, const int);64atf_error_t atf_process_stream_init_inherit(atf_process_stream_t *);65atf_error_t atf_process_stream_init_redirect_fd(atf_process_stream_t *,66const int fd);67atf_error_t atf_process_stream_init_redirect_path(atf_process_stream_t *,68const atf_fs_path_t *);69void atf_process_stream_fini(atf_process_stream_t *);7071int atf_process_stream_type(const atf_process_stream_t *);7273/* ---------------------------------------------------------------------74* The "atf_process_status" type.75* --------------------------------------------------------------------- */7677struct atf_process_status {78int m_status;79};80typedef struct atf_process_status atf_process_status_t;8182void atf_process_status_fini(atf_process_status_t *);8384bool atf_process_status_exited(const atf_process_status_t *);85int atf_process_status_exitstatus(const atf_process_status_t *);86bool atf_process_status_signaled(const atf_process_status_t *);87int atf_process_status_termsig(const atf_process_status_t *);88bool atf_process_status_coredump(const atf_process_status_t *);8990/* ---------------------------------------------------------------------91* The "atf_process_child" type.92* --------------------------------------------------------------------- */9394struct atf_process_child {95pid_t m_pid;9697int m_stdout;98int m_stderr;99};100typedef struct atf_process_child atf_process_child_t;101102atf_error_t atf_process_child_wait(atf_process_child_t *,103atf_process_status_t *);104pid_t atf_process_child_pid(const atf_process_child_t *);105int atf_process_child_stdout(atf_process_child_t *);106int atf_process_child_stderr(atf_process_child_t *);107108/* ---------------------------------------------------------------------109* Free functions.110* --------------------------------------------------------------------- */111112atf_error_t atf_process_fork(atf_process_child_t *,113void (*)(void *),114const atf_process_stream_t *,115const atf_process_stream_t *,116void *);117atf_error_t atf_process_exec_array(atf_process_status_t *,118const atf_fs_path_t *,119const char *const *,120const atf_process_stream_t *,121const atf_process_stream_t *,122void (*)(void));123atf_error_t atf_process_exec_list(atf_process_status_t *,124const atf_fs_path_t *,125const atf_list_t *,126const atf_process_stream_t *,127const atf_process_stream_t *,128void (*)(void));129130#endif /* !defined(ATF_C_DETAIL_PROCESS_H) */131132133