[an error occurred while processing this directive]

HP OpenVMS Systems

ask the wizard
Content starts here

out-of-band image intialization routines?

» close window

The Question is:

 
In most flavors of UNIX (and also NT), there is the availability of
"init/exit" routines on shared libraries. These routines (which are also
on Dec Unix) allow certain routines to be executed before the main function
is called. In the case of Dec Unix, the entry symbol is __init_ and the exit
symbol is __fini_. These symbols are user definable via the linker.
 
An example would be like as follows
cc test.c -init init_proc -fini exit_proc
 
(where the linker is passed  -init <procedure_name> -fini <procedure_name>).
 
The order of operations would then become :
 
init_proc
main
exit_proc
 
Is there any way of doing the same thing? This is expecially useful again
when someone links up to your shared image. This way you can hide variables
and such from the programmer (so he doesn't have to deal with them).
 
Any information would be extremly useful,
 
Chris
 


The Answer is :

 
  Please see the lib$initialize program section (psect) documentation for
  information on the image initialization support -- this is likely the
  most direct analog to the UNIX mechanism cited in your question.  This
  is introduced in the OpenVMS Programming Concepts manual, with additional
  information elsewhere in the OpenVMS documentation set.
 
  OpenVMS applications perform cleanup operations using a program-declared
  exit handler, using the sys$dclexh system service or the C atend() call.
 
  Mechanisms such as user-written exit handlers and signal handlers can be
  bypassed, depending on activity within the image and on activity of the
  user (such as a <CTRL/Y> followed by STOP).  Under most circumstances,
  the exit handlers and signal handlers are invoked when the image is
  run down.
 
  User-written system services include an inner-mode (privileged mode)
  image rundown routine in the PLV structure that is run at all times.
  This mechanism cannot be bypassed.
 
  Entry and exit routines can also be included via the debugger bootstrap
  mechanism -- a standard or user-written debugger can gain control prior
  to the main image, and regains control again when the image exits.  This
  mechanism is less commonly used, but is another direct analog to your
  question.  (You can also use lib$signal() of SS$_DEBUG to activate and
  pass commands to the standard OpenVMS debugger -- these program-requested
  debugger commands can be used for various purposes.)
 

answer written or last revised on ( 24-JUL-1998 )

» close window