This repository has been archived by the owner on Sep 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 128
/
child.h
66 lines (60 loc) · 1.7 KB
/
child.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
* Copyright (c) 2014, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in
* the LICENSE file in the root directory of this source tree. An
* additional grant of patent rights can be found in the PATENTS file
* in the same directory.
*
*/
#pragma once
#include <stdint.h>
#include "util.h"
#define CHILD_CTTY (1<<0)
#define CHILD_SETSID (1<<1)
enum child_io_mode {
CHILD_IO_DEV_NULL,
CHILD_IO_PTY,
CHILD_IO_PIPE,
CHILD_IO_INHERIT,
CHILD_IO_RECORD,
CHILD_IO_DUP_TO_STDOUT,
};
struct child_start_info {
int flags;
const char* exename;
const char* const* argv;
const char* const* environ;
enum child_io_mode io[3];
void (*pre_exec)(void* data);
void* pre_exec_data;
void (*pty_setup)(int master, int slave, void* data);
void* pty_setup_data;
int deathsig;
const char* child_chdir;
};
struct fdrecorder;
struct child {
int flags;
int deathsig;
pid_t pid;
int status;
struct fdh* pty_master;
struct fdh* fd[3];
struct fdrecorder* recorder[3];
unsigned dead : 1;
unsigned skip_cleanup_wait : 1;
};
struct child* child_start(const struct child_start_info* csi);
int child_wait(struct child* c);
void child_wait_die_on_error(struct child* c);
bool child_poll_death(struct child* c);
void child_kill(struct child* c, int signo);
bool child_status_success_p(int status);
int child_status_to_exit_code(int status);
char* massage_output(const void* buf, size_t nr_bytes);
char* massage_output_buf(struct growable_buffer errbuf);
void install_child_error_converter(struct child* child);
// Like system, but using fb-adb infrastructure.
int xsystem(const char* cmd);