From:	CRDGW2::CRDGW2::MRGATE::"SMTP::CRVAX.SRI.COM::RELAY-INFO-VAX"  9-JUN-1991 00:17:39.88
To:	ARISIA::EVERHART
CC:	
Subj:	Re: Mailboxes.

From:	RELAY-INFO-VAX@CRVAX.SRI.COM@SMTP@CRDGW2
To:	Everhart@Arisia@MRGATE

Received:  by crdgw1.ge.com (5.57/GE 1.99)
	 id AA24472; Sun, 9 Jun 91 00:05:34 EDT
Received: From ucbvax.Berkeley.EDU ([128.32.133.1]) by CRVAX.SRI.COM with TCP; Sat,  8 JUN 91 06:16:30 PDT
Received: by ucbvax.Berkeley.EDU (5.63/1.42)
	id AA24662; Sat, 8 Jun 91 06:04:54 -0700
Received: from USENET by ucbvax.Berkeley.EDU with netnews
	for info-vax@kl.sri.com (info-vax@kl.sri.com)
	(contact usenet@ucbvax.Berkeley.EDU if you have questions)
Date: 8 Jun 91 19:02:14 GMT
From: comp.vuw.ac.nz!gp.co.nz!zl2tnm!don@uunet.uu.net  (Don Stokes)
Organization: Computer Archaeologists
Subject: Re: Mailboxes.
Message-Id: <FuL831w163w@zl2tnm.gp.co.nz>
References: <23266@shlump.lkg.dec.com>
Sender: info-vax-request@kl.sri.com
To: info-vax@kl.sri.com

winalski@psw.enet.dec.com (Paul S. Winalski) writes:

> In article <17574.284bd324@ul.ie>, 9025189@ul.ie writes:
> |>				Does anybody know how to handle mailboxes in DCL
> |>(is it possible to create them in dcl?) or a high level language equivilant
> 
> The DCL command interpreter does not have the direct capability to create
> mailboxes.  You could write a little program to do the $CREMBX call, but
> the problem then becomes how to make a temporary mailbox stick around
> after your create program exits--normally, they get deleted after all
> assigned channels are deassigned, which automatically occurs for user-mode
> channels at image rundown.  You could assign a channel in exec mode or
> supervisor mode, but then you've got the problem of how to get the

I've done this; code is below.

> mailbox to go away when you're done with it.  You'd have to write
> a second privileged utility to deassign the channel that the create
> program assigned.  Ideally, what you'd like to do is create the mailbox, do
> a RMS OPEN of it in supervisor mode, opening it as a process-permanent file,
> [...]

You've summed up the problems pretty well.  I put the problem of getting
rid of the mailbox into the "too hard" basket, in favour of damage
limitation.

This creates a mailbox with a supervisor-mode channel, so it is only
deassigned when the process exits.  Given that the mailbox can't be got
rid of without some serious gymnastics, we can reduce the problem to
managable proportions simply by checking if the mailbox already exists
before creating it; easy if we are doing the sensible thing and creating
it with a locical name.

Anyway, assemble the code, call it say "CREMBX", install with CMEXEC
privilege, define a symbol, to point to it, eg:

        $ MACRO CREMBX
        $ LINK CREMBX
        $ COPY CREMBX.EXE SYS$SYSTEM:
        $ INSTALL ADD CREMBX/PRIVILEGE=CMEXEC   ! at boot time too
        $ CREMBX :== $CREMBX                    ! before use, eg in SYLOGIN

then to create and use a mailbox from DCL:

        $ CREMBX MAILBOX
        $ OPEN/WRITE MBX MAILBOX:
        $ etc


-------------------------------cut-here------------------------------
                .title CREMBX   Create a mailbox in supervisor mode

;++
;
;       CREMBX -- Quick-n-dirty to create a mailbox
;
;       Invoke with "$CREMBX logicalname".  Mailbox is created in
;       supervisor mode with logical name assigned (in job table, unless
;       you've fiddled with LNM$TEMPORARY_MAILBOX).
;
;       Don Stokes (don@zl2tnm.gp.co.nz)                26-May-1991
;
;--

		.library "SYS$LIBRARY:LIB"
		$PSLDEF
		$DSCDEF
		$SSDEF

                .psect CREMBX_RW, long,noexe,wrt,noshr

promsk		= ^XFF00		; S:RWLP,O:RWLP,G:,W:
chan:		.blkw
prompt:		.ascid "Mailbox name: "
ask_mbxname:	.word 0			; Dynamic string for mbx name
		.byte DSC$K_DTYPE_T, DSC$K_CLASS_D
		.long 0
mbxname:	.blkq			; Place to put modified descriptor
itmlst:		.long 0			; null itemlist to keep $GETDVI happy
crembx_args:	$CREMBX chan=chan, 	-
			promsk=promsk,	-
			lognam=mbxname,	-
			acmode=PSL$C_SUPER



		.psect CREMBX_RE, long,exe,nowrt,shr

		.entry CREMBX, ^M<>

;
; Get name of mailbox from keyboard or command line
;
		pushaq ask_mbxname
		pushaq prompt
		pushaq ask_mbxname
		calls #3, g^LIB$GET_FOREIGN
		blbc R0, end

;
; Check that device doesn't exists (so we can rely on the reference count)
;
		$GETDVI_S devnam=ask_mbxname, itmlst=itmlst
		cmpl R0, #SS$_NOSUCHDEV
		bneq end

;
; Strip any trailing colons on device name (valid to $GETDVI, but inclined
; to get placed in the logical name)
;
		movq ask_mbxname, mbxname
		cvtwl mbxname, R0
		addl2 mbxname+4, R0
		cmpb -1(R0), #^A":"
		bneq 1$
		decw mbxname
1$:
;
; Call $CREMBX in executive mode to create the mailbox
;
		$CMEXEC_S routin=g^SYS$CREMBX, arglst=crembx_args

;
; Come here on exit
;
end:		ret

		.end CREMBX
-------------------------------cut-here------------------------------

Don Stokes, ZL2TNM  /  /                             don@zl2tnm.gp.co.nz (home)
Systems Programmer /GP/ GP PRINT LIMITED  Wellington,       don@gp.co.nz (work)
__________________/  / ----------------   New_Zealand__________________________

