tor  0.4.2.1-alpha-dev
process.h
Go to the documentation of this file.
1 /* Copyright (c) 2003-2004, Roger Dingledine
2  * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
3  * Copyright (c) 2007-2019, The Tor Project, Inc. */
4 /* See LICENSE for licensing information */
5 
11 #ifndef TOR_PROCESS_H
12 #define TOR_PROCESS_H
13 
14 #include "orconfig.h"
15 #include "lib/malloc/malloc.h"
16 #include "lib/string/printf.h"
17 
19 #define PROCESS_MAX_WRITE (1024)
20 
22 #define PROCESS_MAX_READ (1024)
23 
24 typedef enum {
27 
30 
34 
35 const char *process_status_to_string(process_status_t status);
36 
37 typedef enum {
41 
45 
47 
49 
50 struct smartlist_t;
51 
52 struct process_t;
53 typedef struct process_t process_t;
54 
55 typedef uint64_t process_exit_code_t;
56 typedef uint64_t process_pid_t;
57 
58 typedef void (*process_read_callback_t)(process_t *,
59  const char *,
60  size_t);
61 typedef bool
62 (*process_exit_callback_t)(process_t *, process_exit_code_t);
63 
64 void process_init(void);
65 void process_free_all(void);
66 const struct smartlist_t *process_get_all_processes(void);
67 
68 process_t *process_new(const char *command);
69 void process_free_(process_t *process);
70 #define process_free(s) FREE_AND_NULL(process_t, process_free_, (s))
71 
73 bool process_terminate(process_t *process);
74 
75 process_pid_t process_get_pid(process_t *process);
76 
78  process_read_callback_t);
80  process_read_callback_t);
82  process_exit_callback_t);
83 
84 const char *process_get_command(const process_t *process);
85 
86 void process_append_argument(process_t *process, const char *argument);
87 const struct smartlist_t *process_get_arguments(const process_t *process);
88 char **process_get_argv(const process_t *process);
89 
91  const struct smartlist_t *env);
93  const char *key,
94  const char *value);
95 
98 
99 void process_set_protocol(process_t *process, process_protocol_t protocol);
101 
102 void process_set_data(process_t *process, void *data);
103 void *process_get_data(const process_t *process);
104 
105 void process_set_status(process_t *process, process_status_t status);
107 
108 #ifndef _WIN32
109 struct process_unix_t;
110 struct process_unix_t *process_get_unix_process(const process_t *process);
111 #else
112 struct process_win32_t;
113 struct process_win32_t *process_get_win32_process(const process_t *process);
114 #endif /* !defined(_WIN32) */
115 
116 void process_write(process_t *process,
117  const uint8_t *data, size_t size);
118 void process_vprintf(process_t *process,
119  const char *format, va_list args) CHECK_PRINTF(2, 0);
120 void process_printf(process_t *process,
121  const char *format, ...) CHECK_PRINTF(2, 3);
122 
127  process_exit_code_t);
128 
129 #ifdef PROCESS_PRIVATE
130 MOCK_DECL(STATIC int, process_read_stdout, (process_t *, buf_t *));
131 MOCK_DECL(STATIC int, process_read_stderr, (process_t *, buf_t *));
132 MOCK_DECL(STATIC void, process_write_stdin, (process_t *, buf_t *));
133 
134 STATIC void process_read_data(process_t *process,
135  buf_t *buffer,
136  process_read_callback_t callback);
137 STATIC void process_read_buffer(process_t *process,
138  buf_t *buffer,
139  process_read_callback_t callback);
140 STATIC void process_read_lines(process_t *process,
141  buf_t *buffer,
142  process_read_callback_t callback);
143 #endif /* defined(PROCESS_PRIVATE) */
144 
145 #endif /* !defined(TOR_PROCESS_H) */
void process_append_argument(process_t *process, const char *argument)
Definition: process.c:419
void process_reset_environment(process_t *process, const smartlist_t *env)
Definition: process.c:470
void process_set_stdout_read_callback(process_t *, process_read_callback_t)
Definition: process.c:321
process_status_t process_exec(process_t *process)
Definition: process.c:253
const struct smartlist_t * process_get_all_processes(void)
Definition: process.c:166
Header for printf.c.
void tor_disable_spawning_background_processes(void)
Definition: process.c:132
process_pid_t process_get_pid(process_t *process)
Definition: process.c:303
STATIC void process_read_data(process_t *process, buf_t *buffer, process_read_callback_t callback)
Definition: process.c:694
void process_init(void)
Definition: process.c:141
void process_notify_event_stderr(process_t *process)
Definition: process.c:593
const char * process_status_to_string(process_status_t status)
Definition: process.c:92
Headers for util_malloc.c.
bool process_terminate(process_t *process)
Definition: process.c:284
void process_set_environment(process_t *process, const char *key, const char *value)
Definition: process.c:487
struct process_environment_t * process_get_environment(const process_t *)
Definition: process.c:501
void process_notify_event_stdin(process_t *process)
Definition: process.c:609
void process_set_exit_callback(process_t *, process_exit_callback_t)
Definition: process.c:347
void process_notify_event_exit(process_t *process, process_exit_code_t)
Definition: process.c:622
const struct smartlist_t * process_get_arguments(const process_t *process)
Definition: process.c:430
void process_free_(process_t *process)
Definition: process.c:217
const char * process_get_command(const process_t *process)
Definition: process.c:356
process_status_t
Definition: process.h:24
void process_write(process_t *process, const uint8_t *data, size_t size)
Definition: process.c:530
char ** process_get_argv(const process_t *process)
Definition: process.c:439
void * process_get_data(const process_t *process)
Definition: process.c:395
void process_set_data(process_t *process, void *data)
Definition: process.c:385
void void void process_notify_event_stdout(process_t *process)
Definition: process.c:576
process_protocol_t process_get_protocol(const process_t *process)
Definition: process.c:371
void process_vprintf(process_t *process, const char *format, va_list args)
Definition: process.c:543
void process_free_all(void)
Definition: process.c:153
process_status_t process_get_status(const process_t *process)
Definition: process.c:411
#define MOCK_DECL(rv, funcname, arglist)
Definition: testsupport.h:94
void process_printf(process_t *process, const char *format,...)
Definition: process.c:560
struct process_unix_t * process_get_unix_process(const process_t *process)
Definition: process.c:510
void process_set_stderr_read_callback(process_t *, process_read_callback_t)
Definition: process.c:336
process_t * process_new(const char *command)
Definition: process.c:180
process_protocol_t
Definition: process.h:37
const char * process_protocol_to_string(process_protocol_t protocol)
Definition: process.c:112
STATIC void process_read_buffer(process_t *process, buf_t *buffer, process_read_callback_t callback)
Definition: process.c:721
STATIC void process_read_lines(process_t *process, buf_t *buffer, process_read_callback_t callback)
Definition: process.c:748
void process_set_status(process_t *process, process_status_t status)
Definition: process.c:403