-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlibexecve_thread.cpp
More file actions
44 lines (36 loc) · 922 Bytes
/
libexecve_thread.cpp
File metadata and controls
44 lines (36 loc) · 922 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "execve_thread.h"
#include <pthread.h>
#include <semaphore.h>
#include <assert.h>
#include <stdlib.h>
struct Data {
sem_t sem;
const char* pathname;
const char* const* argv;
const char* const* envp;
};
static void post(void* data) {
sem_t* sem = (sem_t*)data;
sem_post(sem);
}
static void* start(void* _data) {
struct Data* data = (Data*)_data;
execve_here(data->pathname, data->argv, data->envp, post, &data->sem);
abort();
}
__attribute__((visibility("default"))) void execve_thread(
const char* pathname,
const char* const* argv,
const char* const* envp) {
int ret;
pthread_t thread;
struct Data data;
data.pathname = pathname;
data.argv = argv;
data.envp = envp;
ret = sem_init(&data.sem, 0, 0);
assert(ret == 0);
ret = pthread_create(&thread, nullptr, start, &data);
assert(ret == 0);
sem_wait(&data.sem);
}