Tor 0.4.9.0-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-2021, The Tor Project, Inc. */
4/* See LICENSE for licensing information */
5
6/**
7 * \file process.h
8 * \brief Header for process.c
9 **/
10
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
18#include <stdbool.h>
19
20/** Maximum number of bytes to write to a process' stdin. */
21#define PROCESS_MAX_WRITE (1024)
22
23/** Maximum number of bytes to read from a process' stdout/stderr. */
24#define PROCESS_MAX_READ (1024)
25
26typedef enum {
27 /** The process is not running. */
29
30 /** The process is running. */
32
33 /** The process is in an erroneous state. */
36
38
39typedef enum {
40 /** Pass complete newline-terminated lines to the
41 * callback (with the LF or CRLF removed). */
43
44 /** Pass the raw response from read() to the callback. */
47
49
51
52struct smartlist_t;
53
54struct process_t;
55typedef struct process_t process_t;
56
57typedef uint64_t process_exit_code_t;
58typedef uint64_t process_pid_t;
59
60typedef void (*process_read_callback_t)(process_t *,
61 const char *,
62 size_t);
63typedef bool
64(*process_exit_callback_t)(process_t *, process_exit_code_t);
65
66void process_init(void);
67void process_free_all(void);
68const struct smartlist_t *process_get_all_processes(void);
69
70process_t *process_new(const char *command);
71void process_free_(process_t *process);
72#define process_free(s) FREE_AND_NULL(process_t, process_free_, (s))
73
75bool process_terminate(process_t *process);
76
77process_pid_t process_get_pid(process_t *process);
78
80 process_read_callback_t);
82 process_read_callback_t);
84 process_exit_callback_t);
85
86const char *process_get_command(const process_t *process);
87
88void process_append_argument(process_t *process, const char *argument);
89const struct smartlist_t *process_get_arguments(const process_t *process);
90char **process_get_argv(const process_t *process);
91
93 const struct smartlist_t *env);
95 const char *key,
96 const char *value);
97
100
101void process_set_protocol(process_t *process, process_protocol_t protocol);
103
104void process_set_data(process_t *process, void *data);
105void *process_get_data(const process_t *process);
106
107void process_set_status(process_t *process, process_status_t status);
109
110#ifndef _WIN32
111struct process_unix_t;
113#else
114struct process_win32_t;
115struct process_win32_t *process_get_win32_process(const process_t *process);
116#endif /* !defined(_WIN32) */
117
118void process_write(process_t *process,
119 const uint8_t *data, size_t size);
120void process_vprintf(process_t *process,
121 const char *format, va_list args) CHECK_PRINTF(2, 0);
122void process_printf(process_t *process,
123 const char *format, ...) CHECK_PRINTF(2, 3);
124
129 process_exit_code_t);
130
131#ifdef PROCESS_PRIVATE
132struct buf_t;
133MOCK_DECL(STATIC int, process_read_stdout, (process_t *, struct buf_t *));
134MOCK_DECL(STATIC int, process_read_stderr, (process_t *, struct buf_t *));
135MOCK_DECL(STATIC void, process_write_stdin, (process_t *, struct buf_t *));
136
138 struct buf_t *buffer,
139 process_read_callback_t callback);
141 struct buf_t *buffer,
142 process_read_callback_t callback);
144 struct buf_t *buffer,
145 process_read_callback_t callback);
146#endif /* defined(PROCESS_PRIVATE) */
147
148#endif /* !defined(TOR_PROCESS_H) */
tor_cmdline_mode_t command
Definition: config.c:2468
Headers for util_malloc.c.
Header for printf.c.
STATIC void process_read_data(process_t *process, buf_t *buffer, process_read_callback_t callback)
Definition: process.c:695
STATIC void process_write_stdin(process_t *process, buf_t *buffer)
Definition: process.c:678
STATIC void process_read_lines(process_t *process, buf_t *buffer, process_read_callback_t callback)
Definition: process.c:749
STATIC void process_read_buffer(process_t *process, buf_t *buffer, process_read_callback_t callback)
Definition: process.c:722
void process_reset_environment(process_t *process, const smartlist_t *env)
Definition: process.c:470
STATIC int process_read_stdout(process_t *process, buf_t *buffer)
Definition: process.c:648
STATIC int process_read_stderr(process_t *process, buf_t *buffer)
Definition: process.c:663
void process_notify_event_stdout(process_t *process)
Definition: process.c:577
void process_set_data(process_t *process, void *data)
Definition: process.c:385
void process_write(process_t *process, const uint8_t *data, size_t size)
Definition: process.c:530
const char * process_protocol_to_string(process_protocol_t protocol)
Definition: process.c:112
void process_notify_event_stderr(process_t *process)
Definition: process.c:594
void process_free_(process_t *process)
Definition: process.c:217
const struct smartlist_t * process_get_all_processes(void)
Definition: process.c:166
void process_set_status(process_t *process, process_status_t status)
Definition: process.c:403
void process_set_environment(process_t *process, const char *key, const char *value)
Definition: process.c:487
const char * process_status_to_string(process_status_t status)
Definition: process.c:92
void process_append_argument(process_t *process, const char *argument)
Definition: process.c:419
const char * process_get_command(const process_t *process)
Definition: process.c:356
void process_set_exit_callback(process_t *, process_exit_callback_t)
Definition: process.c:347
void * process_get_data(const process_t *process)
Definition: process.c:395
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
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
void process_notify_event_exit(process_t *process, process_exit_code_t)
Definition: process.c:623
void process_init(void)
Definition: process.c:141
const struct smartlist_t * process_get_arguments(const process_t *process)
Definition: process.c:430
void process_set_stdout_read_callback(process_t *, process_read_callback_t)
Definition: process.c:321
process_protocol_t process_get_protocol(const process_t *process)
Definition: process.c:371
process_protocol_t
Definition: process.h:39
@ PROCESS_PROTOCOL_LINE
Definition: process.h:42
@ PROCESS_PROTOCOL_RAW
Definition: process.h:45
struct process_environment_t * process_get_environment(const process_t *)
Definition: process.c:501
void tor_disable_spawning_background_processes(void)
Definition: process.c:132
process_status_t process_get_status(const process_t *process)
Definition: process.c:411
bool process_terminate(process_t *process)
Definition: process.c:284
void process_notify_event_stdin(process_t *process)
Definition: process.c:610
void process_printf(process_t *process, const char *format,...)
Definition: process.c:561
process_status_t
Definition: process.h:26
@ PROCESS_STATUS_NOT_RUNNING
Definition: process.h:28
@ PROCESS_STATUS_RUNNING
Definition: process.h:31
@ PROCESS_STATUS_ERROR
Definition: process.h:34
process_status_t process_exec(process_t *process)
Definition: process.c:253
process_t * process_new(const char *command)
Definition: process.c:180
process_pid_t process_get_pid(process_t *process)
Definition: process.c:303
char ** process_get_argv(const process_t *process)
Definition: process.c:439
#define STATIC
Definition: testsupport.h:32
#define MOCK_DECL(rv, funcname, arglist)
Definition: testsupport.h:127