Article 157564 of comp.os.vms:
Bill Riddle <w2r@ornl.gov> writes:

>Can anyone tell me how to identify processes under OpenVMS that have 
>been "disconnected".  We are experiencing problems with processes that 
>users are abnormally exiting, but the images that they are running are 
>continuing "forever".  These processes are consuming all of the 
>available cpu and are seriously hindering perforamance.  I have checked 
>the DCL lexical functions f$getjpi and f$getdvi but cannot locate the 
>information I need. Any suggestions would be appreciated.

>Thanks in advance.

>Bill Riddle
>WCS, Inc./LMES
>w2r@ornl.gov

Please find enclosed a program that is intended for dialing back.
The idea is that you dial in on a modem line and logins in as usual.
Then you call this program which dials you back using the same modem
as you dial in on.  This is done by hanging up the phone and then waiting
until the phone becomes disconnected.  Then the program dials back using
a sharable image as described in SET HOST/DTE.  You will find code that
detects that the terminal has been disconneted and code that reconnects
the terminal.  This program is an old one, and I have not tested it that
much.

Karsten Nyblad
karsten@tdr.dk
Tele Danmark R&D

DIALBACK.CLD:
define type modems
   keyword df03
   keyword df112
   keyword dcml
   keyword hayes

define verb dialback
   image karsten$dir:dialback.exe
   parameter p1,        label=number,value(required),prompt="Number"
   qualifier modem      value(type=modems,required)
   qualifier hangup     default
   qualifier wait_time  value(type=$number,default=0)

DIALBACK_MESSAGES.MSG:
.TITLE Terminal dial back messages

.FACILITY DIALBACK,100

.SEVERITY FATAL

NOTINTER        "Process is not interactive"
NOTMASTER       "Process is a sub-process"
DEVNOTTERM      "Process main input is not a terminal"
MODEM           "Terminal must have /MODEM and /HANGUP characteristics"
DEVNETDEV       "Terminal may not be a network device"
DEVNOTVT        "The device type of the terminal must be VT"
MODEM_NO        "Terminal must have Hangup and Moden chracteristics"
WRONG_WAIT      "Could not convert waiting period into integer"

.SEVERITY INFORMATIONAL

WILLDIAL        "Will dial !AS, please hang up"/fao=1
.END


DIALBACK.MAR:
        .title          Dial up program.  Dial back to call on hang up
        .ident          \V1.00\
        .disable        global
        .extrn          dialback_notinter
        .extrn          dialback_notmaster
        .extrn          dialback_devnotterm
        .extrn          dialback_modem
        .extrn          dialback_devnetdev
        .extrn          dialback_devnotvt
        .extrn          dialback_willdial
        .extrn          dialback_modem_no
        .extrn          dialback_wrong_wait
        .extrn          sys$qiow
        .extrn          cli$get_value
        .extrn          cli$present
        .extrn          lib$find_image_symbol
        .extrn          ots$cvt_tu_l
        
max_modem_length = 256
max_number_length = 256
max_wait_time_length = 256

        .macro          check_error,source=r0,?l
        blbs            source,l
        .iif different,source,r0,     movzwl    source,r0
        ret
l:
        .endm
        
        .macro          error,error_no
        movl            error_no,r0
        ret
        .endm
        
        $pcbdef
        $iodef
        $devdef
        $jpidef
        $dvidef
        $qiowdef
        $ttdef
        $tt2def
        $ssdef
        $stsdef
        $climsgdef

        .psect          code,nowrt,exe,shr,rd,long

dvi_itemlist:
        .word           64
        .word           dvi$_tt_phydevnam
        .address        physical_name
        .long           physical_name_length
        .word           4
        .word           dvi$_devchar
        .address        devchar
        .address        dummy
        .long           0

dev2_itemlist:
        .word           4
        .word           dvi$_devchar2
        .address        devchar2
        .address        dummy
        .long           0
        
jpi_itemlist:
        .word           4
        .word           jpi$_pid
        .address        pid
        .address        dummy
        .word           4
        .word           jpi$_master_pid
        .address        master_pid
        .address        dummy
        .word           7
        .word           jpi$_terminal
        .address        virtual_name
        .address        virtual_name_length
        .word           4
        .word           jpi$_sts
        .long           pcb_flags
        .address        dummy
        .long           0

introduction_msgvec:
        .word           3       ; Length
        .word           ^XF     ; Output all fields
        .long           dialback_willdial
        .word           1       ; 1 fao argument
        .word           ^XF     ; Output all fields
        .address        number_descr
        
image_symbol_msgvec_init:
        .word           4       ; Length
        .word           ^XF     ; Output all fields
        .long           dialback_modem_no
        .word           1       ; 1 fao argument
        .word           ^XF     ; Output all fields
        .address        modem_descr
image_symbol_msgvec_length=4+.-image_symbol_msgvec_init        
        
period: .ascid          \0000 00:00:01.00\

number_text_descr:
        .ascid          \NUMBER\

wait_time_text_descr:
        .ascid          \WAIT_TIME\

hangup_text_descr:
        .ascid          \HANGUP\

modem_text_descr:
        .ascid          \MODEM\

dial_routine_text:
        .ascid          \DIAL_ROUTINE\

success_text:
        .ascii          \Process was dialbacked\
success_text_length = . - success_text


        .entry          dialback_terminal,^m<IV,R2,R3,R4,R5>
        $getjpiw_s      itmlst=jpi_itemlist
        check_error

        bbs             #pcb$v_inter,pcb_flags,2$
        error           #dialback_notinter

2$:     cmpl            master_pid,pid
        beql            3$
        error           #dialback_notmaster

3$:     $getdviw_s      devnam=virtual_name_descr,itmlst=dvi_itemlist
        check_error
        bbs             #dev$v_trm,devchar,5$
        error           #dialback_devnotterm

5$:     bbc             #dev$v_net,devchar,6$
        error           #dialback_devnetdev

6$:     cmpw            virtual_name,#^a\VT\
        beql            7$
        error           #dialback_devnotvt
        
7$:     $assign_s       devnam=virtual_name_descr,chan=virt_chan
        check_error
        pushaw          number_descr
        pushaq          number_descr
        pushaq          number_text_descr
        calls           #3,g^cli$get_value
        check_error
        pushaw          wait_time_descr
        pushaq          wait_time_descr
        pushaq          wait_time_text_descr
        calls           #3,g^cli$get_value
        check_error
        clrl            -(sp)
        pushl           #4
        pushal          bin_wait_time
        pushaq          wait_time_descr
        calls           #4,g^ots$cvt_tu_l
        check_error
        tstl            bin_wait_time
        bgeq            104$
        error           #dialback_wrong_wait
104$:   pushaq          hangup_text_descr
        calls           #1,g^cli$present
        movl            r0,hangup
        cmpl            r0,#cli$_negated
        beql            100$
        cmpl            r0,#cli$_locneg
        beql            100$
        cmpl            r0,#cli$_absent
        beql            100$
        check_error
100$:   pushaw          modem_descr
        pushaq          modem_descr
        pushaq          modem_text_descr
        calls           #3,g^cli$get_value
        check_error                   
        subl2           #4,modem_descr+4
        addw2           #4,modem_descr
        movl            #^A/DTE_/,dte_text
        clrl            -(sp)
        pushal          dial_routine
        pushaq          dial_routine_text
        pushaq          modem_descr
        calls           #4,g^lib$find_image_symbol
        blbs            r0,10$
        movl            r0,image_symbol_msgvec+image_symbol_msgvec_length-4
        movc3           #image_symbol_msgvec_length-4,image_symbol_msgvec_init,image_symbol_msgvec
        $putmsg_s       msgvec=introduction_msgvec
        check_error
        bisl3           sts$m_inhib_msg,image_symbol_msgvec+image_symbol_msgvec_length-4,r0
        ret
10$:    $qiow_s         chan=virt_chan, -
                        func=#io$_sensechar, -
                        iosb=sense_iosb1, -
                        p1=tt_char1, -
                        p2=#12
        check_error
        check_error     source=sense_iosb1
        $qiow_s         chan=virt_chan, -
                        func=#io$_sensemode, -
                        iosb=sense_iosb2, -
                        p1=tt_char2, -
                        p2=#12
        check_error
        check_error     source=sense_iosb2
        bbc             #tt2$v_hangup,tt_char2+8,15$
        bbs             #tt$v_modem,tt_char2+4,16$
15$:    error           #dialback_modem

16$:    $putmsg_s       msgvec=introduction_msgvec
        check_error
        $dclexh_s       desblk=desblk1
        check_error
        movaq           sense_iosb2,r1
        movl            #io$_setchar,r2
        movab           tt_char2,r3
        bsbw            set_char
        blbc            hangup,101$
        $qiow_s         chan=virt_chan, -
                        func=#<io$_setmode!io$m_hangup>, -
                        iosb=iosb
        check_error
        check_error     source=iosb
101$:   $bintim_s       period,bintime
        check_error
        $dclexh_s       desblk=desblk2
        check_error
        $schdwk_s       daytim=bintime,reptim=bintime
        check_error
21$:    $hiber_s
        check_error
        $getdvi_s       chan=virt_chan,itmlst=dev2_itemlist
        check_error
        bbc             #dev$v_det,devchar2,21$
        tstl            bin_wait_time
        beql            102$
103$:   $hiber_s
        subl2           #1,bin_wait_time
        bneq            103$
102$:   $canwak_s
        check_error
        $canexh_s       desblk=desblk1
        check_error
        $assign_s       devnam=physical_name_descr,chan=phy_chan
        check_error
        $qiow_s         chan=phy_chan, -
                        func=#<io$_readvblk!io$m_timed>, -
                        p1=dummy, -
                        p2=#1, -
                        p3=#1
        check_error
        cmpw            iosb,#ss$_hangup
        beql            22$
        cmpw            iosb,#ss$_timeout
        beql            22$
        check_error     source=iosb
22$:    $qiow_s         chan=phy_chan, -
                        func=#<io$_setmode!io$m_tt_connect>, -
                        iosb=iosb, -
                        p1=virtual_name_descr
        check_error
        check_error     source=iosb
        $dassgn_s       chan=phy_chan   ;  Deassign physical channel as soon as possible
        check_error                     ;  Physical and virtual channel are not dialbacked
                                        ;  before this

        movaq           sense_iosb1,r1
        movl            #io$_setchar,r2
        movab           tt_char1,r3
        bsbw            set_char
        $canexh_s       desblk=desblk2
        check_error
        movaq           sense_iosb2,r1
        movl            #io$_setmode,r2
        movab           tt_char2,r3
        bsbw            set_char
        check_error
        movzwl          virt_chan,-(sp)
        movzwl          virt_chan,-(sp)
        pushaq          number_descr
        calls           #3,@dial_routine
        $qiow_s         chan=virt_chan, -
                        func=#io$_writevblk, -
                        iosb=iosb, -
                        p1=success_text, -
                        p2=#success_text_length
        check_error
        check_error     source=iosb
        $dassgn_s       chan=virt_chan
        ret
       

set_char:
        pushl           #0
        movzbl          6(r1),r0
        bicb2           #^c<tt$m_parity!tt$m_odd>,r0
        bisw2           #<tt$m_altrpar!tt$m_altdispar>,r0
        bbc             #1,6(r1),101$
        bisw2           #tt$m_disparerr,r0
101$:   movzwl          r0,-(sp)
        movzwl          4(r1),-(sp)
        movzwl          2(r1),-(sp)
        pushl           #12
        pushal          (r3)
        clrq            -(sp)
        pushaq          iosb
        movl            r2,-(sp)
        movzwl          virt_chan,-(sp)
        pushl           #0
        calls           #qiow$_nargs,sys$qiow
        check_error
        check_error     source=iosb
        rsb


exit_handler1:
        .word           ^m<iv,r2,r3>
        movaq           sense_iosb1,r1
        movl            #io$_setchar,r2
        movab           tt_char1,r3
        bsbw            set_char
        ret
        
        
exit_handler2:
        .word           ^m<iv>
        $canwak_s
        ret
        .psect          data,wrt,noshr,long
bintime:
        .blkq           1

virt_chan:
        .blkw           1
phy_chan:
        .blkw           1
        .align          2

master_pid:
        .blkl           1
pid:
        .blkl           1

physical_name:
        .blkb           64

physical_name_descr:
physical_name_length:
        .blkl           1
        .address        physical_name

virtual_name:
        .blkb           7
        .align          2

virtual_name_descr:
virtual_name_length:
        .blkl           1
        .address        virtual_name

number: .blkb           max_number_length
number_descr:
        .long           max_number_length
        .address        number

wait_time:
        .blkb           max_wait_time_length
wait_time_descr:
        .long           max_wait_time_length
        .address        wait_time

bin_wait_time:
        .long           0

dte_text:
        .blkb           4
modem:  .blkb           max_modem_length
modem_descr:
        .long           max_modem_length
        .address        modem

devchar:
        .blkl           1
        
devchar2:
        .blkl           1

pcb_flags:
        .blkl           1

dummy:  .blkl           1

iosb:   .blkq           1

sense_iosb1:
        .blkq           1

sense_iosb2:
        .blkq           1

tt_char1:
        .blkl           3

hangup: .blkl           1

tt_char2:
        .blkl           3

desblk1:
        .blkl           1
        .address        exit_handler1
        .long           1
        .address        cond_value

desblk2:
        .blkl           1
        .address        exit_handler2
        .long           1
        .address        cond_value

cond_value:
        .blkl           1

dial_routine:
        .long

image_symbol_msgvec:
        .blkb           image_symbol_msgvec_length
        .end            dialback_terminal


