void my_closefrom(int start);
struct rlimit;
-int raise_rlim_nofile(struct rlimit *old_limit, struct rlimit *new_limit);
int compute_poll_timeout(int next);
void fd_leaving_poll(int wait_time, int status);
#define _HAPROXY_LIMITS_H
#include <sys/resource.h>
+/* handlers to manipulate system resources limits granted by OS to process and
+ * to tie them up with the internal process limits
+ */
+int raise_rlim_nofile(struct rlimit *old_limit, struct rlimit *new_limit);
+
#endif /* _HAPROXY_LIMITS_H */
}
#endif // defined(USE_POLL)
-/* Sets the RLIMIT_NOFILE setting to <new_limit> and returns the previous one
- * in <old_limit> if the pointer is not NULL, even if set_rlimit() fails. The
- * two pointers may point to the same variable as the copy happens after
- * setting the new value. The value is only changed if at least one of the new
- * limits is strictly higher than the current one, otherwise returns 0 without
- * changing anything. The getrlimit() or setrlimit() syscall return value is
- * returned and errno is preserved.
- */
-int raise_rlim_nofile(struct rlimit *old_limit, struct rlimit *new_limit)
-{
- struct rlimit limit = { };
- int ret = 0;
-
- ret = getrlimit(RLIMIT_NOFILE, &limit);
-
- if (ret == 0 &&
- (limit.rlim_max < new_limit->rlim_max ||
- limit.rlim_cur < new_limit->rlim_cur)) {
- ret = setrlimit(RLIMIT_NOFILE, new_limit);
- }
-
- if (old_limit)
- *old_limit = limit;
-
- return ret;
-}
/* Computes the bounded poll() timeout based on the next expiration timer <next>
* by bounding it to MAX_DELAY_MS. <next> may equal TICK_ETERNITY. The pollers
#include <haproxy/proxy.h>
+/* Sets the RLIMIT_NOFILE setting to <new_limit> and returns the previous one
+ * in <old_limit> if the pointer is not NULL, even if set_rlimit() fails. The
+ * two pointers may point to the same variable as the copy happens after
+ * setting the new value. The value is only changed if at least one of the new
+ * limits is strictly higher than the current one, otherwise returns 0 without
+ * changing anything. The getrlimit() or setrlimit() syscall return value is
+ * returned and errno is preserved.
+ */
+int raise_rlim_nofile(struct rlimit *old_limit, struct rlimit *new_limit)
+{
+ struct rlimit limit = { };
+ int ret = 0;
+
+ ret = getrlimit(RLIMIT_NOFILE, &limit);
+
+ if (ret == 0 &&
+ (limit.rlim_max < new_limit->rlim_max ||
+ limit.rlim_cur < new_limit->rlim_cur)) {
+ ret = setrlimit(RLIMIT_NOFILE, new_limit);
+ }
+
+ if (old_limit)
+ *old_limit = limit;
+
+ return ret;
+}