This is the first of the series of commits to import PostgreSQL's exception and memory manager in pgpool.
This checkin includes the following items.

1-- Exception manager API of Postgres is added to pgpool, The API consists of elog.c and elog.h files.
Since this API is very extensive and is designed for PostgreSQL, So to fit it properly into pgpool I have
modified it a little bit, and most of the modifications are related to removal of code which is not required for pgpool.

2-- Added on_proc_exit callback mechanism of Postgres. To facilitate the cleanup at exit time.

3-- Added PostgreSQL's memory manager (palloc API). This includes the client side palloc functions placed in 'src/tools' directory (fe_memutils)

4-- Removed the existing memory manager which was very minimalistic and was not integrated in all parts of the code.

5-- The checkin also refectors some portions of code to make the code more readable at first glance. That includes

-- Dividing the main.c file into two files main.c and pgpool_main.c, Now the main.c file only contains the code
related to early initialisations of pgpool and parsing of the command line options.
The actual logic of the pgpool main process is moved to new pgpool_main.c file.
-- Breaking up some large functions in child.c into smaller functions.
-- Rewrite the pgpool's main loop logic to make the code more readable.

Remaining TODOs on this front.

1-- The current checkin only integrates the memory and exception manager in main process and connection creation
segment of pgpool child process. And the next TODO is to integrate it in pcp and worker child process.

2-- Integration of newly added API into query processor logic in child processes.

3-- elog.c and elog.h files needs some cleanups and changes (To remove unwanted functions and data members of ErrorData structure).
Integrating the exception and memory manager in pcp child process
Some more on integration of exception and memory manager front.
The current checkin includes creation of per loop iteration memory context for
worker child process, and integration of above in some parts of query processing logics.
For the query processing function all my current code browsing leads me to the
believe that although "pool_process_query()" caller has handled five possible
return values from the function i.e POOL_END, POOL_ERROR, POOL_FATAL,
POOL_IDLE and POOL_CONTINUE, but in actual the function returns only POOL_END,
POOL_ERROR and the success which is POOL_CONTINUE. and to squeeze in the managers
in query processing function I am moving forward with the above mentioned assumption.
Finally the checkin puts the wrapper on pool_read function, "pool_read_with_error()"
which throws an ereport instead of returning -ve status in case of an error.
And this wrapper will live till the time when all the callers of pool_read()
will be decorated with the exception manager.
Merge branch 'master' into EXCEPTION_MGR

Conflicts:
	src/auth/pool_auth.c
	src/main/main.c
fixing the pgpool main process loop to properly integrating it with the
new exception and memory manager. Also changing some of the free() calls
to pfree(), which were mistakenly left out and were caught by the regression test.
Add mention about listen queue and how to increase the backlog in the num_init_children section.
Merge branch 'master' into EXCEPTION_MGR

Conflicts:
	doc/pgpool-en.html
	doc/pgpool-ja.html
	src/include/pool.h
	src/main/main.c
	src/protocol/child.c
	src/tools/pgmd5/Makefile.am
This is the penultimate patch for integration of memory and exception manager APIs into pgpool.
The commit is very large mainly because of replacing of pool_error(), pool_debug() and pool_log() function calls to ereport(ERROR,..) ereport(DEBUG,..) and ereport(LOG,..)
Below is the description of few areas changed by the commit

Some Important Memory Contexts
============================

    ProcessLoopContext:
    This context resets at every main loop iteration of a process

    TopMemoryContext:
    This context is same as PostgreSQL's TopMemoryContext and lives for a life time of process.

    ErrorContext:
    Same as PostgreSQL's ErrorContext and used for error processing.

    QueryContext:
    Used by pgpool child process and it lives for single query cycle.

Lifecycle of Important Objects
==============================

    SessionContext:
    The session context consists of a backend and frontend connection and it lives for a single iteration of main child process loop.
    So the session context object is created in ProcessLoopContext.

    ProcessContext:
    ConnectionPool:
    BackendConnection:
    The above objects are required for the life of process hence are created in TopMemoryContext which lives throughout the process life time.

    Child Frontend connection:
    Frontend connection object is placed in the ProcessLoopContext since new frontend connection is created at every main loop iteration of pgpool child process.

    PCP Frontend connection:
    This object can live till the pcp process so the object for pcp frontend is created in TopMemoryContext.

new configuration parameters
===========================

    The patch also adds three new configuration parameters to control the error reporting style and details.
    Parameters names and their behaviours are borrowed from PostgreSQL.
    int log_error_verbosity;    /* controls how much detail about error should be emitted */
    int client_min_messages;    /*controls which message should be sent to client */
    int log_min_messages;       /*controls which message should be emitted to server log */

Some other notable changes introduced by the patch.
================================================

    The patch changes the error reporting behaviour and now pgpool-II tries to send all the error and log messages to the connected frontend clients (controllable by "client_min_messages" configuration pa
    The patch added an extra call back "on_system_exit" to the elog API, which is not present in the PostgreSQL.
Merge branch 'master' into EXCEPTION_MGR

Conflicts:
	src/config/pool_config.c
	src/libs/pcp/Makefile.am
	src/libs/pcp/Makefile.in
	src/libs/pcp/pcp.c
	src/main/main.c
	src/protocol/child.c
	src/protocol/pool_process_query.c
	src/utils/pcp/pcp_stream.c
Faulty logic of find_primary_node() function having pgtry-catch block inside the for-loop was causing
the find_primary_node() to return wrong primary node id, when an error is thrown from
make_persistent_db_connection() and for-loop gets terminated prematurely.
This check-in fixes the issue by creating the wrapper verify_backend_node_status()
over make_persistent_db_connection() and related logic of verifying backend node connectivity.
Hence removing the try-catch from find_primary_node() loop, which was the cause of problem.
Fixing the compiler warnings
This is the first of the series of commits to import PostgreSQL's exception and memory manager in pgpool.
This checkin includes the following items.

1-- Exception manager API of Postgres is added to pgpool, The API consists of elog.c and elog.h files.
Since this API is very extensive and is designed for PostgreSQL, So to fit it properly into pgpool I have
modified it a little bit, and most of the modifications are related to removal of code which is not required for pgpool.

2-- Added on_proc_exit callback mechanism of Postgres. To facilitate the cleanup at exit time.

3-- Added PostgreSQL's memory manager (palloc API). This includes the client side palloc functions placed in 'src/tools' directory (fe_memutils)

4-- Removed the existing memory manager which was very minimalistic and was not integrated in all parts of the code.

5-- The checkin also refectors some portions of code to make the code more readable at first glance. That includes

-- Dividing the main.c file into two files main.c and pgpool_main.c, Now the main.c file only contains the code
related to early initialisations of pgpool and parsing of the command line options.
The actual logic of the pgpool main process is moved to new pgpool_main.c file.
-- Breaking up some large functions in child.c into smaller functions.
-- Rewrite the pgpool's main loop logic to make the code more readable.

Remaining TODOs on this front.

1-- The current checkin only integrates the memory and exception manager in main process and connection creation
segment of pgpool child process. And the next TODO is to integrate it in pcp and worker child process.

2-- Integration of newly added API into query processor logic in child processes.

3-- elog.c and elog.h files needs some cleanups and changes (To remove unwanted functions and data members of ErrorData structure).
Integrating the exception and memory manager in pcp child process
Add description that it is recommended to specify multiple servers to trusted_servers
Fix uninitialized variable in error case in pool_do_auth().

If there's no valid backend, pgpool will return garbage pid to
frontend in auth phase. Actually because no backend is available,
frontend will be disconnected later on. So this is not harmless.
Per Coverity report "1127331 Uninitialized scalar variable".
Remove unused code.

Per Coverity report #1111487 "Uninitialized pointer read".
Fix to add node id range check when issue an error message using node id.

Per Coverity report #1111433 "Out-of-bounds read".
Fix buffer overrun bug and resource leak bug of parse_copy_data().

Per Coverity report 1111427 "Out-of-bounds write" and 1111453
"Resource leak".
Fix possible segfault in CopyDataRaws().

Coverity pointed out that if pool_get_id() returns an error,
VALID_BACKEND will access out of array.  Per Coverity report 1111413
"Memory - illegal accesses".
Fix query cache is enabled and protocol version = 2 case.

When the protocol version = 2, we assume that session state is "idle".
This is not feasible but no way. I recommend to not use query cache
with protocol 2.
Per Coverity report 1111488 "Uninitialized scalar variable".