From:	CRDGW2::CRDGW2::MRGATE::"SMTP::CRVAX.SRI.COM::RELAY-INFO-VAX" 17-MAY-1991 14:14:52.74
To:	ARISIA::EVERHART
CC:	
Subj:	Program to find environment

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

Received:  by crdgw1.ge.com (5.57/GE 1.97)
	 id AA29492; Fri, 17 May 91 14:04:11 EDT
Received: From PUCC.PRINCETON.EDU by CRVAX.SRI.COM with TCP; Fri, 17 MAY 91 08:43:23 PDT
Received: from IRLEARN.UCD.IE by pucc.PRINCETON.EDU (IBM VM SMTP R1.2.2MX) with BSMTP id 8682; Fri, 17 May 91 08:39:28 EDT
Received: from mailgate.ucd.ie by IRLEARN.UCD.IE (Mailer R2.07) with BSMTP id
 4013; Fri, 17 May 91 13:36:25 GMT
Received: from enterprise.eurokom.ie by mailgate.ucd.ie; Fri, 17 May 91 12:26
 GMT
Received: from kirk.eurokom.ie by enterprise.eurokom.ie with PMDF#10597; Fri,
 17 May 1991 13:36 WET
Date: Fri, 17 May 1991 13:35 WET
From: "Tom Wade, VMS Systems" <T.Wade%cc.ucd.ie@pucc.PRINCETON.EDU>
Subject: Program to find environment
Sender: Tom Wade VMS Systems <T_WADE%kirk.eurokom.ie@pucc.PRINCETON.EDU>
To: INFO-VAX@KL.SRI.com, CHRIS_F_CHIESA@CUP.PORTAL.com, CARL@SOL1.CALTECH.edu
Message-Id: <D47FF0EB40000063@kirk.eurokom.ie>
X-Envelope-To: CHRIS_F_CHIESA@CUP.PORTAL.com, INFO-VAX@KL.SRI.com,
 CARL@SOL1.CALTECH.edu
X-Vms-To: info-vax@kl.sri.com
X-Vms-Cc: chris_f_chiesa@cup.portal.com,carl@sol1.caltech.edu

Greetings all,

OK.  I made a boo-boo.  I admit it.  Thanks to Jerry Leichter for pointing
out my mistake.

Well, seeing as I made the mistake, I felt honor bound to do some digging into
the problem.  I enclose a program which can tell the difference between whether
it is invoked via

        $ SPAWN RUN SNERD

or
        $ SPAWN
        $ RUN SNERD.

The routine is called WILL_I_DIE and can be called from any high level
language, returning TRUE or FALSE (WILL_I_DIE refers to what happens to
the process when the image exits).

It examines the PRC_W_FLAGS field within the CLI database (CTL$AG_CLIDATA)
and checks for the flag PRC_M_AUTOLOGO.  No privilege is required.

Note:   I have tested this on my workstation, and it returns TRUE if I SPAWN
        the program directly, and FALSE if I SPAWN then RUN (or RUN at the
        top level).  IT WORKS FOR ME, IT'S UP TO YOU TO TEST IT ON YOUR
        SYSTEM.  NO LIABILITY IS ACCEPTED.  Incidentally, it assumes a CLI
        is present, so you'll have to check for RUN/OUTPUT or RUN/DETACH
        before calling it, or do some modifications.

I am still waiting for my ordered copy of the internals.  I am basing the
above on the seeming validity of the symbol names, and the fact it did work
on my VAX, however, bear in mind my only sources for the above is the
System Dump Analyzer, and dumping the symbols in SYS$SYSTEM:DCLDEF.STB.
Perhaps somebody with an internals book could verify that this is the correct
interpretation for these fields ?

Incidentally, I am rather disappointed with the message I received from
Carl Lydick <carl@sol1.gps.caltech.edu>, copied to the list:

>WHY THE HELL DIDN'T YOU TAKE THE TROUBLE TO MAKE SURE YOU KNEW WHAT YOU WERE
>TALKING ABOUT BEFORE POSTING?  Do you really think it's fair to inflict your
>own misconceptions on people who just might be naive enough to believe you just
>because you're too damned lazy to check your facts before posting?

I would just like to point out to you that:

1.      Nobody pays me or anyone else to answer questions on this list; it
        depends on good will.
2.      Since you took the time to flame, could you not have taken the time
        to provide the correct answer ?  A proverb about lighting a candle as
        opposed to cursing the darkness springs to mind.
3.      Flaming novices who ask simple questions discourages people from asking
        questions; flaming people who answer questions when they make a
        mistake discourages people from answering.  Neither improves the
        function of this list.

------------------------------------------------------------------------------
Tom Wade            |  Internet:    T.Wade@vms.eurokom.ie  (all domain mailers).
Speaker To VAXes    |  Bitnet:      T_WADE@CCVAX
EuroKom             |  PSI-Mail:    PSI%272431001992::T.WADE
University College  |  DEC EASYnet: DECWRL::"t.wade@vms.eurokom.ie"   (VMS Mail)
Belfield            |  JANET:       t.wade%ie.eurokom.vms@UK.AC.EARN-RELAY
Dublin 4            |  X400:        [Address Exceeds 65536 byte buffer]
Ireland             |  Telex:       (0500) 91178 UCD EI  ("TO: WADE" at start)
--------------------+----------------------------------------------------------
Voice:+353-1-2697890|  Official Disclaimer:  "This is not a disclaimer"
Fax:  +353-1-2838605|          Unix  ....  Just say No !
-------------------------------------------------------------------------------
Here's the program.  Extract into WILL-I-DIE.MAR, $MACRO WILL-DIE, and
link it with your own program

;   Procedure to return true if it will die when the image exits, false
;   otherwise.

                .Library        "SYS$SHARE:LIB.MLB"
                .Link           "SYS$SYSTEM:SYS.STB"
                .Link           "SYS$SYSTEM:DCLDEF.STB"

Flags:          .Word   0                       ; PRC flags.


                .Entry  WILL_I_DIE      ^M <R6>

                Moval   G^Ctl$AG_Clidata,       R6      ; get CLI database.
                Movl    Ppd$L_prc(R6),  R6              ; find PRC area.
                Movw    Prc_W_Flags(R6),        flags   ; get the flag word.
                Bbs     #Prc_V_Autologo, flags,-        ; check for die bit.
                        yes
                Clrl    R0                              ; return false.
                Ret

Yes:            Movl    #1,     R0                      ; return true.
                Ret

                .End



