--yEPQxsgoJgBvi8ip
Content-Type: multipart/mixed; boundary="dDRMvlgZJXvWKvBx"
Content-Disposition: inline
--dDRMvlgZJXvWKvBx
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
Hi PostgreSQL developers!
Jacek Drobiecki recently sent me a patch which stops postgresql to
actively violate the system limit of maximum open files
(RLIMIT_NOFILE) in src/backend/storage/file/fd.c, function
count_usable_fds().=20
This avoids irritating kernel logs (if system overstep violations are
enabled) and also the grsecurity alert when starting PostgreSQL.
Can you please adopt this patch?
Currently the modifications are only enabled when postgresql is
compiled with -DCHECK_RLIMIT_NOFILE. Of course you can also use it
unconditionally.
Thanks for considering and have a nice day!
Martin
--=20
Martin Pitt Debian GNU/Linux Developer
martin (AT) piware (DOT) de mpitt (AT) debian (DOT) org
http://www.piware.de http://www.debian.org
--dDRMvlgZJXvWKvBx
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=08check_rlimit_nofile
Content-Transfer-Encoding: quoted-printable
diff -ruN postgresql-7.4.2-old/src/backend/storage/file/fd.c postgresql-7.4=
..2/src/backend/storage/file/fd.c
--- postgresql-7.4.2-old/src/backend/storage/file/fd.c 2004-02-24 00:03:43.=
000000000 +0100
+++ postgresql-7.4.2/src/backend/storage/file/fd.c 2004-05-17 13:31:44.0000=
00000 +0200
@@ -50,6 +50,9 @@
#include "storage/fd.h"
#include "storage/ipc.h"
=20
+#ifdef CHECK_RLIMIT_NOFILE
+#include <sys/resource.h>
+#endif
=20
/* Filename components for OpenTemporaryFile */
#define PG_TEMP_FILES_DIR "pgsql_tmp"
@@ -272,15 +275,28 @@
int used =3D 0;
int highestfd =3D 0;
int j;
+#ifdef CHECK_RLIMIT_NOFILE
+ struct rlimit rlim;
+#endif
=20
size =3D 1024;
fd =3D (int *) palloc(size * sizeof(int));
=20
+#ifdef CHECK_RLIMIT_NOFILE
+ getrlimit(RLIMIT_NOFILE, &rlim);
+#endif
+
/* dup until failure ... */
for (;

{
int thisfd;
=20
+#ifdef CHECK_RLIMIT_NOFILE
+ /* Don't go beyond RLIMIT_NOFILE */
+ if (highestfd >=3D rlim.rlim_cur - 1)
+ break;
+#endif
+
thisfd =3D dup(0);
if (thisfd < 0)
{
--dDRMvlgZJXvWKvBx--
--yEPQxsgoJgBvi8ip
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: Digital signature
Content-Disposition: inline
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
iD8DBQFAqK79DecnbV4Fd/IRAmFpAKDxOUZpDztht73Yifc8fUfkVP2+lQCgv4Hd
k7FK218LTZ2qgIeQdQjRcsU=
=fiAI
-----END PGP SIGNATURE-----
--yEPQxsgoJgBvi8ip--