Browse code

bb11463 - patch by Jim Morris to increase clamd's soft file descriptor to its potential maximum on 64-bit systems

Mickey Sola authored on 2016/03/15 05:07:45
Showing 1 changed files
... ...
@@ -1112,22 +1112,60 @@ int recvloop_th(int *socketds, unsigned nsockets, struct cl_engine *engine, unsi
1112 1112
 	int max_max_queue;
1113 1113
 	unsigned warn = optget(opts, "MaxQueue")->active;
1114 1114
 	const unsigned clamdfiles = 6;
1115
+#ifdef C_SOLARIS
1116
+	int solaris_has_extended_stdio = 0;
1117
+#endif
1115 1118
 	/* Condition to not run out of file descriptors:
1116 1119
 	 * MaxThreads * MaxRecursion + (MaxQueue - MaxThreads) + CLAMDFILES < RLIMIT_NOFILE 
1117 1120
 	 * CLAMDFILES is 6: 3 standard FD + logfile + 2 FD for reloading the DB
1118 1121
 	 * */
1119 1122
 #ifdef C_SOLARIS
1123
+
1124
+	/*
1125
+	**  If compiling 64bit, then set the solaris_has_extended_stdio
1126
+	**  flag
1127
+	*/
1128
+
1129
+#if defined(_LP64)
1130
+	solaris_has_extended_stdio++;
1131
+#endif
1132
+
1120 1133
 #ifdef HAVE_ENABLE_EXTENDED_FILE_STDIO
1121 1134
 	if (enable_extended_FILE_stdio(-1, -1) == -1) {
1122 1135
 	    logg("^Unable to set extended FILE stdio, clamd will be limited to max 256 open files\n");
1123 1136
 	    rlim.rlim_cur = rlim.rlim_cur > 255 ? 255 : rlim.rlim_cur;
1124 1137
 	}
1138
+	else
1139
+	{
1140
+	   solaris_has_extended_stdio++;
1141
+	}
1142
+
1125 1143
 #elif !defined(_LP64)
1126
-	if (rlim.rlim_cur > 255) {
1144
+	if (solaris_has_extended_stdio && rlim.rlim_cur > 255) {
1127 1145
 	    rlim.rlim_cur = 255;
1128 1146
 	    logg("^Solaris only supports 256 open files for 32-bit processes, you need at least Solaris 10u4, or compile as 64-bit to support more!\n");
1129 1147
 	}
1130 1148
 #endif
1149
+
1150
+	/*
1151
+	**  If compiling in 64bit or the file stdio has been extended,
1152
+	**  then increase the soft limit for the number of open files
1153
+	**  as the default is usually 256
1154
+	*/
1155
+
1156
+	if (solaris_has_extended_stdio)
1157
+	{
1158
+	   rlim_t saved_soft_limit = rlim.rlim_cur;
1159
+
1160
+	   rlim.rlim_cur = rlim.rlim_max;
1161
+	   if (setrlimit (RLIMIT_NOFILE, &rlim) < 0)
1162
+	   {
1163
+	      logg("!setrlimit() for RLIMIT_NOFILE to %lu failed: %s\n",
1164
+		   (unsigned long) rlim.rlim_cur, strerror (errno));
1165
+	      rlim.rlim_cur = saved_soft_limit;
1166
+	   }
1167
+	} /*  If 64bit or has extended stdio  */
1168
+
1131 1169
 #endif
1132 1170
 	opt = optget(opts,"MaxRecursion");
1133 1171
 	maxrec = opt->numarg;