mirror of
https://github.com/zeek/zeek.git
synced 2025-10-07 09:08:20 +00:00
Changes to open-file caching limits and uncached file unserialization.
- Unserializing files that were previously kicked out of the open-file cache would cause them to be fopen'd with the original access permissions which is usually 'w' and causes truncation. They are now opened in 'a' mode. (addresses #780) - Add 'max_files_in_cache' script option to manually set the maximum amount of opened files to keep cached. Mainly this just helped to create a simple test case for the above change. - Remove unused NO_HAVE_SETRLIMIT preprocessor switch. - On systems that don't enforce a limit on number of files opened for the process, raise default max size of open-file cache from 32 to 512.
This commit is contained in:
parent
8766a2e2fc
commit
bbac44a6a4
12 changed files with 104 additions and 11 deletions
20
src/File.cc
20
src/File.cc
|
@ -74,9 +74,8 @@ void RotateTimer::Dispatch(double t, int is_expire)
|
|||
|
||||
// The following could in principle be part of a "file manager" object.
|
||||
|
||||
#define MAX_FILE_CACHE_SIZE 32
|
||||
#define MAX_FILE_CACHE_SIZE 512
|
||||
static int num_files_in_cache = 0;
|
||||
static int max_files_in_cache = 0;
|
||||
static BroFile* head = 0;
|
||||
static BroFile* tail = 0;
|
||||
|
||||
|
@ -87,9 +86,6 @@ double BroFile::default_rotation_size = 0;
|
|||
// that we should use for the cache.
|
||||
static int maximize_num_fds()
|
||||
{
|
||||
#ifdef NO_HAVE_SETRLIMIT
|
||||
return MAX_FILE_CACHE_SIZE;
|
||||
#else
|
||||
struct rlimit rl;
|
||||
if ( getrlimit(RLIMIT_NOFILE, &rl) < 0 )
|
||||
reporter->InternalError("maximize_num_fds(): getrlimit failed");
|
||||
|
@ -111,7 +107,6 @@ static int maximize_num_fds()
|
|||
reporter->InternalError("maximize_num_fds(): setrlimit failed");
|
||||
|
||||
return rl.rlim_cur / 2;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
@ -172,7 +167,7 @@ const char* BroFile::Name() const
|
|||
return 0;
|
||||
}
|
||||
|
||||
bool BroFile::Open(FILE* file)
|
||||
bool BroFile::Open(FILE* file, const char* mode)
|
||||
{
|
||||
open_time = network_time ? network_time : current_time();
|
||||
|
||||
|
@ -196,7 +191,12 @@ bool BroFile::Open(FILE* file)
|
|||
InstallRotateTimer();
|
||||
|
||||
if ( ! f )
|
||||
f = fopen(name, access);
|
||||
{
|
||||
if ( ! mode )
|
||||
f = fopen(name, access);
|
||||
else
|
||||
f = fopen(name, mode);
|
||||
}
|
||||
|
||||
SetBuf(buffered);
|
||||
|
||||
|
@ -846,8 +846,8 @@ BroFile* BroFile::Unserialize(UnserialInfo* info)
|
|||
}
|
||||
}
|
||||
|
||||
// Otherwise, open.
|
||||
if ( ! file->Open() )
|
||||
// Otherwise, open, but don't clobber.
|
||||
if ( ! file->Open(0, "a") )
|
||||
{
|
||||
info->s->Error(fmt("cannot open %s: %s",
|
||||
file->name, strerror(errno)));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue