|
Packit Service |
51e54d |
/*
|
|
Packit Service |
51e54d |
* Copyright (C) 2001-2017 Colin Watson.
|
|
Packit Service |
51e54d |
*
|
|
Packit Service |
51e54d |
* This file is part of libpipeline.
|
|
Packit Service |
51e54d |
*
|
|
Packit Service |
51e54d |
* libpipeline is free software; you can redistribute it and/or modify
|
|
Packit Service |
51e54d |
* it under the terms of the GNU General Public License as published by
|
|
Packit Service |
51e54d |
* the Free Software Foundation; either version 2 of the License, or (at
|
|
Packit Service |
51e54d |
* your option) any later version.
|
|
Packit Service |
51e54d |
*
|
|
Packit Service |
51e54d |
* libpipeline is distributed in the hope that it will be useful, but
|
|
Packit Service |
51e54d |
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
51e54d |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
51e54d |
* General Public License for more details.
|
|
Packit Service |
51e54d |
*
|
|
Packit Service |
51e54d |
* You should have received a copy of the GNU General Public License
|
|
Packit Service |
51e54d |
* along with libpipeline; if not, write to the Free Software
|
|
Packit Service |
51e54d |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
|
|
Packit Service |
51e54d |
* USA.
|
|
Packit Service |
51e54d |
*/
|
|
Packit Service |
51e54d |
|
|
Packit Service |
51e54d |
#ifndef PIPELINE_PRIVATE_H
|
|
Packit Service |
51e54d |
#define PIPELINE_PRIVATE_H
|
|
Packit Service |
51e54d |
|
|
Packit Service |
51e54d |
#include "pipeline.h"
|
|
Packit Service |
51e54d |
|
|
Packit Service |
51e54d |
/* exit codes */
|
|
Packit Service |
51e54d |
#define OK 0 /* success */
|
|
Packit Service |
51e54d |
#define FAIL 1 /* usage or syntax error */
|
|
Packit Service |
51e54d |
#define FATAL 2 /* operational error */
|
|
Packit Service |
51e54d |
|
|
Packit Service |
51e54d |
extern char *appendstr (char *, ...)
|
|
Packit Service |
51e54d |
PIPELINE_ATTR_SENTINEL PIPELINE_ATTR_WARN_UNUSED_RESULT;
|
|
Packit Service |
51e54d |
|
|
Packit Service |
51e54d |
extern void init_debug (void);
|
|
Packit Service |
51e54d |
extern int debug_level;
|
|
Packit Service |
51e54d |
extern void debug (const char *message, ...) PIPELINE_ATTR_FORMAT_PRINTF(1, 2);
|
|
Packit Service |
51e54d |
|
|
Packit Service |
51e54d |
#if defined(HAVE_SETENV) && !defined(HAVE_CLEARENV)
|
|
Packit Service |
51e54d |
extern int clearenv (void);
|
|
Packit Service |
51e54d |
#endif
|
|
Packit Service |
51e54d |
|
|
Packit Service |
51e54d |
enum pipecmd_tag {
|
|
Packit Service |
51e54d |
PIPECMD_PROCESS,
|
|
Packit Service |
51e54d |
PIPECMD_FUNCTION,
|
|
Packit Service |
51e54d |
PIPECMD_SEQUENCE
|
|
Packit Service |
51e54d |
};
|
|
Packit Service |
51e54d |
|
|
Packit Service |
51e54d |
struct pipecmd_env {
|
|
Packit Service |
51e54d |
char *name;
|
|
Packit Service |
51e54d |
char *value;
|
|
Packit Service |
51e54d |
};
|
|
Packit Service |
51e54d |
|
|
Packit Service |
51e54d |
struct pipecmd {
|
|
Packit Service |
51e54d |
enum pipecmd_tag tag;
|
|
Packit Service |
51e54d |
char *name;
|
|
Packit Service |
51e54d |
int nice;
|
|
Packit Service |
51e54d |
int discard_err; /* discard stderr? */
|
|
Packit Service |
51e54d |
int cwd_fd;
|
|
Packit Service |
51e54d |
char *cwd;
|
|
Packit Service |
51e54d |
int nenv;
|
|
Packit Service |
51e54d |
int env_max; /* size of allocated array */
|
|
Packit Service |
51e54d |
struct pipecmd_env *env;
|
|
Packit Service |
51e54d |
pipecmd_function_type *pre_exec_func;
|
|
Packit Service |
51e54d |
pipecmd_function_type *pre_exec_free_func;
|
|
Packit Service |
51e54d |
void *pre_exec_data;
|
|
Packit Service |
51e54d |
union {
|
|
Packit Service |
51e54d |
struct pipecmd_process {
|
|
Packit Service |
51e54d |
int argc;
|
|
Packit Service |
51e54d |
int argv_max; /* size of allocated array */
|
|
Packit Service |
51e54d |
char **argv;
|
|
Packit Service |
51e54d |
} process;
|
|
Packit Service |
51e54d |
struct pipecmd_function {
|
|
Packit Service |
51e54d |
pipecmd_function_type *func;
|
|
Packit Service |
51e54d |
pipecmd_function_free_type *free_func;
|
|
Packit Service |
51e54d |
void *data;
|
|
Packit Service |
51e54d |
} function;
|
|
Packit Service |
51e54d |
struct pipecmd_sequence {
|
|
Packit Service |
51e54d |
int ncommands;
|
|
Packit Service |
51e54d |
int commands_max;
|
|
Packit Service |
51e54d |
struct pipecmd **commands;
|
|
Packit Service |
51e54d |
} sequence;
|
|
Packit Service |
51e54d |
} u;
|
|
Packit Service |
51e54d |
};
|
|
Packit Service |
51e54d |
|
|
Packit Service |
51e54d |
enum pipeline_redirect {
|
|
Packit Service |
51e54d |
REDIRECT_NONE,
|
|
Packit Service |
51e54d |
REDIRECT_FD,
|
|
Packit Service |
51e54d |
REDIRECT_FILE_NAME
|
|
Packit Service |
51e54d |
};
|
|
Packit Service |
51e54d |
|
|
Packit Service |
51e54d |
struct pipeline {
|
|
Packit Service |
51e54d |
int ncommands;
|
|
Packit Service |
51e54d |
int commands_max; /* size of allocated array */
|
|
Packit Service |
51e54d |
pipecmd **commands;
|
|
Packit Service |
51e54d |
pid_t *pids;
|
|
Packit Service |
51e54d |
int *statuses; /* -1 until command exits */
|
|
Packit Service |
51e54d |
|
|
Packit Service |
51e54d |
/* REDIRECT_NONE for no redirection; REDIRECT_FD for redirection
|
|
Packit Service |
51e54d |
* from/to file descriptor; REDIRECT_FILE_NAME for redirection
|
|
Packit Service |
51e54d |
* from/to file name.
|
|
Packit Service |
51e54d |
*/
|
|
Packit Service |
51e54d |
enum pipeline_redirect redirect_in, redirect_out;
|
|
Packit Service |
51e54d |
|
|
Packit Service |
51e54d |
/* If non-negative, these contain caller-supplied file descriptors
|
|
Packit Service |
51e54d |
* for the input and output of the whole pipeline. If negative,
|
|
Packit Service |
51e54d |
* pipeline_start() will create pipes and store the input writing
|
|
Packit Service |
51e54d |
* half and the output reading half in infd and outfd as
|
|
Packit Service |
51e54d |
* appropriate.
|
|
Packit Service |
51e54d |
*/
|
|
Packit Service |
51e54d |
int want_in, want_out;
|
|
Packit Service |
51e54d |
|
|
Packit Service |
51e54d |
/* If non-NULL, these contain files to open and use as the input and
|
|
Packit Service |
51e54d |
* output of the whole pipeline. These are only used if want_in or
|
|
Packit Service |
51e54d |
* want_out respectively is zero. The value of using these rather
|
|
Packit Service |
51e54d |
* than simply opening the files before starting the pipeline is
|
|
Packit Service |
51e54d |
* that the files will be opened with the same privileges under
|
|
Packit Service |
51e54d |
* which the pipeline is being run.
|
|
Packit Service |
51e54d |
*/
|
|
Packit Service |
51e54d |
char *want_infile, *want_outfile;
|
|
Packit Service |
51e54d |
|
|
Packit Service |
51e54d |
/* See above. Default to -1. The caller should consider these
|
|
Packit Service |
51e54d |
* read-only.
|
|
Packit Service |
51e54d |
*/
|
|
Packit Service |
51e54d |
int infd, outfd;
|
|
Packit Service |
51e54d |
|
|
Packit Service |
51e54d |
/* Set by pipeline_get_infile() and pipeline_get_outfile()
|
|
Packit Service |
51e54d |
* respectively. Default to NULL.
|
|
Packit Service |
51e54d |
*/
|
|
Packit Service |
51e54d |
FILE *infile, *outfile;
|
|
Packit Service |
51e54d |
|
|
Packit Service |
51e54d |
/* Set by pipeline_connect() to record that this pipeline reads its
|
|
Packit Service |
51e54d |
* input from another pipeline. Defaults to NULL.
|
|
Packit Service |
51e54d |
*/
|
|
Packit Service |
51e54d |
struct pipeline *source;
|
|
Packit Service |
51e54d |
|
|
Packit Service |
51e54d |
/* Private buffer for use by read/peek functions. */
|
|
Packit Service |
51e54d |
char *buffer;
|
|
Packit Service |
51e54d |
size_t buflen, bufmax;
|
|
Packit Service |
51e54d |
|
|
Packit Service |
51e54d |
/* The last line returned by readline/peekline. Private. */
|
|
Packit Service |
51e54d |
char *line_cache;
|
|
Packit Service |
51e54d |
|
|
Packit Service |
51e54d |
/* The amount of data at the end of buffer which has been
|
|
Packit Service |
51e54d |
* read-ahead, either by an explicit peek or by readline/peekline
|
|
Packit Service |
51e54d |
* reading a block at a time to save work. Private.
|
|
Packit Service |
51e54d |
*/
|
|
Packit Service |
51e54d |
size_t peek_offset;
|
|
Packit Service |
51e54d |
|
|
Packit Service |
51e54d |
/* If set, ignore SIGINT and SIGQUIT while the pipeline is running,
|
|
Packit Service |
51e54d |
* like system(). Defaults to 1.
|
|
Packit Service |
51e54d |
*/
|
|
Packit Service |
51e54d |
int ignore_signals;
|
|
Packit Service |
51e54d |
};
|
|
Packit Service |
51e54d |
|
|
Packit Service |
51e54d |
#endif /* PIPELINE_PRIVATE_H */
|