diff options
author | Mike Buland <eichlan@xagasoft.com> | 2011-08-15 17:06:31 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2011-08-15 17:06:31 +0000 |
commit | bc9e6678f6b917f67317a2987866bf1787a3e076 (patch) | |
tree | 446a22eb59bbb8d27518a6404ae425513e4c0f1f /src/process.cpp | |
parent | b307b8bb72b660be65a1dc5d8a05a4db32af7e67 (diff) | |
download | libbu++-bc9e6678f6b917f67317a2987866bf1787a3e076.tar.gz libbu++-bc9e6678f6b917f67317a2987866bf1787a3e076.tar.bz2 libbu++-bc9e6678f6b917f67317a2987866bf1787a3e076.tar.xz libbu++-bc9e6678f6b917f67317a2987866bf1787a3e076.zip |
Process now supports setuid for the child process. Really cool.
Diffstat (limited to 'src/process.cpp')
-rw-r--r-- | src/process.cpp | 49 |
1 files changed, 49 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 | ||
64 | Bu::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 | |||
78 | Bu::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 | |||
64 | Bu::Process::~Process() | 109 | Bu::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 | } |