util: polish the reexec thingy
This commit is contained in:
parent
de9a06f04c
commit
b49da9d838
@ -642,6 +642,12 @@ void ReExec::reexec()
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Execute the atexit funcs
|
||||||
|
while (!m_atexitfuncs.empty()) {
|
||||||
|
(m_atexitfuncs.top())();
|
||||||
|
m_atexitfuncs.pop();
|
||||||
|
}
|
||||||
|
|
||||||
// Try to get back to the initial working directory
|
// Try to get back to the initial working directory
|
||||||
if (m_cfd < 0 || fchdir(m_cfd) < 0) {
|
if (m_cfd < 0 || fchdir(m_cfd) < 0) {
|
||||||
LOGINFO(("ReExec::reexec: fchdir failed, trying chdir\n"));
|
LOGINFO(("ReExec::reexec: fchdir failed, trying chdir\n"));
|
||||||
|
|||||||
@ -20,10 +20,12 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <stack>
|
||||||
#ifndef NO_NAMESPACES
|
#ifndef NO_NAMESPACES
|
||||||
using std::list;
|
using std::list;
|
||||||
using std::string;
|
using std::string;
|
||||||
using std::vector;
|
using std::vector;
|
||||||
|
using std::stack;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "netcon.h"
|
#include "netcon.h"
|
||||||
@ -208,7 +210,8 @@ class ExecCmd {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/** Rexecute myself with the same arguments.
|
/**
|
||||||
|
* Rexecute self process with the same arguments.
|
||||||
*
|
*
|
||||||
* Note that there are some limitations:
|
* Note that there are some limitations:
|
||||||
* - argv[0] has to be valid: an executable name which will be found in
|
* - argv[0] has to be valid: an executable name which will be found in
|
||||||
@ -224,7 +227,10 @@ class ExecCmd {
|
|||||||
* initial state.
|
* initial state.
|
||||||
* - The environment is also not restored.
|
* - The environment is also not restored.
|
||||||
* - Others system aspects ?
|
* - Others system aspects ?
|
||||||
* - Other program state: application-dependant
|
* - Other program state: application-dependant. Any external cleanup
|
||||||
|
* (temp files etc.) must be performed by the application. ReExec()
|
||||||
|
* duplicates the atexit() function to make this easier, but the
|
||||||
|
* ReExec().atexit() calls must be done explicitely, this is not automatic
|
||||||
*
|
*
|
||||||
* In short, this is usable in reasonably controlled situations and if there
|
* In short, this is usable in reasonably controlled situations and if there
|
||||||
* are no security issues involved, but this does not perform miracles.
|
* are no security issues involved, but this does not perform miracles.
|
||||||
@ -234,6 +240,11 @@ public:
|
|||||||
ReExec() {}
|
ReExec() {}
|
||||||
ReExec(int argc, char *argv[]);
|
ReExec(int argc, char *argv[]);
|
||||||
void init(int argc, char *argv[]);
|
void init(int argc, char *argv[]);
|
||||||
|
int atexit(void (*function)(void))
|
||||||
|
{
|
||||||
|
m_atexitfuncs.push(function);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
void reexec();
|
void reexec();
|
||||||
const string& getreason() {return m_reason;}
|
const string& getreason() {return m_reason;}
|
||||||
private:
|
private:
|
||||||
@ -241,6 +252,7 @@ private:
|
|||||||
string m_curdir;
|
string m_curdir;
|
||||||
int m_cfd;
|
int m_cfd;
|
||||||
string m_reason;
|
string m_reason;
|
||||||
|
stack<void (*)(void)> m_atexitfuncs;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* _EXECMD_H_INCLUDED_ */
|
#endif /* _EXECMD_H_INCLUDED_ */
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user