Check-in [ea36882e15]
Overview
Comment:Updated to set resource limits for number of open files at startup, if possible
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: ea36882e154878cc7f9299197d1eeef9c8370f0e
User & Date: rkeene on 2015-10-14 17:48:16
Other Links: manifest | tags
Context
2015-11-19
16:01
Updated initializer to be explicitly unsigned check-in: f905360d64 user: rkeene tags: trunk
2015-10-14
17:48
Updated to set resource limits for number of open files at startup, if possible check-in: ea36882e15 user: rkeene tags: trunk
17:47
Updated to be more careful about closing files check-in: b357796ad5 user: rkeene tags: trunk
Changes

Modified appfsd.c from [6b6df68529] to [55077e4885].

17
18
19
20
21
22
23

24
25

26
27
28
29
30
31
32
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
#define FUSE_USE_VERSION 26


#include <sys/fsuid.h>
#include <sys/types.h>

#include <pthread.h>
#include <signal.h>
#include <limits.h>
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#include <unistd.h>







>


>







17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
#define FUSE_USE_VERSION 26

#include <sys/resource.h>  
#include <sys/fsuid.h>
#include <sys/types.h>
#include <sys/time.h>
#include <pthread.h>
#include <signal.h>
#include <limits.h>
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#include <unistd.h>
2167
2168
2169
2170
2171
2172
2173

2174
2175
2176

2177
2178
2179
2180
2181
2182
2183
/*
 * Entry point into this program.
 */
int main(int argc, char **argv) {
	Tcl_Interp *test_interp;
	char *test_interp_error;
	struct fuse_args args = FUSE_ARGS_INIT(0, NULL);

	int pthread_ret, aop_ret;
	void *signal_ret;
	char *argv0;


	/*
	 * Skip passed program name
	 */
	if (argc == 0 || argv == NULL) {
		return(1);
	}







>
|


>







2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
/*
 * Entry point into this program.
 */
int main(int argc, char **argv) {
	Tcl_Interp *test_interp;
	char *test_interp_error;
	struct fuse_args args = FUSE_ARGS_INIT(0, NULL);
	struct rlimit number_open_files;
	int pthread_ret, aop_ret, rlimit_ret;
	void *signal_ret;
	char *argv0;
	rlim_t number_open_files_max;

	/*
	 * Skip passed program name
	 */
	if (argc == 0 || argv == NULL) {
		return(1);
	}
2301
2302
2303
2304
2305
2306
2307

































2308
2309
2310
2311
2312
2313
2314
2315
	}

	Tcl_DeleteInterp(test_interp);

	if (appfs_threaded_tcl) {
		Tcl_FinalizeNotifier(NULL);
	}


































	/*
	 * Enter the FUSE main loop -- this will process any arguments
	 * and start servicing requests.
	 */
	appfs_fuse_started = 1;
	return(fuse_main(args.argc, args.argv, &appfs_operations, NULL));
}







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>








2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
	}

	Tcl_DeleteInterp(test_interp);

	if (appfs_threaded_tcl) {
		Tcl_FinalizeNotifier(NULL);
	}

	/*
	 * Increase resource limits for number of open files
	 * to the maximum values, since we may be asked to
	 * hold open many files on behalf of many other processes
	 */
	number_open_files.rlim_cur = number_open_files.rlim_max = RLIM_INFINITY;

	rlimit_ret = setrlimit(RLIMIT_NOFILE, &number_open_files);

	if (rlimit_ret != 0) {
		rlimit_ret = getrlimit(RLIMIT_NOFILE, &number_open_files);
		if (rlimit_ret == 0) {
			number_open_files_max = number_open_files.rlim_max;

			if (number_open_files_max < (1024 * 1024)) {
				number_open_files.rlim_cur = number_open_files.rlim_max = 1024 * 1024;

				rlimit_ret = setrlimit(RLIMIT_NOFILE, &number_open_files);
			} else {
				number_open_files.rlim_cur = number_open_files.rlim_max;
			}

			rlimit_ret = setrlimit(RLIMIT_NOFILE, &number_open_files);

			if (rlimit_ret != 0 && number_open_files.rlim_cur != number_open_files_max) {
				number_open_files.rlim_cur = number_open_files.rlim_max = number_open_files_max;

				setrlimit(RLIMIT_NOFILE, &number_open_files);
			}
		}
	}


	/*
	 * Enter the FUSE main loop -- this will process any arguments
	 * and start servicing requests.
	 */
	appfs_fuse_started = 1;
	return(fuse_main(args.argc, args.argv, &appfs_operations, NULL));
}