xref: /openbsd-src/gnu/usr.bin/cvs/vms/startserver.c (revision 50bf276cd1c7e20f1eda64a5e63e0fae39e12a95)
1*50bf276cStholo #include <socket.h>
2*50bf276cStholo #include <netdb.h>
3*50bf276cStholo #include <errno.h>
4*50bf276cStholo 
5*50bf276cStholo #include "options.h"
6*50bf276cStholo 
7*50bf276cStholo static char *cvs_server;
8*50bf276cStholo static char *command;
9*50bf276cStholo 
10*50bf276cStholo extern int trace;
11*50bf276cStholo 
12*50bf276cStholo void
vms_start_server(int * tofd,int * fromfd,char * client_user,char * server_user,char * server_host,char * server_cvsroot)13*50bf276cStholo vms_start_server (int *tofd, int *fromfd,
14*50bf276cStholo                   char *client_user, char *server_user,
15*50bf276cStholo                   char *server_host, char *server_cvsroot)
16*50bf276cStholo {
17*50bf276cStholo   int fd, port;
18*50bf276cStholo   char *portenv;
19*50bf276cStholo   struct servent *sptr;
20*50bf276cStholo 
21*50bf276cStholo   if (! (cvs_server = getenv ("CVS_SERVER")))
22*50bf276cStholo       cvs_server = "cvs";
23*50bf276cStholo   command = xmalloc (strlen (cvs_server)
24*50bf276cStholo 		     + strlen (server_cvsroot)
25*50bf276cStholo 		     + 50);
26*50bf276cStholo   sprintf(command, "%s server", cvs_server);
27*50bf276cStholo 
28*50bf276cStholo   portenv = getenv("CVS_RCMD_PORT");
29*50bf276cStholo   if (portenv)
30*50bf276cStholo       port = atoi(portenv);
31*50bf276cStholo   else if ((sptr = getservbyname("shell", "tcp")) != NULL)
32*50bf276cStholo       port = sptr->s_port;
33*50bf276cStholo   else
34*50bf276cStholo       port = 514; /* shell/tcp */
35*50bf276cStholo 
36*50bf276cStholo   if(trace)
37*50bf276cStholo     {
38*50bf276cStholo     fprintf(stderr, "vms_start_server(): connecting to %s:%d\n",
39*50bf276cStholo             server_host, port);
40*50bf276cStholo     fprintf(stderr, "local_user = %s, remote_user = %s, CVSROOT = %s\n",
41*50bf276cStholo             client_user, (server_user ? server_user : client_user),
42*50bf276cStholo             server_cvsroot);
43*50bf276cStholo     }
44*50bf276cStholo 
45*50bf276cStholo   fd = rcmd(&server_host, port,
46*50bf276cStholo             client_user,
47*50bf276cStholo             (server_user ? server_user : client_user),
48*50bf276cStholo             command, 0);
49*50bf276cStholo 
50*50bf276cStholo   if (fd < 0)
51*50bf276cStholo      error (1, errno, "cannot start server via rcmd()");
52*50bf276cStholo 
53*50bf276cStholo   *tofd = fd;
54*50bf276cStholo   *fromfd = fd;
55*50bf276cStholo   free (command);
56*50bf276cStholo }
57