2019-06-23 21:54:48 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <sys/syscall.h>
|
2022-02-06 08:27:31 +00:00
|
|
|
#include <linux/fcntl.h>
|
2019-06-23 21:54:48 +00:00
|
|
|
#include <unistd.h>
|
2022-02-06 08:27:31 +00:00
|
|
|
#include <cerrno>
|
|
|
|
#include <cstdio>
|
2019-06-23 21:54:48 +00:00
|
|
|
|
2021-10-20 10:17:42 +00:00
|
|
|
static inline int sigtimedwait(const sigset_t* set, siginfo_t* info, const timespec* timeout) {
|
2021-08-21 10:52:59 +00:00
|
|
|
union {
|
|
|
|
sigset_t set;
|
|
|
|
sigset_t set64;
|
|
|
|
} s{};
|
|
|
|
s.set = *set;
|
|
|
|
return syscall(__NR_rt_sigtimedwait, &s.set64, info, timeout, sizeof(sigset64_t));
|
|
|
|
}
|
2022-02-06 08:27:31 +00:00
|
|
|
|
|
|
|
static inline int fexecve(int fd, char* const* argv, char* const* envp) {
|
|
|
|
syscall(__NR_execveat, fd, "", argv, envp, AT_EMPTY_PATH);
|
|
|
|
if (errno == ENOSYS) {
|
|
|
|
char buf[256];
|
|
|
|
std::snprintf(buf, sizeof(buf), "/proc/self/fd/%d", fd);
|
|
|
|
execve(buf, argv, envp);
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|