	.Title log_port
	.ident	/V01.00/
;+
;
; ----	LOG_PORT:	Process' terminal server and port logging 
;
;
; Facility:
;
;	VAX/VMS system management
;
; Environment:
;
;	VAX/VMS V5.2 or later, kernel mode
;
;	This routine will extract the current process' terminal server
;	name and port id, if it is a lat process.   This information will
;	then be stored in the remote node name and remote node id fields of 
;	the process' P1 space.  These fields are normally only used by
;	RTTDRIVER and REMACP for remote process'.  These fields are
;	however written by the system accounting facility and will provide
;	a convenient means for storing and tracking this information.
;
; Version:     	V01.000
; Date:		07-FEB-1990
;                         
; Kevin	F. Homan
; Science Applications, Inc.	
; 800 Oak Ridge Turnpike
; Oak Ridge, TN  37830
; (615) 482-9031
;
;
; Modifications:
;
;                                                     
;-                                                    
 	.page  
        .library "SYS$LIBRARY:LIB"                      ;Get special macros from here
        .link    "sys$system:sys.stb"/selective_Search  ;Ease the link process a bit
	.Psect	DATA	noexe,rd,wrt,nopic,noshr,page
dvi_list:	.word	30
		.word	DVI$_TT_ACCPORNAM
		.address port_buffer
		.address port_descr
		.long	0
ttname_desc:	.ascid /TT/
ttchan:	.blkw	1
arglst:		.LONG	2
		.address port_descr
		.address port_buffer
port_descr:	.long 64
		.address	port_buffer
port_buffer:	.blkb	64

	.Psect		CODE	EXE,RD,NOWRT,NOPIC,SHR,PAGE
	.Entry	Start,^m<>

	$Assign_s -
		Devnam	= ttname_desc, -
		Chan	= ttchan	; assign tt
 	Blbc	r0,10$			; can't, die
	$Getdvi_s Chan	= ttchan,-	; Get the real
		Itmlst	= Dvi_list	; device name
 	blbs	r0,20$			; did all of it work?
10$:	ret				; by
20$:	cmpb	#0,port_buffer		; check port
	beql	50$			; null?
	$cmkrnl_s -			; no, continue
		arglst = arglst,-	; arglst
		routin = move_info	; get info in kernel mode
	blbs	r0,40$                  ; err?
	Ret
40$:	$dassgn_s chan=ttchan		; free chan
50$:	$exit_s
 	.page  
	.entry	move_info,^m<r2,r3,r4,r5>
	nop
	movl	4(ap),r3		; get port length
	movl	(r3),r2			; length of server/port name
	movl	8(ap),r3		; address of server name
	locc  	#^A"/",r2,(r3)		; locate position of server
	subl	r0,r2			; calculate actual server length
 	pushr	#^m<r0,r2,r3>		; save server length
	cmpb   	#6,r2			; have room for 6 characters
	bgeq	5$			; is there room
	movb	#6,r2 	       	       	; no, just give first 6
5$:	movb	r2,ctl$t_nodename      	; store length of server
	movc5  	r2,(r3),#^A/ /,#6,ctl$t_nodename+1; store the server name
                                        ; in remote node field
 	popr	#^m<r0,r2,r3>		; restore port length
	addl	r2,r3			; offset to the portname
	decl	r0			; exclude delimiter
	incl	r3			; ditto
	cmpb   	#16,r0			; have room for 16 characters
	bgeq   	10$			; is there room
	movb	#16,r0			; no, just give first 16
10$:	movb   	r0,ctl$t_remoteid	; store length of port name
	movc5  	r0,(r3),#^A/ /,#16,ctl$t_remoteid+1; store port name
                                        ; in remote id field
	movl	#ss$_normal,r0
	ret
	.end	start

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

$! INSTALL_LOG_PORT.COM 
$! Procedure to install LOG_PORT program with CMKRNL
$!
$   install :== $sys$system:install/command
$   install create/open/head/share SYS$SYSTEM:LOG_PORT.EXE/priv=(CMKRNL)
$   exit

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

$! RUN_LOG_PORT.COM 
$ If F$MODE() .eqs. "INTERACTIVE" then run sys$system:log_port
$ exit
