Return-Path: pg_adm@postgres.berkeley.edu
Received: by postgres.Berkeley.EDU (5.61/1.29)
	id AA12543; Mon, 26 Apr 93 23:02:22 -0700
Date: Mon, 26 Apr 93 23:02:22 -0700
Message-Id: <9304270602.AA12543@postgres.Berkeley.EDU>
From: Christian Millour <chris@etca.fr>
Subject: Exit callback (Was: Several troubles with Postgres.)
To: postgres@postgres.berkeley.edu
Sender: pg_adm@postgres.berkeley.edu

   Date: Mon, 26 Apr 93 12:09:20 -0700
   From: fernando@afrodita.etsimo.uniovi.es (Fernando Ariznavarreta)

   [...]

				The trouble is that when I call PQsetdb(), if
   the Postmaster has crashed - or in many other errors- the library never returns
   control to my program it gives an error message and then makes an exit(1), so
   I cannot write my data to a file or try to make a crash recovery.
	   I think that a library - libpq in this case - shouldn't exit from
   the program on its own, 

my feeling too

                           it might return an error to the calling program and
   let it decide what to do in case of error. Doesn't anybody have this kind of
   problem with libpq?

For a quick and simple fix, and at least on sun boxes, you can use
on_exit(3) to register a routine to be executed after a program calls
exit(3). From the man page :

NAME
     on_exit - name termination handler

SYNOPSIS
     int on_exit(procp, arg)
     void (*procp)();
     caddr_t arg;

DESCRIPTION
     on_exit() names a routine to be called after a program calls
     exit(3)  or  returns  normally,  and before its process ter-
     minates.  The routine named is called as
          (*procp)(status, arg);
     where status is the argument with which exit()  was  called,
     or  zero  if main returns.  Typically, arg is the address of
     an argument vector to (*procp), but may be an integer value.
     Several  calls  may  be  made to on_exit, specifying several
     termination handlers.  The order in which they are called is
     the reverse of that in which they were given to on_exit.


Hope this helps,

   -- 
   Fernando Ariznavarreta Fernandez       E-Mail:fernando@etsimo.uniovi.es
   Dpto. Explotacion y Prospeccion de Minas     Phone: +34 8 510 4267
   School of Mines. University of Oviedo               +34 8 510 4336
   Independencia, 13                            Fax:   +34 8 510 4242
   Oviedo 33004, SPAIN                                 +34 8 510 4340


- Christian Millour         ETCA/CTME/GIS/CEPIA 
  chris@etca.fr             16bis Ave Prieur de la Cote d'Or
  [33] (1) 42 31 96 45      94114 Arcueil Cedex -- France
All opinions expressed are my own. Standard disclaimers apply. 



