* fhandler_disk_file.cc (fhandler_disk_file::opendir): Check descriptor

created by cygheap_fdnew constructor.
	* fhandler_virtual.cc (fhandler_virtual::opendir): Ditto.
	* fhandler_socket.cc (fhandler_socket::accept): Ditto and move
	creation of file descriptor behind blocking OS call.
	* net.cc (cygwin_socket): Ditto.
	(cygwin_rcmd): Ditto.
	(cygwin_rresvport): Ditto.
	(cygwin_rexec): Ditto.
	(socketpair): Ditto.
This commit is contained in:
Corinna Vinschen 2003-02-20 14:14:37 +00:00
parent 1374b148ba
commit 518f5d4935
5 changed files with 200 additions and 162 deletions

View file

@ -1,3 +1,16 @@
2003-02-20 Corinna Vinschen <corinna@vinschen.de>
* fhandler_disk_file.cc (fhandler_disk_file::opendir): Check descriptor
created by cygheap_fdnew constructor.
* fhandler_virtual.cc (fhandler_virtual::opendir): Ditto.
* fhandler_socket.cc (fhandler_socket::accept): Ditto and move
creation of file descriptor behind blocking OS call.
* net.cc (cygwin_socket): Ditto.
(cygwin_rcmd): Ditto.
(cygwin_rresvport): Ditto.
(cygwin_rexec): Ditto.
(socketpair): Ditto.
2003-02-20 Corinna Vinschen <corinna@vinschen.de> 2003-02-20 Corinna Vinschen <corinna@vinschen.de>
* autoload.cc (GetCompressedFileSize): Add. * autoload.cc (GetCompressedFileSize): Add.

View file

@ -619,6 +619,8 @@ fhandler_disk_file::opendir (path_conv& real_name)
strcpy (dir->__d_dirname, real_name.get_win32 ()); strcpy (dir->__d_dirname, real_name.get_win32 ());
dir->__d_dirent->d_version = __DIRENT_VERSION; dir->__d_dirent->d_version = __DIRENT_VERSION;
cygheap_fdnew fd; cygheap_fdnew fd;
if (fd >= 0)
{
fd = this; fd = this;
fd->set_nohandle (true); fd->set_nohandle (true);
dir->__d_dirent->d_fd = fd; dir->__d_dirent->d_fd = fd;
@ -636,6 +638,7 @@ fhandler_disk_file::opendir (path_conv& real_name)
res = dir; res = dir;
} }
}
syscall_printf ("%p = opendir (%s)", res, get_name ()); syscall_printf ("%p = opendir (%s)", res, get_name ());
return res; return res;

View file

@ -484,7 +484,6 @@ fhandler_socket::accept (struct sockaddr *peer, int *len)
WSAEVENT ev[2] = { WSA_INVALID_EVENT, signal_arrived }; WSAEVENT ev[2] = { WSA_INVALID_EVENT, signal_arrived };
BOOL secret_check_failed = FALSE; BOOL secret_check_failed = FALSE;
BOOL in_progress = FALSE; BOOL in_progress = FALSE;
cygheap_fdnew res_fd;
/* Allows NULL peer and len parameters. */ /* Allows NULL peer and len parameters. */
struct sockaddr_in peer_dummy; struct sockaddr_in peer_dummy;
@ -593,13 +592,16 @@ fhandler_socket::accept (struct sockaddr *peer, int *len)
} }
} }
if (res_fd < 0) if ((SOCKET) res == (SOCKET) INVALID_SOCKET)
/* FIXME: what is correct errno? */;
else if ((SOCKET) res == (SOCKET) INVALID_SOCKET)
set_winsock_errno (); set_winsock_errno ();
else else
{ {
fhandler_socket* res_fh = fdsock (res_fd, get_name (), res); 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 (get_addr_family () == AF_LOCAL) if (get_addr_family () == AF_LOCAL)
res_fh->set_sun_path (get_sun_path ()); res_fh->set_sun_path (get_sun_path ());
res_fh->set_addr_family (get_addr_family ()); res_fh->set_addr_family (get_addr_family ());
@ -607,6 +609,12 @@ fhandler_socket::accept (struct sockaddr *peer, int *len)
res_fh->set_connect_state (CONNECTED); res_fh->set_connect_state (CONNECTED);
res = res_fd; res = res_fd;
} }
else
{
closesocket (res);
res = -1;
}
}
done: done:
if (ev[0] != WSA_INVALID_EVENT) if (ev[0] != WSA_INVALID_EVENT)

View file

@ -74,6 +74,8 @@ fhandler_virtual::opendir (path_conv& pc)
strcpy (dir->__d_dirname, get_name ()); strcpy (dir->__d_dirname, get_name ());
dir->__d_dirent->d_version = __DIRENT_VERSION; dir->__d_dirent->d_version = __DIRENT_VERSION;
cygheap_fdnew fd; cygheap_fdnew fd;
if (fd >= 0)
{
fd = this; fd = this;
fd->set_nohandle (true); fd->set_nohandle (true);
dir->__d_dirent->d_fd = fd; dir->__d_dirent->d_fd = fd;
@ -85,6 +87,7 @@ fhandler_virtual::opendir (path_conv& pc)
res = dir; res = dir;
} }
}
syscall_printf ("%p = opendir (%s)", res, get_name ()); syscall_printf ("%p = opendir (%s)", res, get_name ());
return res; return res;

View file

@ -540,10 +540,6 @@ cygwin_socket (int af, int type, int protocol)
SOCKET soc = 0; SOCKET soc = 0;
fhandler_socket *fh = NULL; fhandler_socket *fh = NULL;
cygheap_fdnew fd;
if (fd >= 0)
{
debug_printf ("socket (%d, %d, %d)", af, type, protocol); debug_printf ("socket (%d, %d, %d)", af, type, protocol);
soc = socket (AF_INET, type, af == AF_LOCAL ? 0 : protocol); soc = socket (AF_INET, type, af == AF_LOCAL ? 0 : protocol);
@ -561,18 +557,18 @@ cygwin_socket (int af, int type, int protocol)
else else
name = (type == SOCK_STREAM ? "/dev/streamsocket" : "/dev/dgsocket"); name = (type == SOCK_STREAM ? "/dev/streamsocket" : "/dev/dgsocket");
fh = fdsock (fd, name, soc);
if (!fh)
{ {
closesocket (soc); cygheap_fdnew fd;
res = -1; if (fd >= 0)
} fh = fdsock (fd, name, soc);
else if (fh)
{ {
fh->set_addr_family (af); fh->set_addr_family (af);
fh->set_socket_type (type); fh->set_socket_type (type);
res = fd; res = fd;
} }
else
closesocket (soc);
} }
done: done:
@ -1901,6 +1897,7 @@ cygwin_rcmd (char **ahost, unsigned short inport, char *locuser,
{ {
int res = -1; int res = -1;
SOCKET fd2s; SOCKET fd2s;
sig_dispatch_pending (0); sig_dispatch_pending (0);
sigframe thisframe (mainthread); sigframe thisframe (mainthread);
@ -1910,33 +1907,40 @@ cygwin_rcmd (char **ahost, unsigned short inport, char *locuser,
(remuser && check_null_str_errno (remuser))) (remuser && check_null_str_errno (remuser)))
return (int) INVALID_SOCKET; return (int) INVALID_SOCKET;
res = rcmd (ahost, inport, locuser, remuser, cmd, fd2p ? &fd2s : NULL);
if (res != (int) INVALID_SOCKET)
{
fhandler_socket *fh = NULL;
cygheap_fdnew res_fd; cygheap_fdnew res_fd;
if (res_fd < 0) if (res_fd >= 0)
goto done; fh = fdsock (res_fd, "/dev/tcp", res);
if (fh)
res = res_fd;
else
{
closesocket (res);
res = -1;
}
if (fd2p) if (res >= 0 && fd2p)
{ {
cygheap_fdnew newfd (res_fd, false); cygheap_fdnew newfd (res_fd, false);
if (*fd2p < 0) fh = NULL;
goto done; if (newfd >= 0)
fh = fdsock (*fd2p, "/dev/tcp", fd2s);
if (fh)
*fd2p = newfd; *fd2p = newfd;
}
res = rcmd (ahost, inport, locuser, remuser, cmd, fd2p ? &fd2s : NULL);
if (res == (int) INVALID_SOCKET)
goto done;
else else
{ {
fdsock (res_fd, "/dev/tcp", res); closesocket (res);
res = res_fd; closesocket (fd2s);
res = -1;
}
}
} }
if (fd2p)
fdsock (*fd2p, "/dev/tcp", fd2s);
done:
syscall_printf ("%d = rcmd (...)", res); syscall_printf ("%d = rcmd (...)", res);
return res; return res;
} }
@ -1952,19 +1956,19 @@ cygwin_rresvport (int *port)
if (check_null_invalid_struct_errno (port)) if (check_null_invalid_struct_errno (port))
return -1; return -1;
cygheap_fdnew res_fd;
if (res_fd < 0)
res = -1;
else
{
res = rresvport (port); res = rresvport (port);
if (res != (int) INVALID_SOCKET) if (res != (int) INVALID_SOCKET)
{ {
fdsock (res_fd, "/dev/tcp", res); fhandler_socket *fh = NULL;
cygheap_fdnew res_fd;
if (res_fd >= 0)
fh = fdsock (res_fd, "/dev/tcp", res);
if (fh)
res = res_fd; res = res_fd;
} else
res = -1;
} }
syscall_printf ("%d = rresvport (%d)", res, port ? *port : 0); syscall_printf ("%d = rresvport (%d)", res, port ? *port : 0);
@ -1987,30 +1991,40 @@ cygwin_rexec (char **ahost, unsigned short inport, char *locuser,
(password && check_null_str_errno (password))) (password && check_null_str_errno (password)))
return (int) INVALID_SOCKET; return (int) INVALID_SOCKET;
res = rexec (ahost, inport, locuser, password, cmd, fd2p ? &fd2s : NULL);
if (res != (int) INVALID_SOCKET)
{
fhandler_socket *fh = NULL;
cygheap_fdnew res_fd; cygheap_fdnew res_fd;
if (res_fd < 0) if (res_fd >= 0)
goto done; fh = fdsock (res_fd, "/dev/tcp", res);
if (fd2p) if (fh)
{ res = res_fd;
cygheap_fdnew newfd (res_fd);
if (newfd < 0)
goto done;
*fd2p = newfd;
}
res = rexec (ahost, inport, locuser, password, cmd, fd2p ? &fd2s : NULL);
if (res == (int) INVALID_SOCKET)
goto done;
else else
{ {
fdsock (res_fd, "/dev/tcp", res); closesocket (res);
res = res_fd; res = -1;
}
if (res >= 0 && fd2p)
{
cygheap_fdnew newfd (res_fd, false);
fh = NULL;
if (newfd >= 0)
fh = fdsock (*fd2p, "/dev/tcp", fd2s);
if (fh)
*fd2p = newfd;
else
{
closesocket (res);
closesocket (fd2s);
res = -1;
}
}
} }
if (fd2p)
fdsock (*fd2p, "/dev/tcp", fd2s);
done:
syscall_printf ("%d = rexec (...)", res); syscall_printf ("%d = rexec (...)", res);
return res; return res;
} }
@ -2024,8 +2038,6 @@ socketpair (int family, int type, int protocol, int *sb)
SOCKET insock, outsock, newsock; SOCKET insock, outsock, newsock;
struct sockaddr_in sock_in, sock_out; struct sockaddr_in sock_in, sock_out;
int len; int len;
cygheap_fdnew sb0;
fhandler_socket *fh;
sig_dispatch_pending (0); sig_dispatch_pending (0);
sigframe thisframe (mainthread); sigframe thisframe (mainthread);
@ -2049,19 +2061,6 @@ socketpair (int family, int type, int protocol, int *sb)
goto done; goto done;
} }
if (sb0 < 0)
goto done;
else
{
sb[0] = sb0;
cygheap_fdnew sb1 (sb0, false);
if (sb1 < 0)
goto done;
sb[1] = sb1;
}
/* create the first socket */ /* create the first socket */
newsock = socket (AF_INET, type, 0); newsock = socket (AF_INET, type, 0);
if (newsock == INVALID_SOCKET) if (newsock == INVALID_SOCKET)
@ -2175,34 +2174,46 @@ socketpair (int family, int type, int protocol, int *sb)
insock = newsock; insock = newsock;
} }
res = 0;
if (family == AF_LOCAL)
{ {
fhandler_socket *fh = NULL;
cygheap_fdnew sb0;
const char *name;
fh = fdsock (sb[0], if (family == AF_INET)
type == SOCK_STREAM ? "/dev/streamsocket" : "/dev/dgsocket", name = (type == SOCK_STREAM ? "/dev/tcp" : "/dev/udp");
insock);
fh->set_sun_path ("");
fh->set_addr_family (AF_LOCAL);
fh->set_socket_type (type);
fh = fdsock (sb[1],
type == SOCK_STREAM ? "/dev/streamsocket" : "/dev/dgsocket",
outsock);
fh->set_sun_path ("");
fh->set_addr_family (AF_LOCAL);
fh->set_socket_type (type);
}
else else
name = (type == SOCK_STREAM ? "/dev/streamsocket" : "/dev/dgsocket");
if (sb0 >= 0)
fh = fdsock (sb0, name, insock);
if (fh)
{ {
fh = fdsock (sb[0], type == SOCK_STREAM ? "/dev/tcp" : "/dev/udp", fh->set_sun_path ("");
insock); fh->set_addr_family (family);
fh->set_addr_family (AF_INET);
fh->set_socket_type (type); fh->set_socket_type (type);
fh = fdsock (sb[1], type == SOCK_STREAM ? "/dev/tcp" : "/dev/udp",
outsock); cygheap_fdnew sb1 (sb0, false);
fh->set_addr_family (AF_INET);
fh = NULL;
if (sb1 >= 0)
fh = fdsock (sb1, name, outsock);
if (fh)
{
fh->set_sun_path ("");
fh->set_addr_family (family);
fh->set_socket_type (type); fh->set_socket_type (type);
sb[0] = sb0;
sb[1] = sb1;
res = 0;
}
}
if (res == -1)
{
closesocket (insock);
closesocket (outsock);
}
} }
done: done: