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