WvStreams
Public Member Functions | Private Member Functions | Private Attributes
WvSystem Class Reference

WvSystem is a mostly-replacement for the libc system() function call, which people usually use because of its notational convenience, not because it calls the Unix shell. More...

#include <wvsystem.h>

Inheritance diagram for WvSystem:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 WvSystem (const char cmd[], const char *a0=NULL, const char *a1=NULL, const char *a2=NULL, const char *a3=NULL, const char *a4=NULL, const char *a5=NULL, const char *a6=NULL, const char *a7=NULL, const char *a8=NULL, const char *a9=NULL, const char *a10=NULL, const char *a11=NULL, const char *a12=NULL, const char *a13=NULL, const char *a14=NULL, const char *a15=NULL, const char *a16=NULL, const char *a17=NULL, const char *a18=NULL, const char *a19=NULL)
 Construct a WvSystem from a simple list of strings.
 WvSystem (const char *const *argv)
 Construct a WvSystem from an argv array.
virtual ~WvSystem ()
 Destroy the WvSystem object.
int go ()
 Explicitly start the command running and wait for it to finish.
WvSysteminfile (WvStringParm filename)
 Redirect stdin from the given input file.
WvSystemoutfile (WvStringParm filename)
 Redirect stdout to the given output file, which is overwritten.
WvSystemerrfile (WvStringParm filename)
 Redirect stderr to the given output file, which is overwritten.

Private Member Functions

 DeclareWvList (pid_t)
void prepare (const char cmd[],...)
void preparev (const char cmd[], va_list ap)
void preparev (const char cmd[], const char *const *argv)
void preparev (const char cmd[], WvStringList &)
int start (const char cmd[],...)
int startv (const char cmd[], const char *const *argv)
virtual int start_again ()
virtual void stop (time_t msec_delay, bool kill_children=true)
virtual void wait (time_t msec_delay, bool wait_children=true)
pid_t pidfile_pid ()
void setMemLimit (int megs)
 Sets a limit on the number of megabytes of memory the subprocess will.
void kill (int sig)
void kill_primary (int sig)
virtual void suspend ()
virtual void resume ()

Private Attributes

pid_tList old_pids
pid_t pid
bool running
int estatus
WvString pidfile
WvString last_cmd
WvString app
WvStringList last_args
WvStringList env

Detailed Description

WvSystem is a mostly-replacement for the libc system() function call, which people usually use because of its notational convenience, not because it calls the Unix shell.

In fact, some people don't even realize it calls the shell, leading to security holes when people forget to quote user-provided parameters correctly.

WvSystem() uses WvSubProc but makes sure it can be called in a single line of C++ code with a minimum of fluff. For example:

WvSystem("rm", "-rf", filename, NULL); is like system(WvString("rm -rf %s", filename)); except that you don't have weird security bugs if "filename" contains special characters like newline, space, quotation mark, etc.

See WvSubProc and WvSubProcQueue for less concise, but more flexible ways to run subprograms.

Definition at line 29 of file wvsystem.h.


Constructor & Destructor Documentation

WvSystem::WvSystem ( const char  cmd[],
const char *  a0 = NULL,
const char *  a1 = NULL,
const char *  a2 = NULL,
const char *  a3 = NULL,
const char *  a4 = NULL,
const char *  a5 = NULL,
const char *  a6 = NULL,
const char *  a7 = NULL,
const char *  a8 = NULL,
const char *  a9 = NULL,
const char *  a10 = NULL,
const char *  a11 = NULL,
const char *  a12 = NULL,
const char *  a13 = NULL,
const char *  a14 = NULL,
const char *  a15 = NULL,
const char *  a16 = NULL,
const char *  a17 = NULL,
const char *  a18 = NULL,
const char *  a19 = NULL 
) [inline]

Construct a WvSystem from a simple list of strings.

For example: WvSystem("rm", "-rf", dirname);

Note: this is unlike WvSubProc::prepare(cmd, ...) because you don't need to provide argv[0] yourself. "cmd" is automatically inserted as argv[0]. It also lets you pass WvString objects in without manually calling cstr(), because it doesn't use varargs. Unfortunately, that means it's limited to 20 arguments.

Definition at line 44 of file wvsystem.h.

WvSystem::WvSystem ( const char *const *  argv) [inline]

Construct a WvSystem from an argv array.

This is exactly the same as WvSubProc's argv[] constructor, but the command name is always taken from argv[0] rather than provided separately.

For example: const char *argv[] = { "rm", "-rf", dirname, NULL }; WvSystem(argv);

Definition at line 86 of file wvsystem.h.

WvSystem::~WvSystem ( ) [virtual]

Destroy the WvSystem object.

If you haven't yet called go(), the command is run before destruction.

Definition at line 12 of file wvsystem.cc.

References go().


Member Function Documentation

int WvSystem::go ( )

Explicitly start the command running and wait for it to finish.

This will happen automatically at object destruction time, but if you want to check the return code, you'll need to call go().

Definition at line 59 of file wvsystem.cc.

Referenced by ~WvSystem().

Redirect stdin from the given input file.

Definition at line 71 of file wvsystem.cc.

Redirect stdout to the given output file, which is overwritten.

Definition at line 78 of file wvsystem.cc.

Redirect stderr to the given output file, which is overwritten.

Definition at line 85 of file wvsystem.cc.


The documentation for this class was generated from the following files: