[dovecot-cvs] dovecot/src/lib restrict-process-size.c,NONE,1.1 restrict-process-size.h,NONE,1.1 Makefile.am,1.15,1.16

cras at procontrol.fi cras at procontrol.fi
Sun Dec 1 15:48:52 EET 2002


Update of /home/cvs/dovecot/src/lib
In directory danu:/tmp/cvs-serv27190/src/lib

Modified Files:
	Makefile.am 
Added Files:
	restrict-process-size.c restrict-process-size.h 
Log Message:
Added virtual memory size limits to processes. Default values are pretty
high, this is mostly because I want it to prevent accidental infinite loops
eating memory or some integer overflows, not to actually restrict anything.



--- NEW FILE: restrict-process-size.c ---
/*
    Copyright (c) 2002 Timo Sirainen

    Permission is hereby granted, free of charge, to any person obtaining
    a copy of this software and associated documentation files (the
    "Software"), to deal in the Software without restriction, including
    without limitation the rights to use, copy, modify, merge, publish,
    distribute, sublicense, and/or sell copies of the Software, and to
    permit persons to whom the Software is furnished to do so, subject to
    the following conditions:

    The above copyright notice and this permission notice shall be
    included in all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
    OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
    IN NO EVENT SHALL THE 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.
*/

#include "lib.h"
#include "restrict-process-size.h"

#include <unistd.h>
#include <sys/time.h>
#ifdef HAVE_SYS_RESOURCE_H
#  include <sys/resource.h>
#endif

void restrict_process_size(unsigned int size __attr_unused__)
{
#ifdef HAVE_SETRLIMIT
	struct rlimit rlim;

	rlim.rlim_max = rlim.rlim_cur =
		size > 0 && size < INT_MAX/1024/1024 ?
		size*1024*1024 : RLIM_INFINITY;
	if (setrlimit(RLIMIT_AS, &rlim) < 0)
		i_fatal("setrlimit(RLIMIT_AS, %u): %m", size);
#else
	if (size != 0) {
		i_warning("Can't restrict process size: "
			  "setrlimit() not supported by system. "
			  "Set the limit to 0 to hide this warning.");
	}
#endif
}

--- NEW FILE: restrict-process-size.h ---
#ifndef __RESTRICT_PROCESS_SIZE_H
#define __RESTRICT_PROCESS_SIZE_H

/* Restrict max. process size. The size is in megabytes, setting it to
   (unsigned int)-1 sets it unlimited. */
void restrict_process_size(unsigned int size);

#endif

Index: Makefile.am
===================================================================
RCS file: /home/cvs/dovecot/src/lib/Makefile.am,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- Makefile.am	26 Nov 2002 19:49:06 -0000	1.15
+++ Makefile.am	1 Dec 2002 13:48:50 -0000	1.16
@@ -37,6 +37,7 @@
 	primes.c \
 	randgen.c \
 	restrict-access.c \
+	restrict-process-size.c \
 	sendfile-util.c \
 	strfuncs.c \
 	temp-string.c \
@@ -77,6 +78,7 @@
 	primes.h \
 	randgen.h \
 	restrict-access.h \
+	restrict-process-size.h \
 	sendfile-util.h \
 	strfuncs.h \
 	temp-string.h \




More information about the dovecot-cvs mailing list