On 08/08/2018 01:34 PM, Barath Aron wrote:
> [...] the point is to avoid compiler error if getrlimit is not supported 
> (because the struct rlimit is not exists).

ah, right.  That's a different motivation, so I changed the commit message
in the attached.  Okay to push?

Thanks & have a nice day,
Berny



>From 5dae49b4fc7fd82583d6be033907f693e9832f83 Mon Sep 17 00:00:00 2001
From: Aron Barath <baratha...@caesar.elte.hu>
Date: Wed, 8 Aug 2018 09:39:42 +0200
Subject: [PATCH] fdleak.c: avoid compiler error on platforms lacking getrlimit

* lib/fdleak.c (get_max_fd): Move definition of the fd_limit variable
into the HAVE_GETRLIMIT block giving it a better scope: platforms
lacking getrlimit probably also lack struct rlimit, too.

Copyright-paperwork-exempt: Yes
---
 lib/fdleak.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/lib/fdleak.c b/lib/fdleak.c
index 38ff8360..818c0fbe 100644
--- a/lib/fdleak.c
+++ b/lib/fdleak.c
@@ -109,7 +109,6 @@ get_proc_max_fd (void)
 static int
 get_max_fd (void)
 {
-  struct rlimit fd_limit;
   long open_max;
 
   open_max = get_proc_max_fd ();
@@ -122,13 +121,16 @@ get_max_fd (void)
 
   /* We assume if RLIMIT_NOFILE is defined, all the related macros are, too. */
 #if defined HAVE_GETRLIMIT && defined RLIMIT_NOFILE
-  if (0 == getrlimit (RLIMIT_NOFILE, &fd_limit))
-    {
-      if (fd_limit.rlim_cur == RLIM_INFINITY)
-	return open_max;
-      else
-	return (int) fd_limit.rlim_cur;
-    }
+  {
+    struct rlimit fd_limit;
+    if (0 == getrlimit (RLIMIT_NOFILE, &fd_limit))
+      {
+	if (fd_limit.rlim_cur == RLIM_INFINITY)
+	  return open_max;
+	else
+	  return (int) fd_limit.rlim_cur;
+      }
+  }
 #endif
   /* cannot determine the limit's value */
   return open_max;
-- 
2.18.0

Reply via email to