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