1*2286d8edStholo /* This program is free software; you can redistribute it and/or modify
2*2286d8edStholo it under the terms of the GNU General Public License as published by
3*2286d8edStholo the Free Software Foundation; either version 2, or (at your option)
4*2286d8edStholo any later version.
5*2286d8edStholo
6*2286d8edStholo This program is distributed in the hope that it will be useful,
7*2286d8edStholo but WITHOUT ANY WARRANTY; without even the implied warranty of
8*2286d8edStholo MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9*2286d8edStholo GNU General Public License for more details. */
10*2286d8edStholo
11*2286d8edStholo #include <assert.h>
12*2286d8edStholo #include "cvs.h"
13*2286d8edStholo #include "rcmd.h"
14*2286d8edStholo
15*2286d8edStholo #include <sys/types.h>
16*2286d8edStholo #include <sys/socket.h>
17*2286d8edStholo #include <netdb.h>
18*2286d8edStholo
19*2286d8edStholo #include "options.h"
20*2286d8edStholo
21*2286d8edStholo static char *cvs_server;
22*2286d8edStholo static char *command;
23*2286d8edStholo
24*2286d8edStholo extern int trace;
25*2286d8edStholo
26*2286d8edStholo void
os2_start_server(int * tofd,int * fromfd,char * client_user,char * server_user,char * server_host,char * server_cvsroot)27*2286d8edStholo os2_start_server (int *tofd, int *fromfd,
28*2286d8edStholo char *client_user,
29*2286d8edStholo char *server_user,
30*2286d8edStholo char *server_host,
31*2286d8edStholo char *server_cvsroot)
32*2286d8edStholo {
33*2286d8edStholo int fd, port;
34*2286d8edStholo char *portenv;
35*2286d8edStholo struct servent *sptr;
36*2286d8edStholo const char *rcmd_host = (const char *) server_host;
37*2286d8edStholo
38*2286d8edStholo if (! (cvs_server = getenv ("CVS_SERVER")))
39*2286d8edStholo cvs_server = "cvs";
40*2286d8edStholo command = xmalloc (strlen (cvs_server)
41*2286d8edStholo + strlen (server_cvsroot)
42*2286d8edStholo + 50);
43*2286d8edStholo sprintf (command, "%s server", cvs_server);
44*2286d8edStholo
45*2286d8edStholo portenv = getenv ("CVS_RCMD_PORT");
46*2286d8edStholo if (portenv)
47*2286d8edStholo port = atoi (portenv);
48*2286d8edStholo else if ((sptr = getservbyname ("shell", "tcp")) != NULL)
49*2286d8edStholo port = sptr->s_port;
50*2286d8edStholo else
51*2286d8edStholo port = 514; /* shell/tcp */
52*2286d8edStholo
53*2286d8edStholo if (trace)
54*2286d8edStholo {
55*2286d8edStholo fprintf (stderr, "os2_start_server(): connecting to %s:%d\n",
56*2286d8edStholo server_host, port);
57*2286d8edStholo fprintf (stderr, "local_user = %s, remote_user = %s, CVSROOT = %s\n",
58*2286d8edStholo client_user, (server_user ? server_user : client_user),
59*2286d8edStholo server_cvsroot);
60*2286d8edStholo }
61*2286d8edStholo
62*2286d8edStholo fd = rcmd (&rcmd_host, port,
63*2286d8edStholo client_user,
64*2286d8edStholo (server_user ? server_user : client_user),
65*2286d8edStholo command, 0);
66*2286d8edStholo
67*2286d8edStholo if (fd < 0)
68*2286d8edStholo error (1, errno, "cannot start server via rcmd()");
69*2286d8edStholo
70*2286d8edStholo *tofd = fd;
71*2286d8edStholo *fromfd = fd;
72*2286d8edStholo free (command);
73*2286d8edStholo }
74*2286d8edStholo
75*2286d8edStholo void
os2_shutdown_server(int fd)76*2286d8edStholo os2_shutdown_server (int fd)
77*2286d8edStholo {
78*2286d8edStholo /* FIXME: shutdown on files seems to have no bad effects */
79*2286d8edStholo if (shutdown (fd, 2) < 0 && errno != ENOTSOCK)
80*2286d8edStholo error (1, 0, "couldn't shutdown server connection");
81*2286d8edStholo if (close (fd) < 0)
82*2286d8edStholo error (1, 0, "couldn't close server connection");
83*2286d8edStholo }
84*2286d8edStholo
85