From:	CSBVAX::MRGATE!RELAY-INFO-VAX@CRVAX.SRI.COM@SMTP 16-AUG-1988 22:20
To:	ARISIA::EVERHART
Subj:	Changing another process' name


Received: From KL.SRI.COM by CRVAX.SRI.COM with TCP; Tue, 16 AUG 88 13:23:34 PDT
Received: from CORNELLC.CCS.CORNELL.EDU by KL.SRI.COM with TCP; Tue, 16 Aug 88 13:17:21 PDT
Received: from Bitway.Rose-Hulman.Edu by CORNELLC.CCS.CORNELL.EDU ; Tue, 16 Aug 88 16:18:03 EDT
Received: from VMS.Rose-Hulman.Edu by Bitway.Rose-Hulman.Edu; Tue, 16 Aug 88
 15:14 EST
Date: Tue, 16 Aug 88 15:12 EST
From: "Robert W. Shew" <MGRRWS%VMS.Rose-Hulman.Edu@CORNELLC.CCS.CORNELL.EDU>
Subject: Changing another process' name
To: info-vax@kl.sri.com, fritz@fergvax.unl.edu
X-VMS-To: IN%"info-vax@kl.sri.com",IN%"fritz@fergvax.unl.edu"


For Tim Russel (and any other interested parties) ..

This program works as of VAX/VMS V4.6


***** Here is the .CLD file *****

Define Verb CHG
        Image "MGR:[CUTE]Chg"
        Qualifier  NAME, Value(Required)
        Qualifier  ID, Value


***** Here is the macro source ****



                .Title  Change_Process_Name

;******************************************************************************
;    This program computes the PCB vector index for the specified process,    *
;    verifies the existence of the process, and the uses a                    *
;    Kernel mode routine to change the process name of the specified process. *
;    It also raises the IPL level to avoid rescheduling.                      *
;                                                                             *
;    Basic routines were created by Lynn Crockett with some help by Robert    *
;    Shew, and this program is an incorporation of those basic routines.      *
;                                                                             *
;       AUTHOR: Robert W. Shew          DATE: March 22, 1987                  *
;                                                                             *
;       Note: Must be linked with Sys$System:Sys.Stb                          *
;                                                                             *
;                          Modification History                               *
;                                                                             *
;       RWS : 06-15-87 - Added the SetIPL and also used all global symbols.   *
;                                                                             *
;******************************************************************************



;******************************************************************************
;                           Macro Definitions                                 *
;******************************************************************************



; This macro checks the error status in R0, and acts appropriately.


                .Macro          Error_Check ?No_Error

                Blbs            R0, No_Error
                $Exit_S         R0
No_Error:
                .EndM           Error_Check



;******************************************************************************
;                            Data Definitions                                 *
;******************************************************************************


                .Library  /SYS$SHARE:LIB/

                $PcbDEF
                $PrvDEF
                $JpiDEF
                $IplDEF

Len_Err:        .Ascid  \%CHG-E-LENERR, invalid process name\

Qualifier1:     .Ascid  \ID\
Qualifier2:     .Ascid  \NAME\


JPI_Item_List:  .Word   4
                .Word   Jpi$_Pid
                .Long   PID
                .Long   0
                .Long   0

Privs:          .Quad   Prv$M_Cmkrnl



;*****************************************************************************
;                               Routines                                     *
;*****************************************************************************



        .Entry  Process_Name_Changer, ^M<>


        PushaW          Str_D                   ; Length of line
        PushaQ          Str_D                   ; Descriptor for return
        PushaQ          Qualifier1              ; Descriptor for qualifier1
        CallS           #3, G^Cli$Get_Value
        BlbS            R0, Cont

        CmpL            #CLI$_Absent, R0        ; See if "/ID" is missing.
        Beql            Qual2
        $Exit_S         R0

Cont:   PushAL          PID
        PushAQ          Str_D
        CallS           #2, G^OTS$Cvt_TZ_L
        Error_Check

Qual2:  TstL            PID                     ; Zero will cause an
        Bneq            Not_Zero                ; an access violation

        $GetJPIW_S      ItmLst=JPI_Item_List    ; Get my PID
        Error_Check

Not_Zero:
        MovL            PID, R0                 ; Convert PID to internal
        JsB             G^EXE$Epid_To_Ipid      ; form
        MovL            R0, PID                 ; put the result back in PID

        MovL            #15, Str_D              ; Reset descriptor length
        PushaW          Str_D                   ; Length of line
        PushaQ          Str_D                   ; Descriptor for return
        PushaQ          Qualifier2              ; Descriptor for qualifier2
        CallS           #3, G^Cli$Get_Value
        Error_Check

        CmpW            Str_D, #15
        Bleq            Len_OK
        PushaQ          Len_Err
        CallS           #1, G^Lib$Put_Output
        $Exit_S

Len_OK:
        $SetPRV_S       #1, Privs
        Error_Check

        $CMKRNL_S       Change
        Error_Check

        $Exit_S


        .Entry Change,  ^M<R2,R3, R4,R5>

        SetIPL          IPL_Level               ; Prevent re-scheduling

        MovZWL          PID, R3                 ; Get PCB index from PCB

        CmpL            R3, G^SCH$GL_MaxPix     ; Is index too large?
        BgtrU           1$                      ; Yes, so branch to error

        MovL            @SCH$GL_PcbVec[R3], R4  ; Get the target PCB address

        CmpL            PID, PCB$L_Pid(R4)      ; Verify process existence
        Bneq            1$                      ; Not there

        MovB            Str_D, PCB$T_LName(R4)  ; Length of the name
        MovC3           Str_D,Str_D+8 , -
                        PCB$T_LName+1(R4)       ; Move the name

        SetIPL          #0
        MovL            #SS$_Normal, R0
        Ret

1$:     SetIPL          #0
        MovL            #SS$_NonExPR, R0        ; Non-existent process
        Ret

Str_D:          .Long   4
                .Address .+4
                .BlkB   80

PID:            .Long   0

IPL_Level:      .Long   IPL$_Synch

Assume          .-Change LT 512

        .End            Process_Name_Changer


