From:	CRDGW2::CRDGW2::MRGATE::"SMTP::CRVAX.SRI.COM::RELAY-INFO-VAX" 11-OCT-1989 16:40
To:	MRGATE::"ARISIA::EVERHART"
Subj:	RE: DECwindows DECW$DISPLAY

Received: From MIS.ARIZONA.EDU by CRVAX.SRI.COM with TCP; Wed, 11 OCT 89 13:09:10 PDT
Received: by mis.arizona.edu id <20202685041@mis.arizona.edu> ;
       Wed, 11 Oct 89 13:08:34 MST
Date: Wed, 11 Oct 89 13:07:52 MST
From: "I spent 4 years prostrate to the higher mind..." <JMS@mis.arizona.edu>
Subject: RE: DECwindows DECW$DISPLAY
To: info-vax@crvax.sri.com
X-Vms-Mail-To: EXOS%"info-vax@crvax.sri.com"
Message-Id: <891011130752.20202685041@mis.arizona.edu>

On or about 4 October, I sent the following message:

>How do you track back the WS device for a particular DECwindows
>connection?  Or, in more specific terms, how does the logical
>name DECW$DISPLAY get created in your job logical name table when
>you start a terminal session via the Session Manager "Create Terminal"
>menu item?

> (much text about how hard this would be to do)

With a masterfully short hint from Kevin Mitchell @ dlogics (basically: "look
at sys$error," for which I hereby award him the "guru of the month
award"), and a little delving into the listings, I present you
with this nifty comment out of LOGIN.B32 (V5.1):

%SBTTL 'check_for_decwindows - check to see if we need to define DECW$DISPLAY'
ROUTINE check_for_decwindows : NOVALUE = 
!++
! FUNCTIONAL DESCRIPTION:
! 
!   This routine checks for the need to do DECwindows specific processing in
!   the login path.  There are two types of DECwindows logins which need
!   special attention.  The first in the login on a DECwindows workstation to
!   start the session manager.  This type of login is detected by SYS$INPUT
!   being a workstation device and an interactive login.  The second type of
!   login is processes created by the session manager.  These processes need to
!   know the node and screen to display their output on.  In addition, images
!   which are run in the process may want to know if the DECwindows environment
!   is present.  This type of login is detected by SYS$INPUT not pointing to a
!   workstation device and SYS$ERROR is a workstation device.  If this type of
!   login is occurring, then a job wide logical name is created for this
!   process which points to the workstation device.  In addition, SYS$ERROR is
!   reset to the value of SYS$OUTPUT.
! 
! (much text deleted)
!
! SIDE EFFECTS:
! 
!   SYS$ERROR may be changed to the value of SYS$OUTPUT.
!   A fatal error will be signaled if DECwindows routines can't be loaded.
!   JOB_TYPE is set to LOCAL for DECwindows processes which are interactive.
!--

Yes, there's a magic code path through LOGINOUT where, if SYS$INPUT
and SYS$ERROR are different in an important way (i.e., one points to
a TW device and the other to a WS device), then the value of SYS$ERROR
gets magically transported into DECW$DISPLAY, SYS$ERROR gets patched
up, and life is better for all mankind.

So, if you were using CREATE_DECTERM.C from this list recently, you
may want to change it a trifle:

/*
 * create_decterm.c
 * sort of from VMS V5.1-1 release notes
 *
 * compile with: cc/noopt create_decterm
 * link with: link create_decterm, sys$input/opt
 *            sys$library:decw$dwtlibshr/share
 *            sys$share:vaxcrtl/share
 *            sys$share:decw$terminalshr/share
 * Usage is: mcr sys$login:create_decterm node::screen
 */

#include descrip     /* descriptor definitions */
#include ssdef       /* system status codes */
#include prcdef      /* stsflg bits for creating process */
#include time

main( argc, argv )
  int argc;
  char **argv;
{
  int status, stsflg, baspri = 15;
  char device_name[50], process_name[15], decwdisplay[50];
  char *trnlnm();
  struct dsc$descriptor_s display = { 0, DSC$K_DTYPE_T, DSC$K_CLASS_S, 0 };
  $DESCRIPTOR( command, "SYS$SYSTEM:LOGINOUT.EXE" );
  $DESCRIPTOR( device, device_name );
  $DESCRIPTOR( prcnam, process_name );
  $DESCRIPTOR( error,  decwdisplay );

  /* first parameter is the display name */
  display.dsc$a_pointer = argv[1];
  display.dsc$w_length = strlen( argv[1] );

  /* get the translation of DECW$DISPLAY */
  strcpy ( decwdisplay, trnlnm("DECW$DISPLAY") );
  error.dsc$w_length = (short)strlen(decwdisplay);

  /* make a (semi)unique process name */
  /* NOTE: this change is just for cosmetics; it is not necessary! */
  strcpy( process_name, "DECterm" );
  strcat( process_name, decwdisplay );
  prcnam.dsc$w_length = (short)strlen(process_name);

  /* send the message to the controller */
  status = DECw$Term_Port( &display, 0, 0, &device, &device.dsc$w_length );
  if ( status != SS$_NORMAL )
    printf( "DECterm creation failed, status is %d\n", status );
  else
    {  /* create a process that is already logged in */
    /* make it detached, interactive, logged in */
    stsflg = PRC$M_DETACH | PRC$M_INTER | PRC$M_NOPASSWORD;

    /* create the process */
    status = sys$creprc( 0, &command, &device, &device, 
		&error, 0, 0, &prcnam, baspri, 0, 0, stsflg );
    if ( status != SS$_NORMAL )
    printf( "Could not run LOGINOUT.EXE, status is %d\n", status );
    }
}

#define	LNM$_STRING 2

char *trnlnm(logical_name)
char *logical_name;
{
$DESCRIPTOR(proc_table,"LNM$PROCESS_TABLE");
struct dsc$descriptor_s name;
char *cp;
int loglen,status;
struct itmlst   {
    unsigned short int bufferlength;
    unsigned short int item_code;
    char *pointer;
    int  *retlength;
};                      
struct itmlst trnlist[2];               


	name.dsc$w_length = (short)strlen(logical_name);
	name.dsc$a_pointer = logical_name;
	cp = malloc( 256 );			/* go get us some memory */
	trnlist[0].bufferlength	= 100;		/* set up an itemlist... */
	trnlist[0].item_code	= LNM$_STRING;	/* say it is a string... */
	trnlist[0].pointer	= cp;		/* buffer for the result */
	trnlist[0].retlength	= &loglen;	/* the length for result */
	trnlist[1].bufferlength	= 0;
	trnlist[1].item_code	= 0;
	status = sys$trnlnm(0,&proc_table,&name,0,&trnlist);
	if ( status == SS$_NOLOGNAM || ( status & 1 ) == 0) loglen = 0;
	*(cp + (loglen&255)) = 0;		/* null terminate result */
	return(cp);				/* and return the result */
}


An end note: if you are concerned about the REMOTE vs. LOCAL bit,
note that it is set incorrectly here.  May be a security (???) problem
for some sites.

jms

Joel M Snyder, The Mosaic Group, 627 E Speedway, 85705  Phone: 602.626.8680
(University of Arizona, Dep't of MIS, Eller Graduate School of Management)
BITNET: jms@arizmis  Internet: jms@mis.arizona.edu  SPAN: 47541::uamis::jms   
"Don't get it right, just get it written."  - James Grover Thurber



