Package: sl-modem / 2.9.11~20110321-11

12_ulimit_warn.diff Patch series | download
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
Patch that checks the current limit and makes slmodemd warn & die if the limit 
is judged to be too low (< 8 MB).
By: Corey Hickey <bugfood-c@fatooh.org>
Index: sl-modem-2.9.11~20080817/modem/modem_main.c
===================================================================
--- sl-modem-2.9.11~20080817.orig/modem/modem_main.c	2009-02-25 16:14:25.000000000 +0200
+++ sl-modem-2.9.11~20080817/modem/modem_main.c	2009-02-25 16:19:11.000000000 +0200
@@ -53,6 +53,8 @@
 #include <sys/stat.h>
 #include <sys/ioctl.h>
 #include <sys/mman.h>
+#include <sys/time.h>
+#include <sys/resource.h>
 #include <sched.h>
 #include <signal.h>
 #include <limits.h>
@@ -78,6 +80,8 @@
 
 
 #define SLMODEMD_USER "Slmodemd"
+#define LOCKED_MEM_MIN_KB (8UL * 1024)
+#define LOCKED_MEM_MIN    (LOCKED_MEM_MIN_KB * 1024)
 
 #define CLOSE_COUNT_MAX 100
 
@@ -989,6 +993,22 @@
 	signal(SIGTERM, mark_termination);
 
 #ifdef SLMODEMD_USER
+	if (need_realtime) {
+		struct rlimit limit;
+		if (getrlimit(RLIMIT_MEMLOCK, &limit)) {
+			ERR("getrlimit failed to read RLIMIT_MEMLOCK\n");
+			exit(-1);
+		}
+		if (limit.rlim_cur != RLIM_INFINITY &&
+			limit.rlim_cur < LOCKED_MEM_MIN) {
+			ERR("locked memory limit too low:\n");
+			ERR("need %lu bytes, have %lu bytes\n", LOCKED_MEM_MIN,
+				(unsigned long)limit.rlim_cur);
+			ERR("try 'ulimit -l %lu'\n", LOCKED_MEM_MIN_KB);
+			exit(-1);
+		}
+	}
+
 	pwd = getpwnam(SLMODEMD_USER);
 	if (!pwd) {
 		ERR("getpwnam " SLMODEMD_USER ": %s\n",strerror(errno));