diff options
-rw-r--r-- | winsup/cygwin/ChangeLog | 4 | ||||
-rw-r--r-- | winsup/cygwin/ChangeLog.branch | 22 | ||||
-rw-r--r-- | winsup/cygwin/Makefile.in | 4 | ||||
-rw-r--r-- | winsup/cygwin/cygheap.h | 1 | ||||
-rwxr-xr-x | winsup/cygwin/cygwin-gperf | 26 | ||||
-rw-r--r-- | winsup/cygwin/devices.h | 15 | ||||
-rw-r--r-- | winsup/cygwin/dtable.cc | 20 | ||||
-rw-r--r-- | winsup/cygwin/fhandler.h | 4 | ||||
-rw-r--r-- | winsup/cygwin/fhandler_socket.cc | 15 | ||||
-rw-r--r-- | winsup/cygwin/lib/getopt.c | 11 | ||||
-rw-r--r-- | winsup/cygwin/net.cc | 96 | ||||
-rw-r--r-- | winsup/cygwin/select.cc | 4 |
12 files changed, 127 insertions, 95 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 5c5d53462f3..f81173f33c0 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,5 +1,9 @@ 2003-03-02 Christopher Faylor <cgf@redhat.com> + * lib/getopt.c: Nuke use of unneeded BSDisms. + +2003-03-02 Christopher Faylor <cgf@redhat.com> + * dll_init.cc (dll_list::load_after_fork): Don't revert to LoadLibrary if LoadLibraryEx fails. * dtable.cc (dtable::dec_console_fds): Eliminate. diff --git a/winsup/cygwin/ChangeLog.branch b/winsup/cygwin/ChangeLog.branch index 0fcc2910016..4b6af364af8 100644 --- a/winsup/cygwin/ChangeLog.branch +++ b/winsup/cygwin/ChangeLog.branch @@ -1,3 +1,25 @@ +2003-03-02 Christopher Faylor <cgf@redhat.com> + + * Makefile.in (devicess.cc): Make generation dependent on cygwin-gperf. + * cygheap.h (cygheap_fdmanip): Add fhandler_socket cast. + * cygwin-gperf: Autogenerate references to network devices. + * devices.h: Create separate device types for all network types. + Export references to global network device storage. + * dtable.cc (dtable::release): Use generic determination to control + when need_fixup_before needs to be decremented. + (dtable::init_std_file_from_handle): Replace use of 'socket_dev' with + 'tcp_dev'. + (build_fh_pc): Adapt to new socket types. Don't increment fixup_before + here. + * fhandler.h (fhandler_base::need_fixup_before): Declare/define. + (fhandler_socket::need_fixup_before): Ditto. + * fhandler_socket.cc (fhandler_socket::accept): Accommodate new fdsock + definition. + * net.cc: Throughout, change use of fdsock to return true/false for + success/failure and take cygheap_fdmanip type and device + * select.cc (set_bits): Use 'is_socket ()' test rather than + specificially testing device type. + 2003-02-24 Christopher Faylor <cgf@redhat.com> * device.gperf: Remove nonsensical devices. diff --git a/winsup/cygwin/Makefile.in b/winsup/cygwin/Makefile.in index 489c4d21ffa..cb5c39db33d 100644 --- a/winsup/cygwin/Makefile.in +++ b/winsup/cygwin/Makefile.in @@ -356,8 +356,8 @@ cygserver_client_outside.o: cygserver_client.cc # gperf -c --key-positions='1-126' -r -t -C -E -L 'ANSI-C' -Hdevhash -N'device::lookup' -Z devstring -7 $? |\ -$(srcdir)/devices.cc: devices.gperf devices.h - $(srcdir)/cygwin-gperf $^ > $@ +$(srcdir)/devices.cc: cygwin-gperf devices.gperf devices.h + $^ > $@ cygserver.exe: cygserver.o cygserver_shm.o cygserver_transport_outside.o cygserver_transport_pipes_outside.o cygserver_transport_sockets_outside.o cygserver_client_outside.o cygserver_process.o threaded_queue.o wincap.o version.o smallprint.o $(CXX) -o $@ $^ -lstdc++ diff --git a/winsup/cygwin/cygheap.h b/winsup/cygwin/cygheap.h index bfa7a930861..281f9b4b7eb 100644 --- a/winsup/cygwin/cygheap.h +++ b/winsup/cygwin/cygheap.h @@ -248,6 +248,7 @@ class cygheap_fdmanip } operator int &() {return fd;} operator fhandler_base* &() {return *fh;} + operator fhandler_socket* () const {return reinterpret_cast<fhandler_socket *> (*fh);} void operator = (fhandler_base *fh) {*this->fh = fh;} fhandler_base *operator -> () const {return *fh;} bool isopen () const diff --git a/winsup/cygwin/cygwin-gperf b/winsup/cygwin/cygwin-gperf index 3b083732a01..6b830c36bd8 100755 --- a/winsup/cygwin/cygwin-gperf +++ b/winsup/cygwin/cygwin-gperf @@ -21,7 +21,12 @@ my %fh_declare = ( 'process_dev' => '&process_dev_storage', 'piper_dev' => '&piper_dev_storage', 'pipew_dev' => '&pipew_dev_storage', - 'socket_dev' => '&socket_dev_storage' + 'tcp_dev' => '&tcp_dev_storage', + 'udp_dev' => '&udp_dev_storage', + 'icmp_dev' => '&icmp_dev_storage', + 'unix_dev' => '&unix_dev_storage', + 'stream_dev' => '&stream_dev_storage', + 'dgram_dev' => '&dgram_dev_storage' ); foreach (@lines) { @@ -49,8 +54,23 @@ static const device registry_dev_storage = static const device process_dev_storage = {"", FH_PROCESS, "", 0, 0, 0, 0}; -static const device socket_dev_storage = - {"", FH_SOCKET, "", 0, 0, 0, 0}; +static const device tcp_dev_storage = + {"/dev/inet/tcp", FH_TCP, "", 0, 0, 0, 0}; + +static const device udp_dev_storage = + {"/dev/inet/udp", FH_UCP, "", 0, 0, 0, 0}; + +static const device icmp_dev_storage = + {"/dev/inet/icmp", FH_ICMP, "", 0, 0, 0, 0}; + +static const device unix_dev_storage = + {"/dev/inet/unix", FH_UNIX, "", 0, 0, 0, 0}; + +static const device stream_dev_storage = + {"/dev/inet/stream", FH_STREAM, "", 0, 0, 0, 0}; + +static const device dgram_dev_storage = + {"/dev/inet/dgram", FH_DGRAM, "", 0, 0, 0, 0}; static const device piper_dev_storage = {"", FH_PIPER, "", 0, 0, 0, 0}; diff --git a/winsup/cygwin/devices.h b/winsup/cygwin/devices.h index 5f59c4ba5c7..be5b99cf05d 100644 --- a/winsup/cygwin/devices.h +++ b/winsup/cygwin/devices.h @@ -43,7 +43,6 @@ enum fh_devices FH_PIPER = FHDEV (0, 254), FH_PIPEW = FHDEV (0, 253), FH_FIFO = FHDEV (0, 252), - FH_SOCKET = FHDEV (0, 251), FH_PROC = FHDEV (0, 250), FH_REGISTRY= FHDEV (0, 249), FH_PROCESS = FHDEV (0, 248), @@ -109,6 +108,14 @@ enum fh_devices DEV_RAWDRIVE_MAJOR = 65, FH_RAWDRIVE= FHDEV (DEV_RAWDRIVE_MAJOR, 0), + DEV_TCP_MAJOR = 30, + FH_TCP = FHDEV (DEV_TCP_MAJOR, 36), + FH_UCP = FHDEV (DEV_TCP_MAJOR, 39), + FH_ICMP = FHDEV (DEV_TCP_MAJOR, 33), + FH_UNIX = FHDEV (DEV_TCP_MAJOR, 120), + FH_STREAM = FHDEV (DEV_TCP_MAJOR, 121), + FH_DGRAM = FHDEV (DEV_TCP_MAJOR, 122), + FH_BAD = FHDEV (0, 0) }; @@ -155,3 +162,9 @@ extern const device *socket_dev; extern const device *ttym_dev; extern const device *ttys_dev; extern const device *urandom_dev; +extern const device *tcp_dev; +extern const device *udp_dev; +extern const device *icmp_dev; +extern const device *unix_dev; +extern const device *stream_dev; +extern const device *dgram_dev; diff --git a/winsup/cygwin/dtable.cc b/winsup/cygwin/dtable.cc index de2570bcaef..38e89ac78c5 100644 --- a/winsup/cygwin/dtable.cc +++ b/winsup/cygwin/dtable.cc @@ -177,12 +177,8 @@ dtable::release (int fd) { if (!not_open (fd)) { - switch (fds[fd]->get_device ()) - { - case FH_SOCKET: - dec_need_fixup_before (); - break; - } + if (fds[fd]->need_fixup_before ()) + dec_need_fixup_before (); delete fds[fd]; fds[fd] = NULL; } @@ -245,7 +241,7 @@ dtable::init_std_file_from_handle (int fd, HANDLE handle) dev = *pipew_dev; } else if (wsock_started && getpeername ((SOCKET) handle, &sa, &sal) == 0) - dev = *socket_dev; + dev = *tcp_dev; else if (GetCommState (handle, &dcb)) dev.parse ("/dev/ttyS0"); else @@ -380,9 +376,13 @@ build_fh_pc (path_conv& pc) case FH_PIPEW: fh = cnew (fhandler_pipe) (); break; - case FH_SOCKET: - if ((fh = cnew (fhandler_socket) ())) - cygheap->fdtab.inc_need_fixup_before (); + case FH_TCP: + case FH_UCP: + case FH_ICMP: + case FH_UNIX: + case FH_STREAM: + case FH_DGRAM: + fh = cnew (fhandler_socket) (); break; case FH_FS: fh = cnew (fhandler_disk_file) (); diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h index 930c680d373..7461efced51 100644 --- a/winsup/cygwin/fhandler.h +++ b/winsup/cygwin/fhandler.h @@ -257,6 +257,7 @@ class fhandler_base /* fixup fd possibly non-inherited handles after fork */ void fork_fixup (HANDLE parent, HANDLE &h, const char *name); + virtual bool need_fixup_before () const {return false;} virtual int open (int flags, mode_t mode = 0); int open_fs (int flags, mode_t mode = 0); @@ -311,7 +312,7 @@ class fhandler_base virtual bool isdevice () { return true; } virtual bool isfifo () { return false; } virtual char *ptsname () { return NULL;} - virtual class fhandler_socket *is_socket () { return 0; } + virtual class fhandler_socket *is_socket () { return NULL; } virtual class fhandler_console *is_console () { return 0; } virtual int is_windows () {return 0; } @@ -410,6 +411,7 @@ class fhandler_socket: public fhandler_base virtual void fixup_before_fork_exec (DWORD); void fixup_after_fork (HANDLE); void fixup_after_exec (HANDLE); + bool need_fixup_before () const {return true;} select_record *select_read (select_record *s); select_record *select_write (select_record *s); diff --git a/winsup/cygwin/fhandler_socket.cc b/winsup/cygwin/fhandler_socket.cc index 461d629a1e8..c87790ec679 100644 --- a/winsup/cygwin/fhandler_socket.cc +++ b/winsup/cygwin/fhandler_socket.cc @@ -37,7 +37,7 @@ #define SECRET_EVENT_NAME "cygwin.local_socket.secret.%d.%08x-%08x-%08x-%08x" #define ENTROPY_SOURCE_NAME "/dev/urandom" -extern fhandler_socket *fdsock (int& fd, const char *name, SOCKET soc); +extern bool fdsock (cygheap_fdmanip& fd, const device *, SOCKET soc); extern "C" { int sscanf (const char *, const char *, ...); } /* End of "C" section */ @@ -698,16 +698,13 @@ fhandler_socket::accept (struct sockaddr *peer, int *len) else { cygheap_fdnew res_fd; - fhandler_socket* res_fh = NULL; - if (res_fd >= 0) - res_fh = fdsock (res_fd, get_name (), res); - if (res_fh) + if (res_fd >= 0 && fdsock (res_fd, &dev (), res)) { if (get_addr_family () == AF_LOCAL) - res_fh->set_sun_path (get_sun_path ()); - res_fh->set_addr_family (get_addr_family ()); - res_fh->set_socket_type (get_socket_type ()); - res_fh->set_connect_state (CONNECTED); + ((fhandler_socket *) res_fd)->set_sun_path (get_sun_path ()); + ((fhandler_socket *) res_fd)->set_addr_family (get_addr_family ()); + ((fhandler_socket *) res_fd)->set_socket_type (get_socket_type ()); + ((fhandler_socket *) res_fd)->set_connect_state (CONNECTED); res = res_fd; } else diff --git a/winsup/cygwin/lib/getopt.c b/winsup/cygwin/lib/getopt.c index 1a4439a1ea2..e5e1029d48e 100644 --- a/winsup/cygwin/lib/getopt.c +++ b/winsup/cygwin/lib/getopt.c @@ -36,13 +36,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#include <sys/cdefs.h> - -/*#include "namespace.h"*/ - #include <assert.h> #include <errno.h> -/*#include <err.h>*/ #include <stdlib.h> #include <string.h> #include <getopt.h> @@ -92,9 +87,9 @@ extern char __declspec(dllimport) *__progname; #define EMSG "" -static int getopt_internal __P((int, char * const *, const char *)); -static int gcd __P((int, int)); -static void permute_args __P((int, int, int, char * const *)); +static int getopt_internal (int, char * const *, const char *); +static int gcd (int, int); +static void permute_args (int, int, int, char * const *); static const char *place = EMSG; /* option letter processing */ diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc index 0d8b80b5c33..b6aacb8245c 100644 --- a/winsup/cygwin/net.cc +++ b/winsup/cygwin/net.cc @@ -507,8 +507,8 @@ cygwin_getprotobynumber (int number) return protoent_buf; } -fhandler_socket * -fdsock (int &fd, const char *name, SOCKET soc) +bool +fdsock (cygheap_fdmanip& fd, const device *dev, SOCKET soc) { if (!winsock2_active) soc = set_socket_inheritance (soc); @@ -522,15 +522,15 @@ fdsock (int &fd, const char *name, SOCKET soc) else debug_printf ("not setting socket inheritance since winsock2_active %d", winsock2_active); - fhandler_socket *fh = (fhandler_socket *) build_fh_dev (*socket_dev, name); - if (!fh) - return NULL; - cygheap->fdtab[fd] = fh; - fh->set_io_handle ((HANDLE) soc); - fh->set_flags (O_RDWR | O_BINARY); - fh->set_r_no_interrupt (winsock2_active); - debug_printf ("fd %d, name '%s', soc %p", fd, name, soc); - return fh; + fd = build_fh_dev (*dev); + if (!fd.isopen ()) + return false; + fd->set_io_handle ((HANDLE) soc); + fd->set_flags (O_RDWR | O_BINARY); + fd->set_r_no_interrupt (winsock2_active); + cygheap->fdtab.inc_need_fixup_before (); + debug_printf ("fd %d, name '%s', soc %p", (int) fd, dev->name, soc); + return true; } /* exported as socket: standards? */ @@ -539,7 +539,6 @@ cygwin_socket (int af, int type, int protocol) { int res = -1; SOCKET soc = 0; - fhandler_socket *fh = NULL; debug_printf ("socket (%d, %d, %d)", af, type, protocol); @@ -551,25 +550,23 @@ cygwin_socket (int af, int type, int protocol) goto done; } - const char *name; + const device *dev; if (af == AF_INET) - name = (type == SOCK_STREAM ? "/dev/tcp" : "/dev/udp"); + dev = type == SOCK_STREAM ? tcp_dev : udp_dev; else - name = (type == SOCK_STREAM ? "/dev/streamsocket" : "/dev/dgsocket"); + dev = type == SOCK_STREAM ? stream_dev : dgram_dev; { cygheap_fdnew fd; - if (fd >= 0) - fh = fdsock (fd, name, soc); - if (fh) + if (fd < 0 || !fdsock (fd, dev, soc)) + closesocket (soc); + else { - fh->set_addr_family (af); - fh->set_socket_type (type); + ((fhandler_socket *) fd)->set_addr_family (af); + ((fhandler_socket *) fd)->set_socket_type (type); res = fd; } - else - closesocket (soc); } done: @@ -1911,12 +1908,9 @@ cygwin_rcmd (char **ahost, unsigned short inport, char *locuser, res = rcmd (ahost, inport, locuser, remuser, cmd, fd2p ? &fd2s : NULL); if (res != (int) INVALID_SOCKET) { - fhandler_socket *fh = NULL; cygheap_fdnew res_fd; - if (res_fd >= 0) - fh = fdsock (res_fd, "/dev/tcp", res); - if (fh) + if (res_fd >= 0 && fdsock (res_fd, tcp_dev, res)) res = res_fd; else { @@ -1927,11 +1921,9 @@ cygwin_rcmd (char **ahost, unsigned short inport, char *locuser, if (res >= 0 && fd2p) { cygheap_fdnew newfd (res_fd, false); + cygheap_fdget fd (*fd2p); - fh = NULL; - if (newfd >= 0) - fh = fdsock (*fd2p, "/dev/tcp", fd2s); - if (fh) + if (newfd >= 0 && fdsock (fd, tcp_dev, fd2s)) *fd2p = newfd; else { @@ -1961,12 +1953,9 @@ cygwin_rresvport (int *port) if (res != (int) INVALID_SOCKET) { - fhandler_socket *fh = NULL; cygheap_fdnew res_fd; - if (res_fd >= 0) - fh = fdsock (res_fd, "/dev/tcp", res); - if (fh) + if (res_fd >= 0 && fdsock (res_fd, tcp_dev, res)) res = res_fd; else res = -1; @@ -1995,12 +1984,9 @@ cygwin_rexec (char **ahost, unsigned short inport, char *locuser, res = rexec (ahost, inport, locuser, password, cmd, fd2p ? &fd2s : NULL); if (res != (int) INVALID_SOCKET) { - fhandler_socket *fh = NULL; cygheap_fdnew res_fd; - if (res_fd >= 0) - fh = fdsock (res_fd, "/dev/tcp", res); - if (fh) + if (res_fd >= 0 && fdsock (res_fd, tcp_dev, res)) res = res_fd; else { @@ -2011,11 +1997,9 @@ cygwin_rexec (char **ahost, unsigned short inport, char *locuser, if (res >= 0 && fd2p) { cygheap_fdnew newfd (res_fd, false); + cygheap_fdget fd (*fd2p); - fh = NULL; - if (newfd >= 0) - fh = fdsock (*fd2p, "/dev/tcp", fd2s); - if (fh) + if (newfd >= 0 && fdsock (fd, tcp_dev, fd2s)) *fd2p = newfd; else { @@ -2176,33 +2160,27 @@ socketpair (int family, int type, int protocol, int *sb) } { - fhandler_socket *fh = NULL; cygheap_fdnew sb0; - const char *name; + const device *dev; if (family == AF_INET) - name = (type == SOCK_STREAM ? "/dev/tcp" : "/dev/udp"); + dev = (type == SOCK_STREAM ? tcp_dev : udp_dev); else - name = (type == SOCK_STREAM ? "/dev/streamsocket" : "/dev/dgsocket"); + dev = (type == SOCK_STREAM ? stream_dev : dgram_dev); - if (sb0 >= 0) - fh = fdsock (sb0, name, insock); - if (fh) + if (sb0 >= 0 && fdsock (sb0, dev, insock)) { - fh->set_sun_path (""); - fh->set_addr_family (family); - fh->set_socket_type (type); + ((fhandler_socket *) sb0)->set_sun_path (""); + ((fhandler_socket *) sb0)->set_addr_family (family); + ((fhandler_socket *) sb0)->set_socket_type (type); cygheap_fdnew sb1 (sb0, false); - fh = NULL; - if (sb1 >= 0) - fh = fdsock (sb1, name, outsock); - if (fh) + if (sb1 >= 0 && fdsock (sb1, dev, outsock)) { - fh->set_sun_path (""); - fh->set_addr_family (family); - fh->set_socket_type (type); + ((fhandler_socket *) sb1)->set_sun_path (""); + ((fhandler_socket *) sb1)->set_addr_family (family); + ((fhandler_socket *) sb1)->set_socket_type (type); sb[0] = sb0; sb[1] = sb1; diff --git a/winsup/cygwin/select.cc b/winsup/cygwin/select.cc index 1a829984f78..e468144d7dc 100644 --- a/winsup/cygwin/select.cc +++ b/winsup/cygwin/select.cc @@ -337,7 +337,7 @@ set_bits (select_record *me, fd_set *readfds, fd_set *writefds, if (me->write_selected && me->write_ready) { UNIX_FD_SET (me->fd, writefds); - if (me->except_on_write && me->fh->get_device () == FH_SOCKET) + if (me->except_on_write && me->fh->is_socket ()) ((fhandler_socket *) me->fh)->set_connect_state (CONNECTED); ready++; } @@ -346,7 +346,7 @@ set_bits (select_record *me, fd_set *readfds, fd_set *writefds, if (me->except_on_write) /* Only on sockets */ { UNIX_FD_SET (me->fd, writefds); - if (me->fh->get_device () == FH_SOCKET) + if (me->fh->is_socket ()) ((fhandler_socket *) me->fh)->set_connect_state (CONNECTED); } if (me->except_selected) |