1 /* ***********************************************************
  2    *                                                         *
  3    * Copyright, (C) Honeywell Information Systems Inc., 1982 *
  4    *                                                         *
  5    *********************************************************** */
  6 /* format: style2,ind3 */
  7 detach_audit:
  8 dta:
  9    proc;
 10 
 11 /*  This module turns off auditing for the calling process.  The single parameter
 12    is the switchname of the switch attached via the audit_ module that is to be detached.
 13 
 14 Modified:
 15 11/12/81 by Lindsey Spratt: changed the variable "whoami" to "MYNAME", making
 16             it an internal constant as well.
 17 10/13/82 by Lindsey Spratt:  Changed to destroy the new_iocb, which is no
 18             longer needed after the move_attach.  Also, removed the
 19             set_safety_sw, as this is done by iox_$close.  Changed to
 20             use error_table_$badopt when too many args are given, rather than
 21             a 0 error code.
 22 */
 23 
 24 /*  Automatic  */
 25 
 26       dcl     nargs                  fixed bin;
 27       dcl     tc                     fixed bin;
 28       dcl     tp                     ptr;
 29       dcl     blkptr                 ptr;
 30       dcl     old_iocb               ptr;
 31       dcl     new_iocb               ptr;
 32       dcl     code                   fixed bin (35);
 33 
 34 /*  Based  */
 35 
 36       dcl     targ                   char (tc) based (tp);
 37 
 38 /* Constant */
 39 
 40       dcl     MYNAME                 char (12) init ("detach_audit") internal static options (constant);
 41 
 42 /* Entries  */
 43 
 44       dcl     audit_$audit_close     entry;
 45       dcl     cu_$arg_count          entry (fixed bin);
 46       dcl     cu_$arg_ptr            entry (fixed bin, ptr, fixed bin, fixed bin (35));
 47       dcl     ioa_$ioa_switch        entry options (variable);
 48       dcl     iox_$look_iocb         entry (char (*), ptr, fixed bin (35));
 49       dcl     iox_$move_attach       entry (ptr, ptr, fixed bin (35));
 50       dcl     iox_$detach_iocb       entry (ptr, fixed bin (35));
 51       dcl     iox_$destroy_iocb      entry (ptr, fixed bin (35));
 52       dcl     iox_$close             entry (ptr, fixed bin (35));
 53       dcl     com_err_               entry options (variable);
 54 
 55 /* External */
 56 
 57       dcl     error_table_$badopt    fixed bin (35) ext;
 58 ^L
 59       call cu_$arg_count (nargs);
 60       if nargs > 1
 61       then
 62          do;
 63             call com_err_ (error_table_$badopt, MYNAME, "Too many arguments.^/Usage: detach_audit {switchname}");
 64             return;
 65          end;
 66       else if nargs = 1
 67       then call cu_$arg_ptr (1, tp, tc, code);
 68       else
 69          do;
 70             tc = 8;
 71             alloc targ;
 72             targ = "user_i/o";
 73          end;
 74       call iox_$look_iocb ((targ), old_iocb, code);
 75       if code ^= 0
 76       then
 77          do;
 78             call com_err_ (code, MYNAME, "while looking for ^a", targ);
 79             return;
 80          end;
 81 
 82       if old_iocb -> iocb.close ^= audit_$audit_close
 83       then
 84          do;
 85             call com_err_ (0, MYNAME, "^a not attached via audit_", targ);
 86             return;
 87          end;
 88 
 89       blkptr = old_iocb -> iocb.attach_data_ptr;
 90       new_iocb = blkptr -> blk.auditing_iocb;
 91 
 92       call iox_$close (old_iocb, code);
 93       if code ^= 0
 94       then
 95          do;
 96             call com_err_ (code, MYNAME, "while closing ^a switch", targ);
 97             return;
 98          end;
 99 
100       call iox_$detach_iocb (old_iocb, code);
101       if code ^= 0
102       then
103          do;
104             call ioa_$ioa_switch (new_iocb, "Couldn't detach ^a", targ);
105             return;
106          end;
107 
108 
109       call iox_$move_attach (new_iocb, old_iocb, code);
110       if code ^= 0
111       then
112          do;
113             call com_err_ (code, MYNAME, "while moving attachment from ^a to ^a", new_iocb -> iocb.name, targ);
114             return;
115          end;
116 
117       call iox_$destroy_iocb (new_iocb, code);
118       if code ^= 0
119       then
120          do;
121             call com_err_ (code, MYNAME, "Unable to destroy the auditing iocb.  Auditing was successfully
122 detached for switch ""^a"", however.", targ);
123          end;
124 
125       return;
126 
127 /*  Include  */
128 
129 %include iocb;
130 %include audit_block;
131 
132    end;