diff options
-rw-r--r-- | winsup/cygserver/ChangeLog | 9 | ||||
-rw-r--r-- | winsup/cygserver/Makefile.in | 4 | ||||
-rw-r--r-- | winsup/cygserver/sysv_shm.cc | 2 | ||||
-rw-r--r-- | winsup/cygserver/transport.cc | 8 | ||||
-rw-r--r-- | winsup/cygserver/transport_sockets.cc | 395 | ||||
-rw-r--r-- | winsup/cygserver/transport_sockets.h | 46 |
6 files changed, 14 insertions, 450 deletions
diff --git a/winsup/cygserver/ChangeLog b/winsup/cygserver/ChangeLog index 1dd6cdf39..360685483 100644 --- a/winsup/cygserver/ChangeLog +++ b/winsup/cygserver/ChangeLog @@ -1,3 +1,12 @@ +2007-02-22 Corinna Vinschen <corinna@vinschen.de> + + * Makefile.in (OBJS): Drop transport_sockets.o. + * sysv_shm.cc (shmget_allocate_segment): Remove spurious cast. + * transport.cc: Don't include transport_sockets.h. + (create_server_transport): Always create transport_layer_pipes. + * transport_sockets.cc: Remove. + * transport_sockets.h: Remove. + 2006-05-24 Christopher Faylor <cgf@timesys.com> * configure.in: Update to newer autoconf. diff --git a/winsup/cygserver/Makefile.in b/winsup/cygserver/Makefile.in index d3426f6b6..6476fe87e 100644 --- a/winsup/cygserver/Makefile.in +++ b/winsup/cygserver/Makefile.in @@ -1,5 +1,5 @@ # Makefile for Cygwin server -# Copyright 2003, 2006 Red Hat, Inc. +# Copyright 2003, 2006, 2007 Red Hat, Inc. # This file is part of Cygwin. @@ -38,7 +38,7 @@ override CXXFLAGS+=-MMD -DHAVE_DECL_GETOPT=0 -D__OUTSIDE_CYGWIN__ -DSYSCONFDIR=" .SUFFIXES: .c .cc .a .o .d OBJS:= cygserver.o client.o process.o msg.o sem.o shm.o threaded_queue.o \ - transport.o transport_pipes.o transport_sockets.o \ + transport.o transport_pipes.o \ bsd_helper.o bsd_log.o bsd_mutex.o \ sysv_msg.o sysv_sem.o sysv_shm.o wincap.o LIBOBJS:=${patsubst %.o,lib%.o,$(OBJS)} diff --git a/winsup/cygserver/sysv_shm.cc b/winsup/cygserver/sysv_shm.cc index c3cf730e7..88ddae033 100644 --- a/winsup/cygserver/sysv_shm.cc +++ b/winsup/cygserver/sysv_shm.cc @@ -729,7 +729,7 @@ shmget_allocate_segment(struct thread *td, struct shmget_args *uap, int mode) if (shm_nused >= shminfo.shmmni) /* Any shmids left? */ return (ENOSPC); size = round_page(uap->size); - if (shm_committed + btoc(size) > (unsigned long) shminfo.shmall) + if (shm_committed + btoc(size) > shminfo.shmall) return (ENOMEM); if (shm_last_free < 0) { shmrealloc(); /* Maybe expand the shmsegs[] array. */ diff --git a/winsup/cygserver/transport.cc b/winsup/cygserver/transport.cc index 0e9708272..ff9ce8d80 100644 --- a/winsup/cygserver/transport.cc +++ b/winsup/cygserver/transport.cc @@ -1,6 +1,6 @@ /* transport.cc - Copyright 2001, 2002, 2003, 2004 Red Hat Inc. + Copyright 2001, 2002, 2003, 2004, 2007 Red Hat Inc. Written by Robert Collins <rbtcollins@hotmail.com> @@ -21,16 +21,12 @@ details. */ #include "transport.h" #include "transport_pipes.h" -#include "transport_sockets.h" /* The factory */ transport_layer_base * create_server_transport () { - if (wincap.is_winnt ()) - return new transport_layer_pipes; - else - return new transport_layer_sockets; + return new transport_layer_pipes; } #ifndef __INSIDE_CYGWIN__ diff --git a/winsup/cygserver/transport_sockets.cc b/winsup/cygserver/transport_sockets.cc deleted file mode 100644 index d89e343dc..000000000 --- a/winsup/cygserver/transport_sockets.cc +++ /dev/null @@ -1,395 +0,0 @@ -/* transport_sockets.cc - - Copyright 2001, 2002, 2003, 2004 Red Hat Inc. - - Written by Robert Collins <rbtcollins@hotmail.com> - -This file is part of Cygwin. - -This software is a copyrighted work licensed under the terms of the -Cygwin license. Please consult the file "CYGWIN_LICENSE" for -details. */ - -/* to allow this to link into cygwin and the .dll, a little magic is needed. */ -#ifdef __OUTSIDE_CYGWIN__ -#include "woutsup.h" -#else -#include "winsup.h" -#endif - -#include <sys/types.h> -#include <sys/socket.h> -#include <sys/stat.h> - -#include <assert.h> -#include <stdio.h> -#include <unistd.h> - -#include "cygerrno.h" -#include "transport.h" -#include "transport_sockets.h" - -#ifdef __INSIDE_CYGWIN__ -#define SET_ERRNO(err) set_errno (err) -#define GET_ERRNO() get_errno () -#else -#define SET_ERRNO(err) errno = (err) -#define GET_ERRNO() (errno) -#endif - -/* to allow this to link into cygwin and the .dll, a little magic is needed. */ -#ifndef __OUTSIDE_CYGWIN__ - -extern "C" int cygwin_accept (int fd, struct sockaddr *, int *len); -extern "C" int cygwin_bind (int fd, const struct sockaddr *, int len); -extern "C" int cygwin_connect (int fd, const struct sockaddr *, int len); -extern "C" int cygwin_listen (int fd, int backlog); -extern "C" int cygwin_shutdown (int fd, int how); -extern "C" int cygwin_socket (int af, int type, int protocol); - -#else /* __OUTSIDE_CYGWIN__ */ - -#define cygwin_accept(A,B,C) ::accept (A,B,C) -#define cygwin_bind(A,B,C) ::bind (A,B,C) -#define cygwin_connect(A,B,C) ::connect (A,B,C) -#define cygwin_listen(A,B) ::listen (A,B) -#define cygwin_shutdown(A,B) ::shutdown (A,B) -#define cygwin_socket(A,B,C) ::socket (A,B,C) - -#endif /* __OUTSIDE_CYGWIN__ */ - -enum - { - MAX_CONNECT_RETRY = 64 - }; - -transport_layer_sockets::transport_layer_sockets (const int fd) - : _fd (fd), - _addr_len (0), - _is_accepted_endpoint (true), - _is_listening_endpoint (false) -{ - assert (_fd != -1); - - memset (&_addr, '\0', sizeof (_addr)); -} - -transport_layer_sockets::transport_layer_sockets () - : _fd (-1), - _addr_len (0), - _is_accepted_endpoint (false), - _is_listening_endpoint (false) -{ - memset (&_addr, '\0', sizeof (_addr)); - - _addr.sun_family = AF_UNIX; - strcpy (_addr.sun_path, "/tmp/cygdaemo"); // FIXME: $TMP? - _addr_len = SUN_LEN (&_addr); -} - -transport_layer_sockets::~transport_layer_sockets () -{ - close (); -} - -#ifndef __INSIDE_CYGWIN__ - -int -transport_layer_sockets::listen () -{ - assert (_fd == -1); - assert (!_is_accepted_endpoint); - assert (!_is_listening_endpoint); - - debug_printf ("listen () [this = %p]", this); - - struct stat sbuf; - - if (stat (_addr.sun_path, &sbuf) == -1) - { - if (GET_ERRNO () != ENOENT) - { - system_printf ("cannot access socket file `%s': %s", - _addr.sun_path, strerror (GET_ERRNO ())); - return -1; - } - } - else if (S_ISSOCK (sbuf.st_mode)) - { - // The socket already exists: is a duplicate cygserver running? - - const int newfd = cygwin_socket (AF_UNIX, SOCK_STREAM, 0); - - if (newfd == -1) - { - system_printf ("failed to create UNIX domain socket: %s", - strerror (GET_ERRNO ())); - return -1; - } - - if (cygwin_connect (newfd, (struct sockaddr *) &_addr, _addr_len) == 0) - { - system_printf ("the daemon is already running"); - (void) cygwin_shutdown (newfd, SHUT_WR); - char buf[BUFSIZ]; - while (::read (newfd, buf, sizeof (buf)) > 0) - {} - (void) ::close (newfd); - return -1; - } - - if (unlink (_addr.sun_path) == -1) - { - system_printf ("failed to remove `%s': %s", - _addr.sun_path, strerror (GET_ERRNO ())); - (void) ::close (newfd); - return -1; - } - } - else - { - system_printf ("cannot create socket `%s': File already exists", - _addr.sun_path); - return -1; - } - - _fd = cygwin_socket (AF_UNIX, SOCK_STREAM, 0); - - if (_fd == -1) - { - system_printf ("failed to create UNIX domain socket: %s", - strerror (GET_ERRNO ())); - return -1; - } - - if (cygwin_bind (_fd, (struct sockaddr *) &_addr, _addr_len) == -1) - { - const int saved_errno = GET_ERRNO (); - close (); - SET_ERRNO (saved_errno); - system_printf ("failed to bind UNIX domain socket `%s': %s", - _addr.sun_path, strerror (GET_ERRNO ())); - return -1; - } - - _is_listening_endpoint = true; // i.e. this really means "have bound". - - if (cygwin_listen (_fd, SOMAXCONN) == -1) - { - const int saved_errno = GET_ERRNO (); - close (); - SET_ERRNO (saved_errno); - system_printf ("failed to listen on UNIX domain socket `%s': %s", - _addr.sun_path, strerror (GET_ERRNO ())); - return -1; - } - - debug_printf ("0 = listen () [this = %p, fd = %d]", this, _fd); - - return 0; -} - -class transport_layer_sockets * -transport_layer_sockets::accept (bool *const recoverable) -{ - assert (_fd != -1); - assert (!_is_accepted_endpoint); - assert (_is_listening_endpoint); - - debug_printf ("accept () [this = %p, fd = %d]", this, _fd); - - struct sockaddr_un client_addr; - socklen_t client_addr_len = sizeof (client_addr); - - const int accept_fd = - cygwin_accept (_fd, (struct sockaddr *) &client_addr, &client_addr_len); - - if (accept_fd == -1) - { - system_printf ("failed to accept connection: %s", strerror (GET_ERRNO ())); - switch (GET_ERRNO ()) - { - case ECONNABORTED: - case EINTR: - case EMFILE: - case ENFILE: - case ENOBUFS: - case ENOMEM: - *recoverable = true; - break; - - default: - *recoverable = false; - break; - } - return NULL; - } - - debug_printf ("%d = accept () [this = %p, fd = %d]", accept_fd, this, _fd); - - return new transport_layer_sockets (accept_fd); -} - -#endif /* !__INSIDE_CYGWIN__ */ - -void -transport_layer_sockets::close () -{ - debug_printf ("close () [this = %p, fd = %d]", this, _fd); - - if (_is_listening_endpoint) - (void) unlink (_addr.sun_path); - - if (_fd != -1) - { - (void) cygwin_shutdown (_fd, SHUT_WR); - if (!_is_listening_endpoint) - { - char buf[BUFSIZ]; - while (::read (_fd, buf, sizeof (buf)) > 0) - {} - } - (void) ::close (_fd); - _fd = -1; - } - - _is_listening_endpoint = false; -} - -ssize_t -transport_layer_sockets::read (void *const buf, const size_t buf_len) -{ - assert (_fd != -1); - assert (!_is_listening_endpoint); - - assert (buf); - assert (buf_len > 0); - - // verbose: debug_printf ("read (buf = %p, len = %u) [this = %p, fd = %d]", - // buf, buf_len, this, _fd); - - char *read_buf = static_cast<char *> (buf); - size_t read_buf_len = buf_len; - ssize_t res = 0; - - while (read_buf_len != 0 - && (res = ::read (_fd, read_buf, read_buf_len)) > 0) - { - read_buf += res; - read_buf_len -= res; - - assert (read_buf_len >= 0); - } - - if (res != -1) - { - if (res == 0) - SET_ERRNO (EIO); // FIXME? - - res = buf_len - read_buf_len; - } - - if (res != static_cast<ssize_t> (buf_len)) - debug_printf ("%d = read (buf = %p, len = %u) [this = %p, fd = %d]: %s", - res, buf, buf_len, this, _fd, - (res == -1 ? strerror (GET_ERRNO ()) : "EOF")); - else - { - // verbose: debug_printf ("%d = read (buf = %p, len = %u) [this = %p, fd = %d]", - // res, buf, buf_len, this, _fd); - } - - return res; -} - -ssize_t -transport_layer_sockets::write (void *const buf, const size_t buf_len) -{ - assert (_fd != -1); - assert (!_is_listening_endpoint); - - assert (buf); - assert (buf_len > 0); - - // verbose: debug_printf ("write (buf = %p, len = %u) [this = %p, fd = %d]", - // buf, buf_len, this, _fd); - - char *write_buf = static_cast<char *> (buf); - size_t write_buf_len = buf_len; - ssize_t res = 0; - - while (write_buf_len != 0 - && (res = ::write (_fd, write_buf, write_buf_len)) > 0) - { - write_buf += res; - write_buf_len -= res; - - assert (write_buf_len >= 0); - } - - if (res != -1) - { - if (res == 0) - SET_ERRNO (EIO); // FIXME? - - res = buf_len - write_buf_len; - } - - if (res != static_cast<ssize_t> (buf_len)) - debug_printf ("%d = write (buf = %p, len = %u) [this = %p, fd = %d]: %s", - res, buf, buf_len, this, _fd, - (res == -1 ? strerror (GET_ERRNO ()) : "EOF")); - else - { - // verbose: debug_printf ("%d = write (buf = %p, len = %u) [this = %p, fd = %d]", - // res, buf, buf_len, this, _fd); - } - - return res; -} - -int -transport_layer_sockets::connect () -{ - assert (_fd == -1); - assert (!_is_accepted_endpoint); - assert (!_is_listening_endpoint); - - static bool assume_cygserver = false; - - debug_printf ("connect () [this = %p]", this); - - for (int retries = 0; retries != MAX_CONNECT_RETRY; retries++) - { - _fd = cygwin_socket (AF_UNIX, SOCK_STREAM, 0); - - if (_fd == -1) - { - system_printf ("failed to create UNIX domain socket: %s", - strerror (GET_ERRNO ())); - return -1; - } - - if (cygwin_connect (_fd, (struct sockaddr *) &_addr, _addr_len) == 0) - { - assume_cygserver = true; - debug_printf ("0 = connect () [this = %p, fd = %d]", this, _fd); - return 0; - } - - if (!assume_cygserver || GET_ERRNO () != ECONNREFUSED) - { - debug_printf ("failed to connect to server: %s", strerror (GET_ERRNO ())); - (void) ::close (_fd); - _fd = -1; - return -1; - } - - (void) ::close (_fd); - _fd = -1; - Sleep (0); // Give the server a chance. - } - - debug_printf ("failed to connect to server: %s", strerror (GET_ERRNO ())); - return -1; -} diff --git a/winsup/cygserver/transport_sockets.h b/winsup/cygserver/transport_sockets.h deleted file mode 100644 index dab086e7d..000000000 --- a/winsup/cygserver/transport_sockets.h +++ /dev/null @@ -1,46 +0,0 @@ -/* transport_sockets.h - - Copyright 2001, 2002, 2003 Red Hat Inc. - - Written by Robert Collins <rbtcollins@hotmail.com> - -This file is part of Cygwin. - -This software is a copyrighted work licensed under the terms of the -Cygwin license. Please consult the file "CYGWIN_LICENSE" for -details. */ - -#ifndef _TRANSPORT_SOCKETS_H -#define _TRANSPORT_SOCKETS_H - -#include <sys/socket.h> -#include <sys/un.h> - -class transport_layer_sockets : public transport_layer_base -{ -public: -#ifndef __INSIDE_CYGWIN__ - virtual int listen (); - virtual class transport_layer_sockets *accept (bool *recoverable); -#endif - - virtual void close (); - virtual ssize_t read (void *buf, size_t len); - virtual ssize_t write (void *buf, size_t len); - virtual int connect (); - - transport_layer_sockets (); - virtual ~transport_layer_sockets (); - -private: - /* for socket based communications */ - int _fd; - struct sockaddr_un _addr; - socklen_t _addr_len; - const bool _is_accepted_endpoint; - bool _is_listening_endpoint; - - transport_layer_sockets (int fd); -}; - -#endif /* _TRANSPORT_SOCKETS_H */ |