OSF DCE Application Development Guide--Core Components

OSF DCE Application Development Guide—Core Components
16.4.2 Output Pipes
An [out] pipe is implemented in a similar way to an input pipe, except that the client and
server make use of the push routine instead of the pull routine. The following samples
show an [out] pipe used to read the output from a shell command executed by the server.
The declarations in the interface definition are as follows:
typedef pipe char test_pipe_t;
void pipe_test2(
[in] handle_t handle,
[in, string] char cmd[],
[out] test_pipe_t *test_pipe,
[out] error_status_t *status
);
The server manager routines demonstrate a couple of possible implementations. In each
case, the manager makes a cycle of calls to the server stub’s push routine, ending by
pushing a zero-length chunk:
#include <dirent.h>
#define SBUFFSIZE 256
void
pipe_test2(
handle_t binding_h,
idl_char *cmd,
test_pipe_t *test_pipe,
error_status_t *status
)
{
DIR *dir_ptr;
struct dirent *directory;
char buffer[SBUFFSIZE];
FILE *str_ptr;
int n;
/* An elementary mechanism to execute a command and get
* the output back. Note that popen() and fread() are
* thread-safe, so the whole process won’t block while
* the call thread waits for them to return.
*
* This is potentially a dangerous operation!
* Here we’ll only allow a couple of "safe" commands.
*/
if (!strcmp(cmd, "ps") || !strcmp(cmd, "ls"))
16 28 Tandem Computers Incorporated 124245