-
Notifications
You must be signed in to change notification settings - Fork 2
/
preeny.git_patch
84 lines (74 loc) · 2.32 KB
/
preeny.git_patch
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
diff --git a/src/desock.c b/src/desock.c
index 85a28c7..1b121f2 100644
--- a/src/desock.c
+++ b/src/desock.c
@@ -1,6 +1,8 @@
#define _GNU_SOURCE
+#include <assert.h>
#include <netinet/in.h>
+#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <pthread.h>
@@ -8,6 +10,7 @@
#include <unistd.h>
#include <string.h>
#include <signal.h>
+#include <fcntl.h>
#include <dlfcn.h>
#include <errno.h>
#include <stdio.h>
@@ -18,11 +21,12 @@
#define PREENY_MAX_FD 8192
#define PREENY_SOCKET_OFFSET 500
#define READ_BUF_SIZE 65536
+#define INPUT_FILE_PATH_ENV "PREENY_DESOCK_INFILE"
#define PREENY_SOCKET(x) (x+PREENY_SOCKET_OFFSET)
int preeny_desock_shutdown_flag = 0;
-int preeny_desock_did_accept = 0;
+int in_fd = 0;
pthread_t *preeny_socket_threads_to_front[PREENY_MAX_FD] = { 0 };
pthread_t *preeny_socket_threads_to_back[PREENY_MAX_FD] = { 0 };
@@ -36,6 +40,7 @@ int preeny_socket_sync(int from, int to, int timeout)
int n;
int r;
+
r = poll(&poll_in, 1, timeout);
if (r < 0)
{
@@ -141,7 +146,8 @@ void *preeny_socket_sync_to_front(void *fd)
{
int front_fd = (int)fd;
int back_fd = PREENY_SOCKET(front_fd);
- preeny_socket_sync_loop(0, back_fd);
+ /* Read fd here */
+ preeny_socket_sync_loop(in_fd, back_fd);
return NULL;
}
@@ -160,6 +166,11 @@ __attribute__((constructor)) void preeny_desock_orig()
original_accept = dlsym(RTLD_NEXT, "accept");
original_bind = dlsym(RTLD_NEXT, "bind");
original_connect = dlsym(RTLD_NEXT, "connect");
+
+ if (getenv(INPUT_FILE_PATH_ENV) != NULL) {
+ in_fd = open(getenv(INPUT_FILE_PATH_ENV), O_RDONLY);
+ assert(in_fd != -1 && "Input file not found");
+ }
}
int socket(int domain, int type, int protocol)
@@ -187,6 +198,7 @@ int socket(int domain, int type, int protocol)
front_socket = fds[0];
back_socket = dup2(fds[1], PREENY_SOCKET(front_socket));
+ printf("front = %d, back = %d\n", front_socket, back_socket);
close(fds[1]);
preeny_debug("... dup into socketpair (%d, %d)\n", fds[0], back_socket);
@@ -213,10 +225,6 @@ int socket(int domain, int type, int protocol)
int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
{
- if (preeny_desock_did_accept)
- exit(0);
- preeny_desock_did_accept = 1;
-
//initialize a sockaddr_in for the peer
struct sockaddr_in peer_addr;
memset(&peer_addr, '0', sizeof(struct sockaddr_in));