-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathmonkey.patch
238 lines (204 loc) · 6.86 KB
/
monkey.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
diff --git a/configure b/configure
index 4286c34..b4301fa 100644
--- a/configure
+++ b/configure
@@ -1297,7 +1297,7 @@ fi
[ -n "$relaxed_plugins" ] && DEFS="$DEFS -DRELAXED_PLUGINS"
-CFLAGS_GEN=" -std=gnu99 -Wall -Wextra"
+CFLAGS_GEN=" -std=gnu99 -Wall -Wextra -fcommon"
if test -z "$debug" ; then
CFLAGS="$CFLAGS $CFLAGS_GEN -fvisibility=hidden"
diff --git a/examples/Makefile b/examples/Makefile
index 4bcf670f..20aed5ba 100644
--- a/examples/Makefile
+++ b/examples/Makefile
@@ -1,7 +1,8 @@
CFLAGS += -Wall
-
-CFLAGS += $(shell pkg-config --cflags monkey)
-LDFLAGS += $(shell pkg-config --libs monkey)
+PKGS = glib-2.0 monkey
+CFLAGS += $(shell pkg-config --cflags $(PKGS))
+LDLIBS += $(shell pkg-config --libs $(PKGS)) -ldl
+LDFLAGS += -Wl,--no-as-needed,-rpath,'$$ORIGIN/lib'
.PHONY: all clean first
diff --git a/examples/hello.c b/examples/hello.c
index d54c3dde..d51b7ddf 100644
--- a/examples/hello.c
+++ b/examples/hello.c
@@ -1,6 +1,7 @@
/* Monkey HTTP Daemon
* ------------------
* Copyright (C) 2012, Lauri Kasanen <[email protected]>
+ * Modified 2021, Axis Communications AB, Lund, Sweden
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -21,6 +22,8 @@
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
+#include <syslog.h>
+#include <glib.h>
/*
* This example shows how to start the server, and point it to /tmp.
@@ -39,30 +42,41 @@ static void write_index() {
fclose(f);
}
-int main() {
+int main(int argc, char* argv[]) {
- int ret;
+ GMainLoop *loop;
+ int ret;
- write_index();
+ openlog("hello", LOG_PID|LOG_CONS, LOG_USER);
+ syslog(LOG_INFO, "starting %s", argv[0]);
+ loop = g_main_loop_new(NULL, FALSE);
+ write_index();
// All defaults. Bind to all interfaces, port 2001, default plugins, /tmp.
// No callbacks are used.
mklib_ctx ctx = mklib_init(NULL, 0, 0, "/tmp");
- if (!ctx) return 1;
+ if (!ctx) {
+ syslog(LOG_INFO, "mklib_init failed");
+ exit(0);
+ }
+ syslog(LOG_INFO, "mklib_init success");
// The default has no index files, let's set index.html as one.
ret = mklib_config(ctx, MKC_INDEXFILE, "index.html", NULL);
- if (!ret) return 1;
+ if (!ret) {
+ syslog(LOG_INFO, "mklib_config failed");
+ exit(0);
+ }
+ syslog(LOG_INFO, "mklib_config success");
// Start the server.
mklib_start(ctx);
+ syslog(LOG_INFO, "mklib_start success");
- // I'm now free to do my own things. I'm just going to wait for a keypress.
- printf("All set and running! Visit me, I default to localhost:2001.\n");
- printf("Press a key to exit.\n");
- getchar();
+ g_main_loop_run(loop);
mklib_stop(ctx);
+ syslog(LOG_INFO, "Stop Monkey hello");
return 0;
}
diff --git a/examples/list.c b/examples/list.c
index 7156fd2c..481951bd 100644
--- a/examples/list.c
+++ b/examples/list.c
@@ -1,6 +1,7 @@
/* Monkey HTTP Daemon
* ------------------
* Copyright (C) 2012, Lauri Kasanen <[email protected]>
+ * Modified 2021, Axis Communications AB, Lund, Sweden
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -22,6 +23,8 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+#include <syslog.h>
+#include <glib.h>
/*
* This example shows a directory listing of /tmp, with no access to files. Fun eh?
@@ -67,23 +70,31 @@ static int list(const mklib_session *sr, const char *vhost, const char *url,
* This makes sure the callback function has the right arguments. */
static cb_data listf = list;
-int main() {
+int main(int argc, char* argv[]) {
+ GMainLoop *loop;
+
+ openlog("list", LOG_PID|LOG_CONS, LOG_USER);
+ syslog(LOG_INFO, "starting %s", argv[0]);
+ loop = g_main_loop_new(NULL, FALSE);
// Bind to all interfaces, port 2001, default plugins, no directory.
// Lacking the directory means that no files can be accessed, just what we want.
// We use the data callback.
mklib_ctx ctx = mklib_init(NULL, 0, 0, NULL);
- if (!ctx) return 1;
+ if (!ctx) {
+ syslog(LOG_INFO, "mklib_init failed");
+ exit(0);
+ }
+ syslog(LOG_INFO, "mklib_init success");
mklib_callback_set(ctx, MKCB_DATA, listf);
+ syslog(LOG_INFO, "mklib_callback_set success");
// Start the server.
mklib_start(ctx);
+ syslog(LOG_INFO, "mklib_start success");
- // I'm now free to do my own things. I'm just going to wait for a keypress.
- printf("All set and running! Visit me, I default to localhost:2001.\n");
- printf("Press a key to exit.\n");
- getchar();
+ g_main_loop_run(loop);
mklib_stop(ctx);
diff --git a/examples/quiz.c b/examples/quiz.c
index 9914cb79..383f841f 100644
--- a/examples/quiz.c
+++ b/examples/quiz.c
@@ -1,6 +1,7 @@
/* Monkey HTTP Daemon
* ------------------
* Copyright (C) 2012, Lauri Kasanen <[email protected]>
+ * Modified 2021, Axis Communications AB, Lund, Sweden
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -22,6 +23,8 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+#include <syslog.h>
+#include <glib.h>
#include "image.h"
@@ -100,23 +103,30 @@ static int list(const mklib_session *sr, const char *vhost, const char *url,
* This makes sure the callback function has the right arguments. */
static cb_data listf = list;
-int main() {
+int main(int argc, char* argv[]) {
+ GMainLoop *loop;
+ openlog("quiz", LOG_PID|LOG_CONS, LOG_USER);
+ syslog(LOG_INFO, "starting %s", argv[0]);
+ loop = g_main_loop_new(NULL, FALSE);
// Bind to all interfaces, port 2001, default plugins, no directory.
// Lacking the directory means that no files can be accessed, just what we want.
// We use the data callback.
mklib_ctx ctx = mklib_init(NULL, 0, 0, NULL);
- if (!ctx) return 1;
+ if (!ctx) {
+ syslog(LOG_INFO, "mklib_init failed");
+ exit(0);
+ }
+ syslog(LOG_INFO, "mklib_init success");
mklib_callback_set(ctx, MKCB_DATA, listf);
+ syslog(LOG_INFO, "mklib_callback_set success");
// Start the server.
mklib_start(ctx);
+ syslog(LOG_INFO, "mklib_start success");
- // I'm now free to do my own things. I'm just going to wait for a keypress.
- printf("All set and running! Visit me, I default to localhost:2001.\n");
- printf("Press a key to exit.\n");
- getchar();
+ g_main_loop_run(loop);
mklib_stop(ctx);
diff --git a/src/mk_server.c b/src/mk_server.c
index 8c27742..956f7ee 100644
--- a/src/mk_server.c
+++ b/src/mk_server.c
@@ -40,11 +40,9 @@
unsigned int mk_server_worker_capacity(unsigned short nworkers)
{
unsigned int max, avl;
- struct rlimit lim;
-
- /* Limit by system */
- getrlimit(RLIMIT_NOFILE, &lim);
- max = lim.rlim_cur;
+
+ /* Overwrite the value for RLIMIT_NOFILE to avoid unmanagable memory allocation */
+ max = 1048576;
/* Minimum of fds needed by Monkey:
* --------------------------------