#ifndef _HAPROXY_LIMITS_H
#define _HAPROXY_LIMITS_H
#include <sys/resource.h>
+#include <haproxy/compat.h>
extern unsigned int rlim_fd_cur_at_boot;
extern unsigned int rlim_fd_max_at_boot;
+/* returns 0 if the given limit was not set (reported as infinity), otherwise
+ * returns the limit, useful to print limit values as strings in err messages
+ * via LIM2A macros.
+ */
+static inline ulong normalize_rlim(ulong rlim)
+{
+ if (rlim == RLIM_INFINITY)
+ return 0;
+
+ return rlim;
+}
+
/* handlers to compute internal process limits, if they are not provided via
* cmd line or via configuration file.
*/
#include <haproxy/global.h>
#include <haproxy/hlua.h>
#include <haproxy/http_ana.h>
+#include <haproxy/limits.h>
#if defined(USE_LINUX_CAP)
#include <haproxy/linuxcap.h>
#endif
chunk_appendf(&trash, " capget() failed at runtime with: %s.\n",
strerror(post_mortem.process.caps.err_run));
#endif
- if ((ulong)post_mortem.process.limit_fd.rlim_cur != RLIM_INFINITY)
- chunk_appendf(&trash, " fd limit (soft): %lu\n", (ulong)post_mortem.process.limit_fd.rlim_cur);
- if ((ulong)post_mortem.process.limit_fd.rlim_max != RLIM_INFINITY)
- chunk_appendf(&trash, " fd limit (hard): %lu\n", (ulong)post_mortem.process.limit_fd.rlim_max);
- if ((ulong)post_mortem.process.limit_ram.rlim_cur != RLIM_INFINITY)
- chunk_appendf(&trash, " ram limit (soft): %lu\n", (ulong)post_mortem.process.limit_ram.rlim_cur);
- if ((ulong)post_mortem.process.limit_ram.rlim_max != RLIM_INFINITY)
- chunk_appendf(&trash, " ram limit (hard): %lu\n", (ulong)post_mortem.process.limit_ram.rlim_max);
+ chunk_appendf(&trash, " fd limit (soft): %s\n",
+ LIM2A(normalize_rlim((ulong)post_mortem.process.limit_fd.rlim_cur), "unlimited"));
+ chunk_appendf(&trash, " fd limit (hard): %s\n",
+ LIM2A(normalize_rlim((ulong)post_mortem.process.limit_fd.rlim_max), "unlimited"));
+ chunk_appendf(&trash, " ram limit (soft): %s\n",
+ LIM2A(normalize_rlim((ulong)post_mortem.process.limit_ram.rlim_cur), "unlimited"));
+ chunk_appendf(&trash, " ram limit (hard): %s\n",
+ LIM2A(normalize_rlim((ulong)post_mortem.process.limit_ram.rlim_max), "unlimited"));
return cli_msg(appctx, LOG_INFO, trash.area);
}