Commit 2cf9d925 authored by Per Cederqvist's avatar Per Cederqvist
Browse files

(initialize): Use setrlimit to increase the limit on number of open

	file descriptors, if the config file says to do so.
	Moved code to calculate number of open connections here from main().
(main): Some code moved to initialize().
parent 221da4ce
/*
* $Id: ramkomd.c,v 0.51 1994/06/29 23:30:59 ceder Exp $
* $Id: ramkomd.c,v 0.52 1994/10/24 00:34:39 ceder Exp $
* Copyright (C) 1991, 1992, 1993, 1994 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
......@@ -31,7 +31,7 @@
* It has grown! /ceder
*/
static char *rcsid = "$Id: ramkomd.c,v 0.51 1994/06/29 23:30:59 ceder Exp $";
static char *rcsid = "$Id: ramkomd.c,v 0.52 1994/10/24 00:34:39 ceder Exp $";
#include "rcs.h"
USE(rcsid);
......@@ -51,6 +51,9 @@ USE(rcsid);
#endif
#include <sys/wait.h>
#include <time.h>
#ifdef HAVE_SYS_RESOURCE_H
# include <sys/resource.h>
#endif
#include <unistd.h>
#include <setjmp.h>
#if defined(HAVE_SYS_PARAM_H) && !defined(HAVE_GETCWD)
......@@ -84,6 +87,10 @@ USE(rcsid);
#include "server-config.h"
#include "manipulate.h"
#if defined(HAVE_SETRLIMIT) && defined(RLIMIT_OFILE) && !defined(RLIMIT_NOFILE)
# define RLIMIT_NOFILE RLIMIT_OFILE
#endif
struct kom_par param;
Kom_err kom_errno = KOM_NO_ERROR;
......@@ -292,6 +299,10 @@ go_daemon(const char *prefix, const char *logf)
void
initialize(const char *config_file)
{
#if defined(HAVE_SETRLIMIT) && defined(RLIMIT_NOFILE)
struct rlimit rlim;
#endif
read_configuration(config_file);
#ifdef HAVE_LOCALE_H
......@@ -309,6 +320,52 @@ initialize(const char *config_file)
exit(1);
}
#endif
#if defined(HAVE_SETRLIMIT) && defined(RLIMIT_NOFILE)
if (param.no_file != -1)
{
if (getrlimit(RLIMIT_NOFILE, &rlim) < 0)
{
perror("getrlimit(RLIMIT_NOFILE) failed");
exit(1);
}
if (param.no_files > rlim.rlim_max)
{
fprintf(stderr, "attempt to raise open files from %d to %d, "
"but only %d is allowed\n", rlim.rlim_cur, param.no_files,
rlim.rlim_max);
rlim.rlim_cur = rlim.rlim_max;
}
else
rlim.rlim_cur = param.no_files;
if (setrlimit(RLIMIT_NOFILE, &rlim) < 0)
{
perror("setrlimit failed");
exit(1);
}
}
#else
if (param.no_files != -1)
{
fprintf(stderr,
"can't alter number of open files in your environment.\n");
exit(1);
}
#endif
/* Find out how many connections we can handle. */
#if defined (HAVE_SYSCONF)
MAX_NO_OF_CONNECTIONS = sysconf(_SC_OPEN_MAX) - PROTECTED_FDS;
#else
# ifdef HAVE_GETDTABLESIZE
MAX_NO_OF_CONNECTIONS = getdtablesize() - PROTECTED_FDS;
# else
/* If we don't have getdtablesize or sysconf, MAX_NO_OF_CONNECTIONS is
set at compile time. */
# endif
#endif
go_daemon(param.dbase_dir, param.logfile_name);
server_init(param.ip_client_port, param.ip_mux_port);
init_data_base(param.dbase_dir);
......@@ -330,20 +387,6 @@ main (int argc,
#include "version.incl"
, getpid());
/* Find out how many connections we can handle. */
#if defined (HAVE_SYSCONF)
MAX_NO_OF_CONNECTIONS = sysconf(_SC_OPEN_MAX) - PROTECTED_FDS;
#else
# ifdef HAVE_GETDTABLESIZE
MAX_NO_OF_CONNECTIONS = getdtablesize() - PROTECTED_FDS;
# else
/* If we don't have getdtablesize or sysconf, MAX_NO_OF_CONNECTIONS is
set at compile time. */
# endif
#endif
#ifdef ENCRYPT_PASSWORDS
/* Seed the random number generator. */
srand(time(NULL) + getpid());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment