... | ... |
@@ -35,6 +35,7 @@ |
35 | 35 |
* 2006-09-20 added profile support (-DPROFILING) (hscholz) |
36 | 36 |
* 2006-10-25 sanity check before allowing forking w/ tcp support (is_main |
37 | 37 |
* & tcp not started yet); set is_main=0 in childs (andrei) |
38 |
+ * 2007-07-04 added register_fds() and get_max_open_fds(() (andrei) |
|
38 | 39 |
*/ |
39 | 40 |
|
40 | 41 |
|
... | ... |
@@ -60,6 +61,25 @@ |
60 | 61 |
|
61 | 62 |
|
62 | 63 |
static int estimated_proc_no=0; |
64 |
+static int estimated_fds_no=0; |
|
65 |
+ |
|
66 |
+ |
|
67 |
+/* number of known "common" used fds */ |
|
68 |
+static int calc_common_open_fds_no() |
|
69 |
+{ |
|
70 |
+ int max_fds_no; |
|
71 |
+ |
|
72 |
+ /* 1 tcp send unix socket/all_proc, |
|
73 |
+ * + 1 udp sock/udp proc + 1 possible dns comm. socket + |
|
74 |
+ * + 1 temporary tcp send sock. |
|
75 |
+ */ |
|
76 |
+ max_fds_no=estimated_proc_no*4 /* udp + tcp unix sock + tmp. tcp send + |
|
77 |
+ tmp dns.*/ -1 /* timer (no udp)*/ + |
|
78 |
+ 3 /* stdin/out/err */; |
|
79 |
+ return max_fds_no; |
|
80 |
+} |
|
81 |
+ |
|
82 |
+ |
|
63 | 83 |
|
64 | 84 |
/* returns 0 on success, -1 on error */ |
65 | 85 |
int init_pt(int proc_no) |
... | ... |
@@ -69,6 +89,7 @@ int init_pt(int proc_no) |
69 | 89 |
#endif |
70 | 90 |
|
71 | 91 |
estimated_proc_no+=proc_no; |
92 |
+ estimated_fds_no+=calc_common_open_fds_no(); |
|
72 | 93 |
/*alloc pids*/ |
73 | 94 |
#ifdef SHM_MEM |
74 | 95 |
pt=shm_malloc(sizeof(struct process_table)*estimated_proc_no); |
... | ... |
@@ -126,6 +147,35 @@ int get_max_procs() |
126 | 147 |
} |
127 | 148 |
|
128 | 149 |
|
150 |
+/* register no fds, used from mod_init when modules will open more global |
|
151 |
+ * fds (from mod_init or child_init(PROC_INIT) |
|
152 |
+ * or from child_init(rank) when the module will open fds local to the |
|
153 |
+ * process "rank". |
|
154 |
+ * (this is needed because some other parts of ser code rely on knowing |
|
155 |
+ * the maximum open fd number in a process) |
|
156 |
+ * returns 0 on success, -1 on error |
|
157 |
+ */ |
|
158 |
+int register_fds(int no) |
|
159 |
+{ |
|
160 |
+ /* can be called at runtime, but should be called from child_init() */ |
|
161 |
+ estimated_fds_no+=no; |
|
162 |
+ return 0; |
|
163 |
+} |
|
164 |
+ |
|
165 |
+ |
|
166 |
+ |
|
167 |
+/* returns the maximum open fd number */ |
|
168 |
+int get_max_open_fds() |
|
169 |
+{ |
|
170 |
+ if (pt==0){ |
|
171 |
+ LOG(L_CRIT, "BUG: get_max_open_fds() called too early " |
|
172 |
+ "(it must _not_ be called from mod_init())\n"); |
|
173 |
+ abort(); /* crash to quickly catch offenders */ |
|
174 |
+ } |
|
175 |
+ return estimated_fds_no; |
|
176 |
+} |
|
177 |
+ |
|
178 |
+ |
|
129 | 179 |
/* return processes pid */ |
130 | 180 |
int my_pid() |
131 | 181 |
{ |
... | ... |
@@ -33,6 +33,7 @@ |
33 | 33 |
* -------- |
34 | 34 |
* 2003-04-15 added tcp_disable support (andrei) |
35 | 35 |
* 2006-06-14 added process table in shared mem (dragos) |
36 |
+ * 2007-07-04 added register_fds() and get_max_open_fds(() (andrei) |
|
36 | 37 |
*/ |
37 | 38 |
|
38 | 39 |
|
... | ... |
@@ -69,6 +70,8 @@ extern struct tcp_child* tcp_children; |
69 | 70 |
int init_pt(); |
70 | 71 |
int get_max_procs(); |
71 | 72 |
int register_procs(int no); |
73 |
+int get_max_open_fds(); |
|
74 |
+int register_fds(int no); |
|
72 | 75 |
|
73 | 76 |
/* return processes pid */ |
74 | 77 |
int my_pid(); |