Browse code

- added missing register_fds & get_max_open_fds() declarations

Andrei Pelinescu-Onciul authored on 07/07/2007 00:33:02
Showing 2 changed files
... ...
@@ -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 60
 
61 61
 
62 62
 static int estimated_proc_no=0;
63
+static int estimated_fds_no=0;
64
+
65
+
66
+/* number of known "common" used fds */
67
+static int calc_common_open_fds_no()
68
+{
69
+	int max_fds_no;
70
+	
71
+	/* 1 tcp send unix socket/all_proc, 
72
+	 *  + 1 udp sock/udp proc + 1 possible dns comm. socket + 
73
+	 *  + 1 temporary tcp send sock.
74
+	 */
75
+	max_fds_no=estimated_proc_no*4 /* udp + tcp unix sock + tmp. tcp send +
76
+									  tmp dns.*/ -1 /* timer (no udp)*/ + 
77
+				3 /* stdin/out/err */;
78
+	return max_fds_no;
79
+}
80
+
81
+
63 82
 
64 83
 /* returns 0 on success, -1 on error */
65 84
 int init_pt(int proc_no)
... ...
@@ -69,6 +89,7 @@ int init_pt(int proc_no)
69 69
 #endif
70 70
 	
71 71
 	estimated_proc_no+=proc_no;
72
+	estimated_fds_no+=calc_common_open_fds_no();
72 73
 	/*alloc pids*/
73 74
 #ifdef SHM_MEM
74 75
 	pt=shm_malloc(sizeof(struct process_table)*estimated_proc_no);
... ...
@@ -126,6 +147,35 @@ int get_max_procs()
126 126
 }
127 127
 
128 128
 
129
+/* register no fds, used from mod_init when modules will open more global
130
+ *  fds (from mod_init or child_init(PROC_INIT)
131
+ *  or from child_init(rank) when the module will open fds local to the
132
+ *   process "rank".
133
+ *   (this is needed because some other parts of ser code rely on knowing
134
+ *    the maximum open fd number in a process)
135
+ *  returns 0 on success, -1 on error
136
+ */
137
+int register_fds(int no)
138
+{
139
+	/* can be called at runtime, but should be called from child_init() */
140
+	estimated_fds_no+=no;
141
+	return 0;
142
+}
143
+
144
+
145
+
146
+/* returns the maximum open fd number */
147
+int get_max_open_fds()
148
+{
149
+	if (pt==0){
150
+		LOG(L_CRIT, "BUG: get_max_open_fds() called too early "
151
+				"(it must _not_ be called from mod_init())\n");
152
+		abort(); /* crash to quickly catch offenders */
153
+	}
154
+	return estimated_fds_no;
155
+}
156
+
157
+
129 158
 /* return processes pid */
130 159
 int my_pid()
131 160
 {
... ...
@@ -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 69
 int init_pt();
70 70
 int get_max_procs();
71 71
 int register_procs(int no);
72
+int get_max_open_fds();
73
+int register_fds(int no);
72 74
 
73 75
 /* return processes pid */
74 76
 int my_pid();