| 1 | 
schorsch | 
3.4 | 
/* RCSid $Id: rtprocess.h,v 3.3 2003/07/14 20:02:29 schorsch Exp $ */ | 
| 2 | 
schorsch | 
3.1 | 
/* | 
| 3 | 
  | 
  | 
 *   rtprocess.h  | 
| 4 | 
  | 
  | 
 *   Routines to communicate with separate process via dual pipes | 
| 5 | 
  | 
  | 
 * | 
| 6 | 
  | 
  | 
 *   WARNING: On Windows, there's a system header named <process.h>. | 
| 7 | 
  | 
  | 
 */ | 
| 8 | 
  | 
  | 
#ifndef _RAD_PROCESS_H_ | 
| 9 | 
  | 
  | 
#define _RAD_PROCESS_H_ | 
| 10 | 
  | 
  | 
 | 
| 11 | 
schorsch | 
3.3 | 
#include  <errno.h> | 
| 12 | 
schorsch | 
3.1 | 
#ifdef _WIN32 | 
| 13 | 
schorsch | 
3.3 | 
  #include <windows.h> /* DWORD etc. */ | 
| 14 | 
  | 
  | 
  typedef DWORD pid_t; | 
| 15 | 
  | 
  | 
  #include <process.h> /* getpid() and others */ | 
| 16 | 
schorsch | 
3.1 | 
#else | 
| 17 | 
  | 
  | 
  #include <sys/param.h> | 
| 18 | 
  | 
  | 
#endif | 
| 19 | 
  | 
  | 
 | 
| 20 | 
  | 
  | 
#include "paths.h" | 
| 21 | 
  | 
  | 
 | 
| 22 | 
schorsch | 
3.4 | 
#ifdef __cplusplus | 
| 23 | 
  | 
  | 
extern "C" { | 
| 24 | 
  | 
  | 
#endif | 
| 25 | 
schorsch | 
3.1 | 
 | 
| 26 | 
  | 
  | 
/* On Windows, a process ID is a DWORD. That might actually be the | 
| 27 | 
  | 
  | 
   same thing as an int, but it's better not to assume anything. | 
| 28 | 
  | 
  | 
 | 
| 29 | 
  | 
  | 
   This means that we shouldn't rely on PIDs and file descriptors | 
| 30 | 
  | 
  | 
   being the same type, so we have to describe processes with a struct, | 
| 31 | 
  | 
  | 
   instead of the original int[3]. To keep things simple, we typedef | 
| 32 | 
  | 
  | 
   the posix pid_t on those systems that don't have it already. | 
| 33 | 
  | 
  | 
 | 
| 34 | 
  | 
  | 
   Some older Windows systems use negative PIDs. Open_process() and | 
| 35 | 
  | 
  | 
   close_process() will convert those to positive values during | 
| 36 | 
  | 
  | 
   runtime, so that client modules can still use -1 as invalid PID. | 
| 37 | 
  | 
  | 
*/ | 
| 38 | 
  | 
  | 
 | 
| 39 | 
  | 
  | 
 | 
| 40 | 
  | 
  | 
#ifndef PIPE_BUF | 
| 41 | 
  | 
  | 
  #ifdef PIPSIZ | 
| 42 | 
  | 
  | 
    #define PIPE_BUF    PIPSIZ | 
| 43 | 
  | 
  | 
  #else | 
| 44 | 
  | 
  | 
    #ifdef PIPE_MAX | 
| 45 | 
  | 
  | 
      #define PIPE_BUF  PIPE_MAX | 
| 46 | 
  | 
  | 
    #else | 
| 47 | 
  | 
  | 
      #define PIPE_BUF  512             /* hyperconservative */ | 
| 48 | 
  | 
  | 
    #endif | 
| 49 | 
  | 
  | 
  #endif | 
| 50 | 
  | 
  | 
#endif | 
| 51 | 
  | 
  | 
 | 
| 52 | 
  | 
  | 
typedef struct { | 
| 53 | 
  | 
  | 
        int r; /* read handle */ | 
| 54 | 
  | 
  | 
        int w; /* write handle */ | 
| 55 | 
  | 
  | 
        int running; /* doing something */ | 
| 56 | 
  | 
  | 
        pid_t pid; /* process ID */ | 
| 57 | 
  | 
  | 
} SUBPROC; | 
| 58 | 
  | 
  | 
 | 
| 59 | 
  | 
  | 
#define SP_INACTIVE {-1,-1,0,0} /* for static initializations */ | 
| 60 | 
  | 
  | 
 | 
| 61 | 
  | 
  | 
extern int open_process(SUBPROC *pd, char *av[]); | 
| 62 | 
  | 
  | 
extern int close_process(SUBPROC *pd); | 
| 63 | 
  | 
  | 
extern int process(SUBPROC *pd, char *recvbuf, char *sendbuf, int nbr, int nbs); | 
| 64 | 
  | 
  | 
extern int readbuf(int fd, char *bpos, int siz); | 
| 65 | 
  | 
  | 
extern int writebuf(int fd, char *bpos, int siz); | 
| 66 | 
  | 
  | 
 | 
| 67 | 
  | 
  | 
 | 
| 68 | 
  | 
  | 
#ifdef __cplusplus | 
| 69 | 
  | 
  | 
} | 
| 70 | 
  | 
  | 
#endif | 
| 71 | 
  | 
  | 
#endif /* _RAD_PROCESS_H_ */ | 
| 72 | 
  | 
  | 
 |