Switch to unified view

a/src/utils/execmd.h b/src/utils/execmd.h
...
...
18
#define _EXECMD_H_INCLUDED_
18
#define _EXECMD_H_INCLUDED_
19
#include <signal.h>
19
#include <signal.h>
20
#include <string>
20
#include <string>
21
#include <list>
21
#include <list>
22
#include <vector>
22
#include <vector>
23
#include <stack>
23
#ifndef NO_NAMESPACES
24
#ifndef NO_NAMESPACES
24
using std::list;
25
using std::list;
25
using std::string;
26
using std::string;
26
using std::vector;
27
using std::vector;
28
using std::stack;
27
#endif
29
#endif
28
30
29
#include "netcon.h"
31
#include "netcon.h"
30
32
31
/** 
33
/** 
...
...
206
    ExecCmd(const ExecCmd &) {}
208
    ExecCmd(const ExecCmd &) {}
207
    ExecCmd& operator=(const ExecCmd &) {return *this;};
209
    ExecCmd& operator=(const ExecCmd &) {return *this;};
208
};
210
};
209
211
210
212
213
/** 
211
/** Rexecute myself with the same arguments. 
214
 * Rexecute self process with the same arguments. 
212
 *
215
 *
213
 * Note that there are some limitations:
216
 * Note that there are some limitations:
214
 *  - argv[0] has to be valid: an executable name which will be found in 
217
 *  - argv[0] has to be valid: an executable name which will be found in 
215
 *    the path when exec is called in the initial working directory. This is 
218
 *    the path when exec is called in the initial working directory. This is 
216
 *    by no means guaranteed. The shells do this, but argv[0] could be an
219
 *    by no means guaranteed. The shells do this, but argv[0] could be an
...
...
222
 *  - We don't restore the signals. Signals set to be blocked 
225
 *  - We don't restore the signals. Signals set to be blocked 
223
 *    or ignored by the program will remain ignored even if this was not their
226
 *    or ignored by the program will remain ignored even if this was not their
224
 *    initial state.
227
 *    initial state.
225
 *  - The environment is also not restored.
228
 *  - The environment is also not restored.
226
 *  - Others system aspects ?
229
 *  - Others system aspects ?
227
 *  - Other program state: application-dependant
230
 *  - Other program state: application-dependant. Any external cleanup 
231
 *    (temp files etc.) must be performed by the application. ReExec() 
232
 *    duplicates the atexit() function to make this easier, but the 
233
 *    ReExec().atexit() calls must be done explicitely, this is not automatic
228
 * 
234
 * 
229
 * In short, this is usable in reasonably controlled situations and if there 
235
 * In short, this is usable in reasonably controlled situations and if there 
230
 * are no security issues involved, but this does not perform miracles.
236
 * are no security issues involved, but this does not perform miracles.
231
 */
237
 */
232
class ReExec {
238
class ReExec {
233
public:
239
public:
234
    ReExec() {}
240
    ReExec() {}
235
    ReExec(int argc, char *argv[]);
241
    ReExec(int argc, char *argv[]);
236
    void init(int argc, char *argv[]);
242
    void init(int argc, char *argv[]);
243
    int atexit(void (*function)(void))
244
    {
245
  m_atexitfuncs.push(function);
246
  return 0;
247
    }
237
    void reexec();
248
    void reexec();
238
    const string& getreason() {return m_reason;}
249
    const string& getreason() {return m_reason;}
239
private:
250
private:
240
    vector<string> m_argv;
251
    vector<string> m_argv;
241
    string m_curdir;
252
    string m_curdir;
242
    int    m_cfd;
253
    int    m_cfd;
243
    string m_reason;
254
    string m_reason;
255
    stack<void (*)(void)> m_atexitfuncs;
244
};
256
};
245
257
246
#endif /* _EXECMD_H_INCLUDED_ */
258
#endif /* _EXECMD_H_INCLUDED_ */