File: pipeline-private.h

package info (click to toggle)
libpipeline 1.5.8-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,048 kB
  • sloc: ansic: 34,415; sh: 5,519; makefile: 168
file content (157 lines) | stat: -rw-r--r-- 4,275 bytes parent folder | download | duplicates (2)
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
 * Copyright (C) 2001-2017 Colin Watson.
 *
 * This file is part of libpipeline.
 *
 * libpipeline is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or (at
 * your option) any later version.
 *
 * libpipeline is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with libpipeline; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
 * USA.
 */

#ifndef PIPELINE_PRIVATE_H
#define PIPELINE_PRIVATE_H

#include "pipeline.h"

/* exit codes */
#define OK 0    /* success */
#define FAIL 1  /* usage or syntax error */
#define FATAL 2 /* operational error */

extern char *appendstr (char *, ...)
        PIPELINE_ATTR_SENTINEL PIPELINE_ATTR_WARN_UNUSED_RESULT;

extern void init_debug (void);
extern int debug_level;
extern void debug (const char *message, ...)
        PIPELINE_ATTR_FORMAT_PRINTF (1, 2);

#if defined(HAVE_SETENV) && !defined(HAVE_CLEARENV)
extern int clearenv (void);
#endif

enum pipecmd_tag {
	PIPECMD_PROCESS,
	PIPECMD_FUNCTION,
	PIPECMD_SEQUENCE
};

struct pipecmd_env {
	char *name;
	char *value;
};

struct pipecmd {
	enum pipecmd_tag tag;
	char *name;
	int nice;
	int discard_err; /* discard stderr? */
	int cwd_fd;
	char *cwd;
	int nenv;
	int env_max; /* size of allocated array */
	struct pipecmd_env *env;
	pipecmd_function_type *pre_exec_func;
	pipecmd_function_type *pre_exec_free_func;
	void *pre_exec_data;
	union {
		struct pipecmd_process {
			int argc;
			int argv_max; /* size of allocated array */
			char **argv;
		} process;
		struct pipecmd_function {
			pipecmd_function_type *func;
			pipecmd_function_free_type *free_func;
			void *data;
		} function;
		struct pipecmd_sequence {
			int ncommands;
			int commands_max;
			struct pipecmd **commands;
		} sequence;
	} u;
};

enum pipeline_redirect {
	REDIRECT_NONE,
	REDIRECT_FD,
	REDIRECT_FILE_NAME
};

struct pipeline {
	int ncommands;
	int commands_max; /* size of allocated array */
	pipecmd **commands;
	pid_t *pids;
	int *statuses; /* -1 until command exits */

	/* REDIRECT_NONE for no redirection; REDIRECT_FD for redirection
	 * from/to file descriptor; REDIRECT_FILE_NAME for redirection
	 * from/to file name.
	 */
	enum pipeline_redirect redirect_in, redirect_out;

	/* If non-negative, these contain caller-supplied file descriptors
	 * for the input and output of the whole pipeline.  If negative,
	 * pipeline_start() will create pipes and store the input writing
	 * half and the output reading half in infd and outfd as
	 * appropriate.
	 */
	int want_in, want_out;

	/* If non-NULL, these contain files to open and use as the input and
	 * output of the whole pipeline.  These are only used if want_in or
	 * want_out respectively is zero.  The value of using these rather
	 * than simply opening the files before starting the pipeline is
	 * that the files will be opened with the same privileges under
	 * which the pipeline is being run.
	 */
	char *want_infile, *want_outfile;

	/* See above. Default to -1. The caller should consider these
	 * read-only.
	 */
	int infd, outfd;

	/* Set by pipeline_get_infile() and pipeline_get_outfile()
	 * respectively. Default to NULL.
	 */
	FILE *infile, *outfile;

	/* Set by pipeline_connect() to record that this pipeline reads its
	 * input from another pipeline. Defaults to NULL.
	 */
	struct pipeline *source;

	/* Private buffer for use by read/peek functions. */
	char *buffer;
	size_t buflen, bufmax;

	/* The last line returned by readline/peekline. Private. */
	char *line_cache;

	/* The amount of data at the end of buffer which has been
	 * read-ahead, either by an explicit peek or by readline/peekline
	 * reading a block at a time to save work. Private.
	 */
	size_t peek_offset;

	/* If set, ignore SIGINT and SIGQUIT while the pipeline is running,
	 * like system(). Defaults to 1.
	 */
	int ignore_signals;
};

#endif /* PIPELINE_PRIVATE_H */