home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / os / vms / 13657 < prev    next >
Encoding:
Internet Message Format  |  1992-08-14  |  15.9 KB

  1. Path: sparky!uunet!destroyer!gatech!news.byu.edu!yvax.byu.edu!heinrich
  2. From: heinrich@yvax.byu.edu (Ed Heinrich  - The LOKI Group, Inc.)
  3. Newsgroups: comp.os.vms
  4. Subject: re: Getting notified when a process terminates?
  5. Message-ID: <1992Aug14.094502.888@yvax.byu.edu>
  6. Date: 14 Aug 92 09:45:02 -0700
  7. References: <9208110358.AA01660@uu3.psi.com> <1992Aug13.082015.100@ipact.com>
  8. Distribution: world
  9. Organization: Brigham Young University
  10. Lines: 479
  11.  
  12. In article <1992Aug13.082015.100@ipact.com>, lakia@ipact.com writes:
  13. > In article <9208110358.AA01660@uu3.psi.com>, leichter@lrw.com (Jerry Leichter) writes:
  14. >>
  15. >>     Say... does anyone out there know what a "Termination Mailbox" is?  I
  16. >>     have an application whereby I'll want a single process to "monitor" a
  17. >>     group of other processes to measure how long they've been online for
  18. >>rest deleted....
  19. >>
  20. > One could also tell all authors of the programs you are interested
  21. > in monitoring to set up exit handlers.  These exit handlers
  22. > could send a mail message to a permenant mail box that your
  23. > monitor could be looking at.   This however will not work
  24. > if someone does a delete process  (such as the DCL STOP command).
  25. > However, I used a function available for user written system
  26. > services that allow the system service to be called on
  27. > process rundown, regardless if the process was deleted, or
  28. > exited.
  29. > [...]
  30. > Earl Lakia            Email:  LAKIA@IPACT.COM
  31. > IPACT Inc.            Voice:  219-464-7212
  32. > 260 South Campbell        FAX:    219-462-5387
  33. > Valparaiso, IN   46383
  34.  
  35.  
  36. Several years ago I also was faced with the neeed to know when an image
  37. had terminated.  The processes were created as detached processses
  38. by another process, which also needed this information and employed
  39. the termination mailbox method. I had written several privileged-mode
  40. routines and had created them as user-written system services, to make
  41. modifications to those routines transparent to the users and to
  42. avoid granting CMKRNL privileges to every process on the system that
  43. needed access to these routines.  One of the nice side-effects of 
  44. user-written system services is that there is a mechanism provided
  45. that allows for these services to receive notification when an image
  46. is being rundown, specifically so they can clean up after themselves,
  47. i.e., return non-paged pool, etc.  As one of the necessary steps to
  48. creating a user-written system service, you must create a change mode
  49. vector.  The change mode vector contains relative offsets to the
  50. user-defined executive and kernel mode change mode dispatchers and
  51. also allows the user to specify an image rundown routine and an
  52. RMS rundown routine.  When the image activator executes the image, it
  53. notices the change mode vector and loads the address of the rundown
  54. handler into CTL$GL_USRUNDWN.  As part of image rundown, VMS checks this
  55. cell and issues a JSB to the address contained in it, (normally simply
  56. a RSB instruction).  Your user-defined rundown code is then executed,
  57. called via a JSB, NOT A CALLx instruction!  
  58.  
  59. The beauty of doing it this way, unlike some other proposals that 
  60. have been posted, is that other than relinking the images that you
  61. wish to track so they link against the privileged image containing the
  62. change mode vector, NO modifications need be made to the target images.
  63.  
  64.  
  65. In SYS$EXAMPLES is a template that can be used for writing user-written
  66. system services.  (USSDISP.MAR, I think).  You can edit this file, I
  67. think it contains an example of a rundown handler, and have it handle
  68. your requirements.  I have enclosed part of a rundown handler I wrote,
  69. past my signature, along with the shell of the symbiont process that handled 
  70. the mailbox message sent to it from the rundown handler.  I last worked on 
  71. this under V5.2 so I cannot be ABSOLUTELY certain that it works 100% on V5.5
  72. but don't see anything in it that should have broken.  Also, I edited 
  73. it quite a bit to remove superflous (to your question) code so it is not
  74. complete.
  75.  
  76.  
  77.                         - Ed -
  78.  
  79. *+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*
  80. Ed Heinrich
  81. The LOKI Group, Inc.        (801)-576-0730
  82. HEINRICH@yvax.byu.EDU
  83. *+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*
  84.  
  85.  
  86. ;
  87. ;
  88. ;    This vector is used by the image activator to connect the
  89. ;    privileged shareable image to the VMS change mode dispatcher.
  90. ;    The offsets in the vector are self-relative to enable the
  91. ;    construction of position independent images.  The system
  92. ;    version number will be used by the image activator to verify 
  93. ;    that this shareable image was linked with the symbol table for
  94. ;    the current system.
  95. ;
  96.     .Weak    SYS$K_VERSION
  97.  
  98.     .Psect    PRIV_SERVICES    PAGE,VEC,PIC,NOWRT,EXE
  99.  
  100.     .Long    PLV$C_TYP_CMOD        ; Vector type = change mode dispatcher
  101.     .Long    SYS$K_VERSION        ; Identify system version
  102.     .Long    KERNEL_DISPATCH-.    ; Offset to kernel mode dispatcher
  103.     .Long    EXEC_DISPATCH-.        ; Offset to executive mode dispatcher
  104. ***>>>    .Long    PRIV_RUNDOWN-.        ; Offset to user rundown service
  105.     .Long    0            ; Reserved.
  106.     .Long    0            ; No RMS dispatcher
  107.     .Long    0            ; Address check - PIC image
  108.  
  109.  
  110.  
  111.  
  112. ;
  113. ;    This Psect contains local data definitions for CSIPRVRTL
  114. ;
  115. $PRCDEF                    ; Process options
  116.  
  117. RNDDEF                    ; Define RUNDOWN mnemonics
  118.  
  119.     .Page
  120.     .Sbttl    PUREDATA    Non-writeable Data
  121.     .Psect    PUREDATA    NOWRT,NOEXE,PIC,REL,LONG
  122.  
  123. RUNDOWN_MAILBOX:
  124.     .Ascii    /RUNDOWN_MBX/        ; Mailbox to assign to
  125. RUNDOWN_MBXLEN = . - RUNDOWN_MAILBOX    ; Let assembler compute length
  126.  
  127.     .Align    Long
  128. RUNDOWN_DESC:                ; Ascid descriptor for
  129.     .Ascid    /RUNDOWN/        ; Name of rundown image
  130.  
  131.  
  132.     .Page
  133.     .Sbttl    PRIV_RUNDOWN        User Rundown Service
  134. ;+
  135. ;
  136. ; FUNCTIONAL DESCRIPTION:
  137. ;    This routine is invoked from within the kernel mode VMS system
  138. ;    service that performs image rundown.  It is invoked before any
  139. ;    system run down functions are performed.  It preserves all work
  140. ;    registers, as it must, disables system service failure exceptions
  141. ;    so we don't do undesireable things while in here, assigns a
  142. ;    channel to the RUNDOWN mailbox, fires a QIO off to RUNDOWN with
  143. ;    the PID of the current image, and deassigns the channel to the
  144. ;    RUNDOWN mailbox.
  145. ;
  146. ; NOTES:
  147. ;    We check in this routine if RUNDOWN is the process that is executing
  148. ;    the PRIV_RUNDOWN code so that we do not get into any funny states,
  149. ;    i.e., attempting to perform the QIO, which will wait forever for
  150. ;    the special kernel mode AST that cannot be delivered since the
  151. ;    DELPEN bit is set in the process header.
  152. ;    Note that the asynchronous form of $QIO must be used to send messages
  153. ;    to the RUNDOWN mailbox in order to avoid the situation where RUNDOWN
  154. ;    is not running and a process is attempting to queue a mailbox message
  155. ;    to it.  The QIOW form will force the image / process that is being
  156. ;    run down to wait forever since the I/O will never complete.
  157. ;
  158. ; ENTRY FORMAT:
  159. ;    JSB    PRIV_RUNDOWN    - invoked by VMS routine SYS$RUNDWN
  160. ;    Entered in KERNEL mode at IPL 0 and must exit at IPL 0.
  161. ;
  162. ; INPUT PARAMETERS:
  163. ;    R4    Current PCB address.  (Therefore R4 must be preserved).
  164. ;    R7    Access mode parameter to $RUNDWN maximized with previous mode.
  165. ;    AP     Argument pointer existing when the $RUNDWN service was invoked.
  166. ;     4(AP)     Access mode parameter to $RUNDWN
  167. ;
  168. ; SIDE EFFECTS:
  169. ;    A mailbox message is sent to RUNDOWN.
  170. ;    A link ABORT message is sent on any channels assigned to DECnet.
  171. ;
  172. ;-
  173.     .Page
  174.     .Align    Long            ; For a little speed at execution time
  175. PRIV_RUNDOWN::                ; The transfer address
  176.  
  177.     PUSHL    R1            ; Preserve work registers upon entry
  178.     PUSHL    R2            ; So everything else works correctly
  179.     PUSHL    R3            ; When we exit and return control to
  180.     PUSHL    R5            ; SYS$RUNDWN
  181.     PUSHL    R6            ; R6 used for disconnect data
  182.     PUSHL    R7            ; R7 is used for flag field
  183.     PUSHL    R8            ; Save R8 used for length
  184.  
  185.     $SETSFM_S enbflg = #0        ; No system service failure exceptions
  186.  
  187.     MOVZBL    #<RND_M_LOCK>, R7    ; Always set LOCK flag
  188.     MOVAB    RUNDOWN_DESC + 8, R5    ; Address of process name
  189.     MOVAB    G^CTL$GL_IMGHDRBF, R2    ; Image activator's image header buffer
  190.     MOVL    0(R2), R2        ; Get address of image header buffer
  191.     MOVL    4(R2), R2        ; R2 address of image file descriptor
  192.     MOVQ    IFD$Q_CURPROG(R2), R2    ; Get image name descriptor
  193.     MOVZWL    R2, R2            ; Get size as word
  194.     LOCC    #^A/]/, R2, (R3)    ; Find directory delimiter
  195.     BEQL    0$            ; Insure we found one
  196.     ADDL3    #1, R1, R3        ; Save it for later use
  197.     LOCC    #^A/./, R0, (R1)    ; Find '.' for extension
  198.     BEQL    0$            ; Not found - exit from RUNDOWN routine
  199.     SUBL3    R3, R1, R2        ; Compute length of image name
  200.     MOVL    R2, R8            ; Save length              EAH779
  201.     MOVL    R3, R6            ; And address              EAH779
  202.     MOVZWL    RUNDOWN_DESC, R1    ; Get length of process name
  203.     CMPL    R1, R2            ; Does size of image name match?
  204.     BNEQ    200$            ; No then not what we're lookin' for
  205.  
  206.     PUSHL    R2            ; Save registers needed in next check
  207.     PUSHL    R3            ; If this one fails
  208.     CMPC3    R1, (R5), (R3)        ; See if this is the RUNDOWN process
  209.     POPL    R3            ; Before going any futher restore R3
  210.     POPL    R2            ; And R2
  211.     TSTL    R0            ; See if we had a match
  212.     BNEQ    200$            ; If this is not RUNDOWN then continue
  213.     MOVZBL    #SS$_NORMAL, R0        ; Say success to $RUNDWN
  214.     BRW    NO_OPERATION        ; If it is RUNDOWN then exit routine
  215.  
  216.     .Align    Long
  217.     0$:    BRB    600$            ; Branch helper (Like hamburger helper!)
  218. ;
  219. ;    Here we did a bunch of other things, looking for explicit
  220. ;    image names and creating other processes if we found them, etc.
  221. ;    That code has been removed to avoid complicating the example.
  222.  
  223.   200$:
  224. ;    R2    Length of current image name
  225. ;    R3    Address of current image name
  226. ;
  227.     [...]
  228.  
  229.   600$:    PUSHAB    RUNDOWN_MAILBOX        ; Build an ASCID descriptor on stack
  230.     PUSHL    #RUNDOWN_MBXLEN        ; For SYS$ASSIGN system service
  231.     MOVAL    -(SP), R2        ; A longword for channel number
  232.     $ASSIGN_S -            ; Invoke assign channel system service
  233.         chan    =  (R2), -    ; To get a channel for the mailbox to
  234.         devnam    = 4(R2)        ; The symbiont rundown process
  235.  
  236.     BLBS    R0, 800$        ; Continue on success
  237.     BRW    RUNDOWN_EXIT        ; Give up on error
  238.  
  239.     .Align    Long
  240.   800$:    PUSHL    R7            ; Set flag bits for RUNDOWN.EXE
  241.     PUSHL    PCB$L_PID(R4)        ; Copy PID to stack
  242.     MOVAL    (SP), R3        ; R3 is now pointer to PID (Buffer arg)
  243.     $QIO_S    chan    = (R2),       -    ; Channel to write it to
  244.         func    = #IO$_WRITEVBLK, -
  245.         p1    = (R3),       -    ; Buffer address
  246.         p2    = #RND_C_REQUIRED
  247.                     ; No error recovery so don't check 
  248.     ADDL2    #RND_C_REQUIRED, SP    ; Give back work space
  249.  
  250.     $DASSGN_S -            ; Deassign the channel
  251.         chan    = (R2)        ; Used to send to symbiont rundown image
  252. ;
  253. ;    If we still have an open DECnet channel then that means the
  254. ;    process did not terminate the link on purpose.  We want to
  255. ;    let the remote process know that this was a LINKABORT, not
  256. ;    a planned termination.  (Contrary to the documentation, DECnet
  257. ;    does NOT automatically do this!)
  258. ;
  259. ;    Now look for DECnet channels and if found clean up for them
  260. ;    ever so nicely.  Note that the following code can be deleted
  261. ;    someday when DEC does this for us in SYSRUNDWN.
  262. ;
  263. CHECK_CHAN:
  264.     MOVPSL    R7            ; Get PSL to work register
  265.     PUSHL    R5
  266.     EXTZV    #PSL$V_PRVMOD, #PSL$S_PRVMOD, R7, R7
  267.                     ; Extract previous mode
  268.     MOVZWL    @#CTL$GW_CHINDX, R5    ; Get maximum channel index
  269.     BEQL    2100$            ; No channels assigned, leave now
  270.     MNEGL    R5, R5            ; Convert to negative offset
  271. ;
  272. ;    Build descriptor for optional data sent in disconnect message
  273. ;
  274.     SUBL2    R8, SP            ; Subtract size of process name
  275.     DECL    SP            ; Include count field
  276.     MOVL    SP, R1            ; Save address of stack
  277.     MOVL    R1, R2            ; Save it in work register
  278.     MOVB    R8, (R2)+        ; Make it counted string
  279.     MOVL    R8, R0            ; Copy length to use as index
  280.  
  281.   900$:    MOVB    (R6)+, (R2)+        ; Include process name text
  282.     SOBGTR    R0, 900$        ; Do all bytes in it
  283.  
  284.     PUSHL    R1            ; Build descriptor on stack
  285.     PUSHL    R8            ; To send optional data
  286.     INCL    (SP)            ; In ABORT message
  287.     MOVL    SP, R6            ; So remote knows who broke link
  288.     
  289.     ASSUME    CCB$B_STS+1 EQ CCB$B_AMOD 
  290.  1000$:    MOVL    G^CTL$GL_CCBBASE, R2    ; Get CCB base address for this channel
  291.     MOVAB    (R2)[R5], R1        ; Get CCB address for this channel
  292.     MOVL    CCB$L_WIND(R1), R0    ; Do we have a XWB?
  293.     BEQL    2000$            ; No then can't be DECnet
  294.     MOVL    CCB$L_UCB(R1), R0    ; Grab UCB address from CCB
  295.     BBC    #DEV$V_NET, UCB$L_DEVCHAR(R0), 2000$
  296.                     ; Check for DECnet type of device
  297.     MNEGL    R5, -(SP)        ; Get back channel number from offset
  298.     CALLS    #1, G^SYS$CANCEL    ; Cancel any and all outstanding I/O
  299.  
  300.     MNEGL    R5, R0            ; Convert offset back to channel number
  301.     $QIO_S    chan     = R0, -        ; Send the "correct" message!
  302.         func    = #<IO$_DEACCESS!IO$M_ABORT>, -
  303.         p2    = R6        ; Include optional data
  304.  
  305.  2000$:    ADDL2    #CCB$C_LENGTH, R5    ; Point at next channel
  306.     BLSS    1000$            ; Process next channel
  307.     CMPL    (SP)+, (SP)+        ; Throw away descriptor    
  308.     ADDL2    R8, SP            ; Fix up stack
  309.     INCL    SP            ; Including count field
  310.  
  311.  2100$:    POPL    R5
  312. ;
  313. ;        End of code to issue ABORT on DECnet
  314. ;
  315.  
  316. RUNDOWN_EXIT:
  317.     ADDL2    #12, SP            ; Restore stack
  318.  
  319. NO_OPERATION:
  320.     POPL    R8            ; Restore R8
  321.     POPL    R7            ; Get back R7
  322.     POPL    R6            ; Restore R6
  323.     POPL    R5            ; Restore saved R5
  324.     POPL    R3            ; Restore R3
  325.     POPL    R2            ; And R2
  326.     POPL    R1            ; And R1
  327.     RSB                ; Return from user run down
  328.  
  329.  
  330.  
  331. The following is the code, minus all the "real" rundown activity, that
  332. was contained in the rundown symbiont.
  333.  
  334.  
  335.     .Title    RUNDOWN        Image Rundown Handler
  336.     .Ident    /V1.0-000/    ; EAH974
  337.     .Sbttl    DESCRIPTION    Program Description
  338. ;+
  339. ;
  340. ; PROGRAM:
  341. ;    RUNDOWN.MAR
  342. ;
  343. ; AUTHOR:            CREATION DATE: 
  344. ;    Edward A. Heinrich        03-Jul-1985
  345. ;
  346. ; ABSTRACT:
  347. ;    RUNDOWN is the image run down handler.  It receives a mailbox
  348. ;    message from an exiting image and performs clean up on CSI resources
  349. ;    associated with that image.
  350. ;
  351. ; ENVIRONMENT:
  352. ;    User mode code
  353. ;
  354. ; INPUTS:
  355. ;    Mailbox message from exiting image
  356. ;
  357. ;-
  358. RNDDEF                    ; Define RUNDOWN mnemonics
  359.  
  360. $PRCDEF                    ; Process options
  361. $PSLDEF                    ; PSL definitions
  362.  
  363.     .Page
  364.     .Sbttl    PUREDATA    Non-writeable Data
  365.     .Psect    PUREDATA    NOWRT,NOEXE,PIC,REL,LONG
  366.  
  367. RUNDOWN_MBX_PRMFLG:
  368.     .Long    1            ; Put in system table
  369.  
  370. RUNDOWN_MBX_ACMODE:
  371.     .Long    PSL$C_KERNEL!PSL$C_USER    ; Type of mailbox access allowed
  372.  
  373. RUNDOWN_MBX_NAME:
  374.     .Ascid    /RUNDOWN_MBX/        ; Mailbox name in Ascii
  375.  
  376.  
  377.     .Page
  378.     .Sbttl    IMPUREDATA    Writeable Data
  379.     .Psect    IMPUREDATA      WRT,NOEXE,PIC,REL,QUAD
  380.  
  381. IOSB:    .Quad    0            ; General purpose IOSB
  382.  
  383. RUNDOWN_MBX_BUFQUO:
  384.     .Long    8192            ; Buffer quota for RUNDOWN_MBX
  385.  
  386. RUNDOWN_MBX_SIZE:
  387.     .Long    RND_C_MBXSIZE        ; Size of mailbox buffer
  388.  
  389. RUNDOWN_MBX_CHAN:
  390.     .Word    0            ; Word to receive mailbox channel
  391.  
  392. RUNDOWN_MBX_BUFFER:
  393.     .Blkb    RND_C_MBXSIZE        ; Buffer for mailbox I/O
  394.  
  395.  
  396.     .Page
  397.     .Sbttl    RUNDOWN        Main-line Code
  398.     .Psect    RUNDOWN_CODE    NOWRT,  EXE,PIC,REL,LONG
  399.  
  400.     .Entry    RUNDOWN, 0        ; Take your mark, get set, Go!
  401. ;
  402. ;    We begin this little program by creating a mailbox for RUNDOWN
  403. ;
  404.     $CREMBX_S -    
  405.         prmflg    = RUNDOWN_MBX_PRMFLG,    -
  406.         chan    = RUNDOWN_MBX_CHAN,     -
  407.         maxmsg    = RUNDOWN_MBX_SIZE,     -
  408.         bufquo    = RUNDOWN_MBX_BUFQUO,    -
  409.         acmode    = RUNDOWN_MBX_ACMODE,    -
  410.         lognam    = RUNDOWN_MBX_NAME
  411.                     ; Specify all relevant parameters
  412.     BLBS    R0, 200$        ; Continue if successful
  413.     BRW    ERROR_HANDLER        ; Go to error routine otherwise
  414. ;
  415. ;    Queue a read I/O request to the RUNDOWN mailbox.
  416. ;    We specify an AST address so we can simply hibernate once the
  417. ;    QIO returns and wait until we receive a message before doing
  418. ;    any more work.
  419. ;
  420.     .Align    Long
  421. 200$:    $QIO_S    chan    = RUNDOWN_MBX_CHAN,    -
  422.         func    = #IO$_READVBLK,    -
  423.         iosb    = IOSB,            -
  424.         astadr    = RUNDOWN_AST,        -
  425.         p1    = RUNDOWN_MBX_BUFFER,    -
  426.         p2    = #RND_C_MBXSIZE; Queue asynchronous read
  427.  
  428.     BLBC    R0, ERROR_HANDLER    ; Check for errors on QIO
  429.  
  430. 400$:    $HIBER_S            ; Go catch up on your sleep
  431.     BRB    400$            ; In case of superious wakeups
  432.  
  433.     .Align    Long
  434. ERROR_HANDLER:
  435.  
  436.  
  437.     RET                ; Exit program
  438.  
  439.  
  440.     .Page
  441.     .Sbttl    RUNDOWN_AST    AST For Actual Processing
  442. ;+
  443. ;
  444. ; FUNCTIONAL DESCRIPTION:
  445. ;    This routine is executed when a mailbox message is received.
  446. ;    It calls all the routines necessary to perform image run down.
  447. ;
  448. ; INPUTS:
  449. ;    None
  450. ;
  451. ; IMPLICIT INPUTS:
  452. ;    Mailbox message in RUNDOWN_MBX_BUFFER
  453. ;
  454. ; OUTPUTS:
  455. ;    None
  456. ;
  457. ; SIDE EFFECTS:
  458. ;    Image currently executing in process identified by PID in mailbox
  459. ;    message is run down for CSI resources.
  460. ;
  461. ;-
  462.     .Align    Long
  463.     .Entry    RUNDOWN_AST, 0        ; No need to preserve any registers
  464. ;
  465. ;    Get PID of the image to rundown in R6
  466. ;
  467.     MOVL    RUNDOWN_MBX_BUFFER+RND_L_PID, R6
  468. ;
  469. ;    Do whatever processing is necessary here ...
  470. ;
  471.  
  472.  
  473. ;
  474. ;    Issue QIO to the mailbox so we can receive another message and run 
  475. ;    down the next exiting image.
  476. ;
  477. QUE_IO:    $QIO_S    chan    = RUNDOWN_MBX_CHAN,    -
  478.         func    = #IO$_READVBLK,    -
  479.         iosb    = IOSB,            -
  480.         astadr    = RUNDOWN_AST,        -
  481.         p1    = RUNDOWN_MBX_BUFFER,    -
  482.         p2    = #RND_C_MBXSIZE
  483.  
  484.     RET                ; Dismiss AST 
  485.  
  486.  
  487.     .End    RUNDOWN            ; That's all there is
  488.  
  489.