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