1 /* 2 * $Id: pipe.h 769 2007-10-24 00:15:40Z hubert@u.washington.edu $ 3 * 4 * ======================================================================== 5 * Copyright 2013-2021 Eduardo Chappa 6 * Copyright 2006 University of Washington 7 * 8 * Licensed under the Apache License, Version 2.0 (the "License"); 9 * you may not use this file except in compliance with the License. 10 * You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * ======================================================================== 15 */ 16 17 #ifndef PITH_OSDEP_PIPE_INCLUDED 18 #define PITH_OSDEP_PIPE_INCLUDED 19 20 /* Standard I/O File Descriptor Definitions */ 21 #ifndef STDIN_FILENO 22 #define STDIN_FILENO 0 23 #endif 24 #ifndef STDOUT_FILENO 25 #define STDOUT_FILENO 1 26 #endif 27 #ifndef STDERR_FILENO 28 #define STDERR_FILENO 2 29 #endif 30 31 32 /* 33 * Flags for the pipe command routines... 34 */ 35 #define PIPE_WRITE 0x0001 /* set up pipe for reading */ 36 #define PIPE_READ 0x0002 /* set up pipe for reading */ 37 #define PIPE_NOSHELL 0x0004 /* don't exec in shell */ 38 #define PIPE_USER 0x0008 /* user mode */ 39 #define PIPE_STDERR 0x0010 /* stderr to child output */ 40 #define PIPE_PROT 0x0020 /* protected mode */ 41 #define PIPE_RESET 0x0040 /* reset terminal mode */ 42 #define PIPE_DESC 0x0080 /* no stdio desc wrapping */ 43 #define PIPE_SILENT 0x0100 /* no screen clear, etc */ 44 #define PIPE_RUNNOW 0x0200 /* don't wait for child (PC-Pine) */ 45 #define PIPE_RAW 0x0400 /* don't convert to locale */ 46 #define PIPE_NONEWMAIL 0x0800 /* don't call new_mail */ 47 48 #ifdef _WINDOWS 49 /* 50 * Flags for mswin_exec_and_wait 51 */ 52 #define MSWIN_EAW_CAPT_STDERR 0x0001 53 #define MSWIN_EAW_CTRL_C_CANCELS 0x0002 54 #endif 55 56 57 /* 58 * Reaper flags 59 */ 60 #define PR_NONE 0x0000 61 #ifdef WNOHANG 62 #define PR_NOHANG 0x0001 63 #endif 64 65 /* 66 * open_system_pipe callback so caller can insert code, typically interface 67 * stuff right before/after the fork and before/after wait 68 */ 69 #define OSB_PRE_OPEN 0x0001 70 #define OSB_POST_OPEN 0x0002 71 #define OSB_PRE_CLOSE 0x0004 72 #define OSB_POST_CLOSE 0x0008 73 74 /* 75 * structure required for the pipe commands... 76 */ 77 typedef struct pipe_s { 78 pid_t pid; /* child's process id */ 79 int mode, /* mode flags used to open */ 80 timeout, /* wait this long for child */ 81 old_timeo; /* previous active alarm */ 82 RETSIGTYPE (*hsig)(int), /* previously installed... */ 83 (*isig)(int), /* handlers */ 84 (*qsig)(int), 85 (*alrm)(int), 86 (*chld)(int); 87 union { 88 FILE *f; 89 int d; 90 } in; /* input data handle */ 91 union { 92 FILE *f; 93 int d; 94 } out; /* output data handle */ 95 char **argv, /* any necessary args */ 96 *args, 97 *tmp; /* pointer to stuff */ 98 #ifdef _WINDOWS 99 char *infile; /* file containing pipe's stdin */ 100 char *outfile; /* file containing pipe's stdout */ 101 char *command; /* command to execute */ 102 int exit_code; /* proc rv if run right away */ 103 int deloutfile; /* need to rm outfile at close */ 104 #endif 105 } PIPE_S; 106 107 108 /* 109 * Exported Prototypes 110 */ 111 PIPE_S *open_system_pipe(char *, char **, char **, int, int, 112 void (*)(PIPE_S *, int, void *), void (*)(char *)); 113 int close_system_pipe(PIPE_S **, int *, void (*)(PIPE_S *, int, void *)); 114 int pipe_close_write(PIPE_S *); 115 pid_t process_reap(pid_t, int *, int); 116 117 118 #endif /* PITH_OSDEP_PIPE_INCLUDED */ 119