aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/process.cpp49
-rw-r--r--src/process.h18
2 files changed, 67 insertions, 0 deletions
diff --git a/src/process.cpp b/src/process.cpp
index 8ea6ce3..b3f2801 100644
--- a/src/process.cpp
+++ b/src/process.cpp
@@ -61,6 +61,51 @@ Bu::Process::Process( Flags eFlags, const char *sName, const char *argv, ...) :
61 delete[] list; 61 delete[] list;
62} 62}
63 63
64Bu::Process::Process( Flags eFlags, const Bu::Process::Options &opt, const char *sName, char *const argv[] ) :
65 iStdIn( -1 ),
66 iStdOut( -1 ),
67 iStdErr( -1 ),
68 iPid( 0 ),
69 iProcStatus( 0 ),
70 bBlocking( true ),
71 bStdOutEos( true ),
72 bStdErrEos( true ),
73 opt( opt )
74{
75 gexec( eFlags, sName, argv );
76}
77
78Bu::Process::Process( Flags eFlags, const Bu::Process::Options &opt, const char *sName, const char *argv, ...) :
79 iStdIn( -1 ),
80 iStdOut( -1 ),
81 iStdErr( -1 ),
82 iPid( 0 ),
83 iProcStatus( 0 ),
84 bBlocking( true ),
85 bStdOutEos( true ),
86 bStdErrEos( true ),
87 opt( opt )
88{
89 int iCnt = 0;
90 va_list ap;
91 va_start( ap, argv );
92 for(; va_arg( ap, const char *); iCnt++ ) { }
93 va_end( ap );
94
95 char const **list = new char const *[iCnt+2];
96 va_start( ap, argv );
97 list[0] = argv;
98 for( int j = 1; j <= iCnt; j++ )
99 {
100 list[j] = va_arg( ap, const char *);
101 }
102 list[iCnt+1] = NULL;
103 va_end( ap );
104
105 gexec( eFlags, sName, (char *const *)list );
106 delete[] list;
107}
108
64Bu::Process::~Process() 109Bu::Process::~Process()
65{ 110{
66 close(); 111 close();
@@ -109,6 +154,10 @@ void Bu::Process::gexec( Flags eFlags, const char *sName, char *const argv[] )
109 ::close( iaStdErr[0] ); 154 ::close( iaStdErr[0] );
110 dup2( iaStdErr[1], 2 ); 155 dup2( iaStdErr[1], 2 );
111 } 156 }
157 if( (opt.eFlags&Options::SetUid) )
158 {
159 setuid( opt.iUid );
160 }
112 execvp( sName, argv ); 161 execvp( sName, argv );
113 throw Bu::ExceptionBase("Hey, execvp failed!"); 162 throw Bu::ExceptionBase("Hey, execvp failed!");
114 } 163 }
diff --git a/src/process.h b/src/process.h
index 4934408..f3d84b1 100644
--- a/src/process.h
+++ b/src/process.h
@@ -33,8 +33,25 @@ namespace Bu
33 }; 33 };
34 34
35 public: 35 public:
36 class Options
37 {
38 public:
39 enum OptFlags
40 {
41 None = 0x00,
42 SetUid = 0x01,
43 };
44
45 Options() : eFlags( None ) {}
46
47 OptFlags eFlags;
48 int iUid;
49 };
50
36 Process( Flags eFlags, const char *sName, char *const argv[] ); 51 Process( Flags eFlags, const char *sName, char *const argv[] );
37 Process( Flags eFlags, const char *sName, const char *argv, ...); 52 Process( Flags eFlags, const char *sName, const char *argv, ...);
53 Process( Flags eFlags, const Options &opt, const char *sName, char *const argv[] );
54 Process( Flags eFlags, const Options &opt, const char *sName, const char *argv, ...);
38 virtual ~Process(); 55 virtual ~Process();
39 56
40 /** 57 /**
@@ -125,6 +142,7 @@ namespace Bu
125 142
126 void gexec( Flags eFlags, const char *sName, char *const argv[] ); 143 void gexec( Flags eFlags, const char *sName, char *const argv[] );
127 void checkClose(); 144 void checkClose();
145 Options opt;
128 }; 146 };
129} 147}
130 148