You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by jo...@apache.org on 2006/05/16 16:17:03 UTC
svn commit: r406953 - /httpd/httpd/trunk/server/main.c
Author: jorton
Date: Tue May 16 07:17:02 2006
New Revision: 406953
URL: http://svn.apache.org/viewcvs?rev=406953&view=rev
Log:
* server/main.c (abort_on_oom): New function.
(create_process): Set abort callback for process pool.
(main): Set abort callback for global pool.
Reviewed by: colm
Modified:
httpd/httpd/trunk/server/main.c
Modified: httpd/httpd/trunk/server/main.c
URL: http://svn.apache.org/viewcvs/httpd/httpd/trunk/server/main.c?rev=406953&r1=406952&r2=406953&view=diff
==============================================================================
--- httpd/httpd/trunk/server/main.c (original)
+++ httpd/httpd/trunk/server/main.c Tue May 16 07:17:02 2006
@@ -40,6 +40,10 @@
#include "ap_mpm.h"
#include "mpm_common.h"
+#if APR_HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
/* WARNING: Win32 binds http_main.c dynamically to the server. Please place
* extern functions and global data in another appropriate module.
*
@@ -261,6 +265,17 @@
exit(process_exit_value);
}
+#define OOM_MESSAGE "[crit] Memory allocation failed, " \
+ "aborting process." APR_EOL_STR
+
+/* APR callback invoked if allocation fails. */
+static int abort_on_oom(int retcode)
+{
+ write(STDERR_FILENO, OOM_MESSAGE, strlen(OOM_MESSAGE));
+ abort();
+ return retcode; /* unreachable, hopefully. */
+}
+
static process_rec *create_process(int argc, const char * const *argv)
{
process_rec *process;
@@ -279,6 +294,7 @@
exit(1);
}
+ apr_pool_abort_set(abort_on_oom, cntx);
apr_pool_tag(cntx, "process");
ap_open_stderr_log(cntx);
@@ -448,6 +464,10 @@
pglobal = process->pool;
pconf = process->pconf;
ap_server_argv0 = process->short_name;
+
+ /* Set up the OOM callback in the global pool, so all pools should
+ * by default inherit it. */
+ apr_pool_abort_set(abort_on_oom, apr_pool_parent_get(process->pool));
#if APR_CHARSET_EBCDIC
if (ap_init_ebcdic(pglobal) != APR_SUCCESS) {