Article 167512 of comp.os.vms:
In article <97030911564043@omnia4.omnia.de>,
	arvidsson@omnia4.omnia.de writes:

[emailed, posted]

>	I am porting a program from UNIX to OpenVMS and run across a problem
>	with socket's.  
>
>	On the OpenVMS a real fork does not exist and I wonder if anyone
>	knows of a way to pass the socket i.e the file descriptor to another
>	process on OpenVMS or if someone have written a fork for OpenVMS.
>	To use the Auxilary server on OpenVMS will not function for this
>	application.

Here is one solution, and that is to create a new process with
sys$creprc() that is a net process and pass the device name "BGxxx:"
so the new process can access it by translating SYS$NET:. The
following code is called after the listening server has validated a
user name and password (sys$hash_password etc).

//
// Create a detached process to handle a new connection.
// Parameters are:
//  devnam: The VMS device associated with this connection (BGxxx:)
//  mbx:    The unit number of our termination mailbox
//  ppid:   returned pid of the new process
//  user:   Login name
// 

static int detached (char *devnam, ulong mbx, ulong * ppid, char *user, 
	char *fnam)
{
    descriptor_t out,err,cmd;  // dsc$descriptor_s typedef
    const static $DESCRIPTOR(image,"sys$system:loginout.exe");
    int pid, sts;
    char *ip,iblock[PATH_MAX];
    unsigned long uic;

    uic = getuid() | (getgid() << 16);
    
    MakeDesc(&cmd, fnam, 0);   // make a descriptor from C string
    MakeDesc(&err, devnam, 0);
 
    ///////////////////////////////////////////////////    
    // +++ Warning: Here be deep(ish) magic {:=) +++ //
    ///////////////////////////////////////////////////
    // To do a net login
    // inp = command file to run (after LOGIN.COM)
    // out = descriptor to block of
    //       short LGI$M_NET_PROXY
    //       ASCIC username
    //       ASCIC default user name
    //       ASCIC default password
    //       ASCIC default account
    // err = translation for SYS$NET
    ///////////////////////////////////////////////////
    
    *(short *)iblock = LGI$M_NET_PROXY;
    ip = iblock+sizeof(short);
    *ip++ = strlen(user);
    ip = stpcpy(ip, user);	// roll your own
    *ip++ = 6;
    ip = stpcpy(ip,"DECNET");
    *(short *)ip = 0;
    ip += 2;

    out.dsc$w_length = (ip - iblock);
    out.dsc$a_pointer = iblock;
    out.dsc$b_class = DSC$K_CLASS_S;
    out.dsc$b_class = DSC$K_DTYPE_T;
    
    sts = sys$creprc (ppid, &image, &cmd, &out, &err, NULL, NULL,
	              NULL, 4, uic,  mbx, PRC$M_NETWRK);
    return sts;
}

This is currently tested on AXP VMS 6.2 /UCX and VAX/VMS 6.2 with
TCPware. The created process can use QIO after opening SYS$NET or, (I
anticipate), with VMS 7.x, socket_fd() to use socket library calls
after a sys$assign to obtain a VMS channel for SYS$NET.

-- 
 -----------------------------------------------------------------------
 Jonathan R Hudson                       Email: jrh@jrhudson.demon.co.uk
 WWW: http://www.jrhudson.demon.co.uk    Voice/Fax: +44 (0)1703 867843


