home *** CD-ROM | disk | FTP | other *** search
/ vsiftp.vmssoftware.com / VSIPUBLIC@vsiftp.vmssoftware.com.tar / FREEWARE / FREEWARE40.ZIP / callmon / src / callmon$init.c < prev    next >
C/C++ Source or Header  |  1996-08-06  |  9KB  |  314 lines

  1. /*  CALLMON - A Call Monitor for OpenVMS Alpha
  2.  *
  3.  *  File:     CALLMON$INIT.C
  4.  *  Author:   Thierry Lelegard
  5.  *  Version:  1.0
  6.  *  Date:     24-JUL-1996
  7.  *
  8.  *  Abstract: This module contains CALLMON initialization routine.
  9.  */
  10.  
  11. #define DEFINE_CALLMON_OWN_STORAGE 1 /* allocate callmon$$own */
  12. #include "callmon$private.h"
  13.  
  14.  
  15. /*
  16.  *  This redefinition of CALLMON$_FACILITY forces a reference to
  17.  *  the message object file. This is necessary to have it included
  18.  *  in the application image file.
  19.  */
  20.  
  21. #ifdef CALLMON$_FACILITY
  22. #undef CALLMON$_FACILITY
  23. #endif
  24.  
  25. #pragma extern_model save
  26. #pragma extern_model globalvalue
  27. extern unsigned int CALLMON$_FACILITY;
  28. static unsigned int unused_facility = CALLMON$_FACILITY;
  29. #pragma extern_model restore
  30.  
  31.  
  32. /*******************************************************************************
  33.  *
  34.  *  The following declarations include CALLMON initialization routine
  35.  *  in psect LIB$INITIALIZE. Note that DEC C V5.3 or higher is required
  36.  *  to include psect attributes in pragma extern_model.
  37.  *
  38.  *  These declarations are not compiled by default. If the macro 
  39.  *  CALLMON_AUTO_INITIALIZE is not defined (default) CALLMON is
  40.  *  initialized during the first call to one of its public routines.
  41.  */
  42.  
  43. #ifdef CALLMON_AUTO_INITIALIZE
  44.  
  45. void LIB$INITIALIZE ();
  46. static void (*dummy)() = LIB$INITIALIZE;  /* force a reference */
  47.  
  48. #pragma extern_model save
  49. #pragma extern_model strict_refdef "LIB$INITIALIZE" long, gbl, noshr, nowrt
  50. uint32 (*const callmon$$initialize_vector) (void) = callmon$initialize;
  51. #pragma extern_model restore
  52.  
  53. #endif
  54.  
  55.  
  56. /*******************************************************************************
  57.  *
  58.  *  This routine initializes the trace flags according to logical name.
  59.  *
  60.  *  The logical name CALLMON$TRCE should be defined as a search list of
  61.  *  keywords. The list of keywords is defined in the trace_flags_list array.
  62.  *
  63.  *  Examples:
  64.  *
  65.  *      $ DEFINE CALLMON$TRACE RELOCATION, FIXUP
  66.  *      $ DEFINE CALLMON$TRACE ALL
  67.  */
  68.  
  69. static void init_trace_flags (void)
  70. {
  71.     uint32 status;
  72.     int32 flag;
  73.     int count;
  74.     int index;
  75.     char value [256];
  76.  
  77.     if ((count = callmon$$translation_count ("CALLMON$TRACE", NULL)) <= 0)
  78.         return;
  79.  
  80.     for (index = 0; index < count; index++) {
  81.  
  82.         status = callmon$$translate ("CALLMON$TRACE", value, sizeof (value),
  83.             NULL, index);
  84.  
  85.         if (!$VMS_STATUS_SUCCESS (status))
  86.             continue;
  87.  
  88.         flag = callmon$$name_to_value (callmon$$trace_flags_names, value, 0);
  89.  
  90.         if (flag == 0)
  91.             callmon$$putmsg (CALLMON$_IVTRFLG, 1, value);
  92.         else
  93.             callmon$$own.trace_flags |= flag;
  94.     }
  95.  
  96.     if (callmon$$own.trace_flags != 0)
  97.         callmon$$putmsg (CALLMON$_TRFLG, 1, callmon$$own.trace_flags);
  98. }
  99.  
  100.  
  101. /*******************************************************************************
  102.  *
  103.  *  This routine initializes the logical name CALLMON$TRACE_DIRECTORY.
  104.  *  If it is not defined, define it to SYS$DISK:[] in used mode.
  105.  */
  106.  
  107. static void init_trace_directory (void)
  108. {
  109.     uint32 status;
  110.     item_t* itm;
  111.     item_t itmlst [5];
  112.     char value [FILE_SPEC_SIZE];
  113.  
  114.     static $DESCRIPTOR (name_d, "CALLMON$TRACE_DIRECTORY");
  115.     static $DESCRIPTOR (table_d, "LNM$PROCESS_TABLE");
  116.  
  117.     /* If the logical name exists, return */
  118.  
  119.     status = callmon$$translate (name_d.dsc$a_pointer, value, sizeof (value),
  120.         NULL, 0);
  121.  
  122.     if ($VMS_STATUS_SUCCESS (status))
  123.         return;
  124.  
  125.     /* Otherwise, define to default value */
  126.  
  127.     itm = itmlst;
  128.     set_str_item (itm++, LNM$_STRING, "SYS$DISK:[]");
  129.     set_final_item (itm++);
  130.  
  131.     status = sys$crelnm (0, &table_d, &name_d, 0, itmlst);
  132.  
  133.     if (!$VMS_STATUS_SUCCESS (status))
  134.         callmon$$putmsg (CALLMON$_DEFINE, 1, name_d.dsc$a_pointer, status);
  135. }
  136.  
  137.  
  138. /*******************************************************************************
  139.  *
  140.  *  This routine determines the BSR replacement according to logical name
  141.  *  CALLMON$BSR_REPLACEMENT. See file CALLMON$BRANCH,C for the usage of
  142.  *  the BSR replacement.
  143.  */
  144.  
  145. static void init_bsr_replacement (void)
  146. {
  147.     static name_value_t name_list [] = {
  148.         {BSR_OFF,    "OFF"},
  149.         {BSR_IF_R27, "IF_R27"},
  150.         {BSR_ALL,    "ALL"},
  151.         {0,          NULL}
  152.     };
  153.  
  154.     uint32 status;
  155.     int32 value;
  156.     char str [80];
  157.  
  158.     status = callmon$$translate ("CALLMON$BSR_REPLACEMENT", str, sizeof (str),
  159.         NULL, 0);
  160.  
  161.     if (!$VMS_STATUS_SUCCESS (status))
  162.         return;
  163.  
  164.     value = callmon$$name_to_value (name_list, str, -1);
  165.  
  166.     if (value < 0)
  167.         callmon$$putmsg (CALLMON$_IVBSRREP, 1, str);
  168.     else {
  169.         callmon$$own.bsr_replacement = value;
  170.         if (callmon$$own.trace_flags & TRACE_CONFIGURATION)
  171.             callmon$$putmsg (CALLMON$_BSRREP, 2, str,
  172.                 callmon$$own.bsr_replacement);
  173.     }
  174. }
  175.  
  176.  
  177. /*******************************************************************************
  178.  *
  179.  *  This routine initializes the BSR depth according to logical name
  180.  *  CALLMON$BSR_DEPTH. See file CALLMON$BRANCH,C for the usage of the
  181.  *  BSR depth.
  182.  */
  183.  
  184. static void init_bsr_depth (void)
  185. {
  186.     uint32 status;
  187.     int val;
  188.     char str [80];
  189.  
  190.     status = callmon$$translate ("CALLMON$BSR_DEPTH", str, sizeof (str),
  191.         NULL, 0);
  192.  
  193.     if ($VMS_STATUS_SUCCESS (status)) {
  194.         if ((val = atoi (str)) <= 0)
  195.             callmon$$putmsg (CALLMON$_INVBSRDEP, 1, str);
  196.         else {
  197.             callmon$$own.bsr_depth = val;
  198.             if (callmon$$own.trace_flags & TRACE_CONFIGURATION)
  199.                 callmon$$putmsg (CALLMON$_BSRDEPTH, 1, callmon$$own.bsr_depth);
  200.         }
  201.     }
  202. }
  203.  
  204.  
  205. /*******************************************************************************
  206.  *
  207.  *  CALLMON initialization routine.
  208.  *
  209.  *  Called during the LIB$INITIALIZE process.
  210.  */
  211.  
  212. uint32 callmon$initialize (void)
  213. {
  214.     imcb_t* imcb;
  215.     int image_count;
  216.     int routine_count;
  217.     image_t* image;
  218.     char** name;
  219.     int not_monitored;
  220.     thread_state_t thread_state;
  221.  
  222.     /* Execute only once */
  223.  
  224.     static int done = 0;
  225.  
  226.     if (done)
  227.         return SS$_NORMAL;
  228.  
  229.     done = 1;
  230.  
  231.     callmon$$disable_threading (&thread_state);
  232.  
  233.     /* Get initial state */
  234.  
  235.     init_trace_flags ();
  236.  
  237.     if (callmon$$own.trace_flags)
  238.         callmon$$putmsg (CALLMON$_INIT, 0);
  239.  
  240.     init_trace_directory ();
  241.     init_bsr_replacement ();
  242.     init_bsr_depth ();
  243.  
  244.     callmon$$own.uninterceptable_routines_sup = 
  245.         callmon$$search_list ("CALLMON$NO_INTERCEPTION", NULL);
  246.  
  247.     callmon$$own.unrelocatable_routines_sup =
  248.         callmon$$search_list ("CALLMON$NO_RELOCATION", NULL);
  249.  
  250.     /* Load all image descriptors */
  251.  
  252.     image_count = 0;
  253.     routine_count = 0;
  254.     not_monitored = 0;
  255.  
  256.     for (imcb = iac$gl_image_list.imcb$l_blink;
  257.          imcb != &iac$gl_image_list;
  258.          imcb = imcb->imcb$l_blink) {
  259.  
  260.         if ((image = callmon$$load_image (imcb)) != NULL) {
  261.             image_count++;
  262.             routine_count += image->routine_count;
  263.             if (image->resident && image->protected)
  264.                 not_monitored++;
  265.         }
  266.     }
  267.  
  268.     if (not_monitored > 0)
  269.         callmon$$putmsg (CALLMON$_FROMNOTMON, 0);
  270.  
  271.     /* Record uninterceptable routines */
  272.  
  273.     for (name = callmon$$own.uninterceptable_routines; *name != NULL; name++)
  274.         callmon$$set_uninterceptable (callmon$$get_routine_by_name (*name));
  275.  
  276.     if (callmon$$own.uninterceptable_routines_sup != NULL) {
  277.  
  278.         for (name = callmon$$own.uninterceptable_routines_sup;
  279.              *name != NULL; name++)
  280.             callmon$$set_uninterceptable (callmon$$get_routine_by_name (*name));
  281.  
  282.         if (callmon$$own.trace_flags & TRACE_CONFIGURATION)
  283.             for (name = callmon$$own.uninterceptable_routines_sup;
  284.                  *name != NULL; name++)
  285.                 callmon$$putmsg (CALLMON$_UDUNINT, 1, *name);
  286.     }
  287.  
  288.     /* Record unrelocatable routines */
  289.  
  290.     for (name = callmon$$own.unrelocatable_routines; *name != NULL; name++)
  291.         callmon$$set_unrelocatable (callmon$$get_routine_by_name (*name));
  292.  
  293.     if (callmon$$own.unrelocatable_routines_sup != NULL) {
  294.  
  295.         for (name = callmon$$own.unrelocatable_routines_sup;
  296.              *name != NULL; name++)
  297.             callmon$$set_unrelocatable (callmon$$get_routine_by_name (*name));
  298.  
  299.         if (callmon$$own.trace_flags & TRACE_CONFIGURATION)
  300.             for (name = callmon$$own.unrelocatable_routines_sup;
  301.                  *name != NULL; name++)
  302.                 callmon$$putmsg (CALLMON$_UDUNREL, 1, *name);
  303.     }
  304.  
  305.     /* End of initialization */
  306.  
  307.     if (callmon$$own.trace_flags)
  308.         callmon$$putmsg (CALLMON$_INOK, 2, image_count, routine_count);
  309.  
  310.     callmon$$restore_threading (&thread_state);
  311.  
  312.     return SS$_NORMAL;
  313. }
  314.