PROCEDURE (HIDDEN) rap$create_aam_files (
  status)

*IF $variable(rav$proc_doc,declared)<>'UNKNOWN'

" PURPOSE:
"   This procedure creates the AAM lock and dependency files plus the
"   shared recovery log.
"
" NOTES:
"   In order to execute the AAM utilities in this procedure, the local
"   files AAF$44D_LIBRARY, AAF$4DD_LIBRARY, MLF$LIBRARY, SMF$LIBRARY,
"   and CYF$RUN_TIME_LIBRARY must exist and $SYSTEM.OSF$COMMAND_LIBRARY
"   must be on the command list.  The procedure assumes that all of these
"   products have been installed.
"
"   Executing ADMINISTER_RECOVERY_LOG utility displays messages to the
"   $ERRORS file.  These messages are redirected to the $JOB_LOG
"   by this procedure.
"
"   To facilitate running this procedure in test mode (ie.  from a terminal
"   running in ring 11), the variable rav$system is used.  Whenever the
"   value of the variable is not :$SYSTEM.$SYSTEM, then the procedure is in
"   test mode and commands commands requiring priviledge are skipped.
"
"   In order to delete the shared recovery log, use the commands:
"     administer_recovery_log
"       delete_log c=<shared_recovery_log catalog name> rc=no
"     quit
*IFEND

  "$FORMAT=OFF"
  VAR
    aam_catalog: file
    command_file: file = $unique($local)
    delete_status: status
    dependency_file_cycle: integer 1..999 = 7
    dependency_file_path: file
    execution_ring : integer 3..15
    ignore_status: status
    local_status: status
    lock_file_cycle: integer 1..999 = 7
    lock_file_path : file
    rav$system: (xref) file
    running_in_test_mode: boolean = (rav$system <> :$system.$system)
    shared_recovery_log_path: file
  VAREND
  "$FORMAT=ON"

  aam_catalog = rav$system.aam
  dependency_file_path = aam_catalog.AAF$DEPENDENCY_FILE
  lock_file_path = aam_catalog.AAF$LOCK_FILE
  shared_recovery_log_path = aam_catalog.SHARED_RECOVERY_LOG

install_block: ..
  BLOCK

    PUSH file_connections
    $system.delete_file_connection sf=$errors f=$local.output status=ignore_status
    $system.create_file_connection sf=$errors f=$job_log status=ignore_status

    " Delete old lock and dependency files.  Number of cycles unknown.

    IF running_in_test_mode THEN
      execution_ring = 11
    ELSE
      execution_ring = 4
    IFEND

    TASK ring=execution_ring

      REPEAT
        $system.delete_file f=lock_file_path status=delete_status
      UNTIL NOT delete_status.normal

      REPEAT
        $system.delete_file f=dependency_file_path status=delete_status
      UNTIL NOT delete_status.normal

    TASKEND

    " Create the dependency file.  This code is older than history itself.

    dependency_file_path = dependency_file_path//dependency_file_cycle

    $system.create_file f=dependency_file_path lfn=dependency
    $system.set_file_attributes f=dependency_file_path file_limit=100000
COLLECT_TEXT o=dependency_file_path
**
    $system.change_file_attributes $local.dependency fl=1000000
    $system.detach_file $local.dependency status=ignore_status
    $system.create_file_permit f=dependency_file_path g=public am=(read modify shorten append) sm=none
    IF NOT running_in_test_mode THEN
      $system.change_file_attributes f=dependency_file_path ra=(4 4 4) file_limit=100000000
    IFEND
    $system.change_catalog_entry f=dependency_file_path nl=yes

    " Create the lock file.

    lock_file_path = lock_file_path//lock_file_cycle

COLLECT_TEXT o=command_file until='COLLECT_END'
    ADMINISTER_LOCK_FILE
      use_lock_file lf=lock_file_path
      create_lock_file private=false
    QUIT
COLLECT_END

    $system.include_file command_file status=local_status
    $system.delete_file command_file status=ignore_status

    EXIT install_block WHEN NOT local_status.normal

    " Create the recovery log.

    IF running_in_test_mode THEN
      execution_ring = 11
    ELSE
      execution_ring = 6
    IFEND

    $system.create_catalog c=shared_recovery_log_path status=local_status

    IF local_status.normal THEN
      $system.create_catalog_permit c=shared_recovery_log_path group=public access_mode=(read write) ..
            share_mode=none
    IFEND

    IF (local_status.normal) OR ($condition(local_status.condition) = 'PFE$NAME_ALREADY_SUBCATALOG') THEN

COLLECT_TEXT o=command_file until='COLLECT_END'
  TASK ring=execution_ring
    ADMINISTER_RECOVERY_LOG
      use_log c=shared_recovery_log_path
      configure_log_residence status=ignore_status
    QUIT
  TASKEND
COLLECT_END

      $system.include_file command_file status=local_status
      $system.delete_file command_file status=ignore_status

    IFEND

    POP file_connections

  BLOCKEND install_block

  EXIT procedure WITH local_status WHEN NOT local_status.normal

PROCEND rap$create_aam_files
