home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / cvs-1.8.7-src.tgz / tar.out / fsf / cvs / macintosh / server_if.c < prev    next >
C/C++ Source or Header  |  1996-09-28  |  2KB  |  73 lines

  1. /*
  2.  * server_if.c
  3.  * Open connection to the CVS server under MacOS
  4.  *
  5.  * Michael Ladwig <mike@twinpeaks.prc.com> --- November 1995
  6.  */
  7.  
  8. #include "mac_config.h"
  9. #include "cvs.h"
  10.  
  11. #include <GUSI.h>
  12. #include <sys/socket.h>
  13.  
  14. static int read_fd, write_fd;
  15.     
  16. void
  17. macos_start_server (int *tofd, int *fromfd,
  18.           char *client_user,
  19.           char *server_user,
  20.           char *server_host,
  21.           char *server_cvsroot)
  22. {
  23.     char *cvs_server;
  24.     char *command;
  25.     char *portenv;
  26.     struct servent *sptr;
  27.     unsigned short port;
  28.  
  29.     if (! (cvs_server = getenv ("CVS_SERVER")))
  30.         cvs_server = "cvs";
  31.     command = xmalloc (strlen (cvs_server)
  32.                + strlen (server_cvsroot)
  33.                + 50);
  34.     sprintf (command, "%s -d %s server", cvs_server, server_cvsroot);
  35.  
  36.     portenv = getenv("CVS_RCMD_PORT");
  37.     if (portenv)
  38.     port = atoi(portenv);
  39.     else if ((sptr = getservbyname("shell", "tcp")) != NULL)
  40.     port = sptr->s_port;
  41.     else
  42.     /* This is the normal case.  Macs will generally lack a /etc/services
  43.        file (causing getservbyname to fail), and getenv is only something
  44.        that we provide via our own AppleEvents stuff, not a standard
  45.        Mac feature.  */
  46.     port = 514;
  47.  
  48.     read_fd = rcmd (&server_host,
  49.                     port,
  50.                     client_user,
  51.                 (server_user ? server_user : client_user),
  52.                 command,
  53.                 0);
  54.     if (read_fd < 0)
  55.     error (1, errno, "cannot start server via rcmd");
  56.     
  57.     /* Split the socket into a reading and a writing half.  */
  58.     if ((write_fd = dup (read_fd)) < 0)
  59.         error (1, errno, "duplicating server connection");
  60.     
  61.     *tofd = write_fd;
  62.     *fromfd = read_fd;
  63.     free (command);
  64. }
  65.  
  66.  
  67. void
  68. macos_shutdown_server (int to_server)
  69. {
  70.     if( close (read_fd) != 0 ) perror( "close on read_fd");
  71.     if( close (write_fd) != 0 ) perror( "close on write_fd");
  72. }
  73.