Browse Source

Merge commit 'c4105a6' into bfgminer-3.0.x

Conflicts:
	miner.c
Luke Dashjr 12 years ago
parent
commit
6e5ecacd0d
3 changed files with 35 additions and 0 deletions
  1. 2 0
      configure.ac
  2. 5 0
      logging.h
  3. 28 0
      miner.c

+ 2 - 0
configure.ac

@@ -535,6 +535,8 @@ if echo "$LIBCURL_CFLAGS" | grep '@CPPFLAG_CURL_STATICLIB@' >/dev/null 2>&1; the
 fi
 fi
 AC_SUBST(LIBCURL_LIBS)
 AC_SUBST(LIBCURL_LIBS)
 
 
+AC_CHECK_FUNCS([setrlimit])
+
 dnl CCAN wants to know a lot of vars.
 dnl CCAN wants to know a lot of vars.
 # All the configuration checks.  Regrettably, the __attribute__ checks will
 # All the configuration checks.  Regrettably, the __attribute__ checks will
 # give false positives on old GCCs, since they just cause warnings.  But that's
 # give false positives on old GCCs, since they just cause warnings.  But that's

+ 5 - 0
logging.h

@@ -31,6 +31,11 @@ extern int opt_log_level;
 extern void vapplog(int prio, const char *fmt, va_list ap) FORMAT_SYNTAX_CHECK(printf, 2, 0);
 extern void vapplog(int prio, const char *fmt, va_list ap) FORMAT_SYNTAX_CHECK(printf, 2, 0);
 extern void applog(int prio, const char *fmt, ...) FORMAT_SYNTAX_CHECK(printf, 2, 3);
 extern void applog(int prio, const char *fmt, ...) FORMAT_SYNTAX_CHECK(printf, 2, 3);
 
 
+#define applogr(rv, prio, ...)  do {  \
+	applog(prio, __VA_ARGS__);  \
+	return rv;  \
+} while (0)
+
 /* high-level logging functions with implicit priority */
 /* high-level logging functions with implicit priority */
 extern void log_error(const char *fmt, ...) FORMAT_SYNTAX_CHECK(printf, 1, 2);
 extern void log_error(const char *fmt, ...) FORMAT_SYNTAX_CHECK(printf, 1, 2);
 extern void log_warning(const char *fmt, ...) FORMAT_SYNTAX_CHECK(printf, 1, 2);
 extern void log_warning(const char *fmt, ...) FORMAT_SYNTAX_CHECK(printf, 1, 2);

+ 28 - 0
miner.c

@@ -7952,6 +7952,32 @@ extern void setup_pthread_cancel_workaround();
 extern struct sigaction pcwm_orig_term_handler;
 extern struct sigaction pcwm_orig_term_handler;
 #endif
 #endif
 
 
+static void raise_fd_limits(void)
+{
+#ifdef HAVE_SETRLIMIT
+	struct rlimit fdlimit;
+	unsigned long old_soft_limit;
+	
+	if (getrlimit(RLIMIT_NOFILE, &fdlimit))
+		applogr(, LOG_DEBUG, "setrlimit: Failed to getrlimit(RLIMIT_NOFILE)");
+	
+	if (fdlimit.rlim_cur == RLIM_INFINITY)
+		applogr(, LOG_DEBUG, "setrlimit: Soft fd limit already infinite");
+	
+	if (fdlimit.rlim_cur == fdlimit.rlim_max)
+		applogr(, LOG_DEBUG, "setrlimit: Soft fd limit already identical to hard limit (%lu)", (unsigned long)fdlimit.rlim_max);
+	
+	old_soft_limit = fdlimit.rlim_cur;
+	fdlimit.rlim_cur = fdlimit.rlim_max;
+	if (setrlimit(RLIMIT_NOFILE, &fdlimit))
+		applogr(, LOG_DEBUG, "setrlimit: Failed to increase soft fd limit from %lu to hard limit of %lu", old_soft_limit, (unsigned long)fdlimit.rlim_max);
+	
+	applog(LOG_DEBUG, "setrlimit: Increased soft fd limit from %lu to hard limit of %lu", old_soft_limit, (unsigned long)fdlimit.rlim_max);
+#else
+	applog(LOG_DEBUG, "setrlimit: Not supported by platform");
+#endif
+}
+
 int main(int argc, char *argv[])
 int main(int argc, char *argv[])
 {
 {
 	bool pools_active = false;
 	bool pools_active = false;
@@ -8090,6 +8116,8 @@ int main(int argc, char *argv[])
 	applog(LOG_DEBUG, "pthread_cancel workaround in use");
 	applog(LOG_DEBUG, "pthread_cancel workaround in use");
 #endif
 #endif
 
 
+	raise_fd_limits();
+	
 	if (opt_benchmark) {
 	if (opt_benchmark) {
 		struct pool *pool;
 		struct pool *pool;