* net.cc (set_socket_inheritance): Rename from duplicate_socket. Use NT
specific call when appropriate. (__set_winsock_errno): Rename from set_winsock_errno. Accept function and line as arguments. * path.cc (path_conv::check): Continue the neverending battle to make cygwin properly understand that path specs ending in a slash require that the path refer to a directory. Windows does not do this by default. (symlink_info::check): Remove ENOTDIR test. Move it to path_conv::check. * path.h: Remove obsolete constant. * winsup.h (set_winsock_errno): New macro.
This commit is contained in:
parent
d12eba25a5
commit
829425c9fd
@ -1,3 +1,18 @@
|
|||||||
|
Thu Oct 5 20:34:48 2000 Christopher Faylor <cgf@cygnus.com>
|
||||||
|
|
||||||
|
* net.cc (set_socket_inheritance): Rename from duplicate_socket. Use
|
||||||
|
NT specific call when appropriate.
|
||||||
|
(__set_winsock_errno): Rename from set_winsock_errno. Accept function
|
||||||
|
and line as arguments.
|
||||||
|
* path.cc (path_conv::check): Continue the neverending battle to make
|
||||||
|
cygwin properly understand that path specs ending in a slash require
|
||||||
|
that the path refer to a directory. Windows does not do this by
|
||||||
|
default.
|
||||||
|
(symlink_info::check): Remove ENOTDIR test. Move it to
|
||||||
|
path_conv::check.
|
||||||
|
* path.h: Remove obsolete constant.
|
||||||
|
* winsup.h (set_winsock_errno): New macro.
|
||||||
|
|
||||||
Thu Oct 5 14:58:00 2000 Corinna Vinschen <corinna@vinschen.de>
|
Thu Oct 5 14:58:00 2000 Corinna Vinschen <corinna@vinschen.de>
|
||||||
|
|
||||||
* fhandler.h: Add mmap(), munmap() and msync() to fhandler_base
|
* fhandler.h: Add mmap(), munmap() and msync() to fhandler_base
|
||||||
|
@ -45,24 +45,23 @@ int sscanf (const char *, const char *, ...);
|
|||||||
} /* End of "C" section */
|
} /* End of "C" section */
|
||||||
|
|
||||||
/* Cygwin internal */
|
/* Cygwin internal */
|
||||||
static SOCKET
|
static SOCKET __stdcall
|
||||||
duplicate_socket (SOCKET sock)
|
set_socket_inheritance (SOCKET sock)
|
||||||
{
|
{
|
||||||
/* Do not duplicate socket on Windows NT because of problems with
|
|
||||||
MS winsock proxy server.
|
|
||||||
*/
|
|
||||||
if (os_being_run == winNT)
|
if (os_being_run == winNT)
|
||||||
return sock;
|
(void) SetHandleInformation ((HANDLE) sock, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT);
|
||||||
|
|
||||||
SOCKET newsock;
|
|
||||||
if (DuplicateHandle (hMainProc, (HANDLE) sock, hMainProc, (HANDLE *) &newsock,
|
|
||||||
0, TRUE, DUPLICATE_SAME_ACCESS))
|
|
||||||
{
|
|
||||||
closesocket (sock);
|
|
||||||
sock = newsock;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
small_printf ("DuplicateHandle failed %E");
|
{
|
||||||
|
SOCKET newsock;
|
||||||
|
if (!DuplicateHandle (hMainProc, (HANDLE) sock, hMainProc, (HANDLE *) &newsock,
|
||||||
|
0, TRUE, DUPLICATE_SAME_ACCESS))
|
||||||
|
small_printf ("DuplicateHandle failed %E");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
closesocket (sock);
|
||||||
|
sock = newsock;
|
||||||
|
}
|
||||||
|
}
|
||||||
return sock;
|
return sock;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -233,7 +232,7 @@ static struct tl errmap[] =
|
|||||||
|
|
||||||
/* Cygwin internal */
|
/* Cygwin internal */
|
||||||
void
|
void
|
||||||
set_winsock_errno ()
|
__set_winsock_errno (const char *fn, int ln)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int why = WSAGetLastError ();
|
int why = WSAGetLastError ();
|
||||||
@ -243,12 +242,12 @@ set_winsock_errno ()
|
|||||||
|
|
||||||
if (errmap[i].w != 0)
|
if (errmap[i].w != 0)
|
||||||
{
|
{
|
||||||
syscall_printf ("%d (%s) -> %d", why, errmap[i].s, errmap[i].e);
|
syscall_printf ("%s:%d - %d (%s) -> %d", fn, ln, why, errmap[i].s, errmap[i].e);
|
||||||
set_errno (errmap[i].e);
|
set_errno (errmap[i].e);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
syscall_printf ("unknown error %d", why);
|
syscall_printf ("%s:%d - unknown error %d", fn, ln, why);
|
||||||
set_errno (EPERM);
|
set_errno (EPERM);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -337,7 +336,7 @@ cygwin_socket (int af, int type, int protocol)
|
|||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
soc = duplicate_socket (soc);
|
soc = set_socket_inheritance (soc);
|
||||||
|
|
||||||
const char *name;
|
const char *name;
|
||||||
if (af == AF_INET)
|
if (af == AF_INET)
|
||||||
@ -718,7 +717,7 @@ cygwin_accept (int fd, struct sockaddr *peer, int *len)
|
|||||||
set_winsock_errno ();
|
set_winsock_errno ();
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
res = duplicate_socket (res);
|
res = set_socket_inheritance (res);
|
||||||
|
|
||||||
fdsock (res_fd, sock->get_name (), res);
|
fdsock (res_fd, sock->get_name (), res);
|
||||||
res = res_fd;
|
res = res_fd;
|
||||||
@ -1553,14 +1552,14 @@ cygwin_rcmd (char **ahost, unsigned short inport, char *locuser,
|
|||||||
goto done;
|
goto done;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
res = duplicate_socket (res);
|
res = set_socket_inheritance (res);
|
||||||
|
|
||||||
fdsock (res_fd, "/dev/tcp", res);
|
fdsock (res_fd, "/dev/tcp", res);
|
||||||
res = res_fd;
|
res = res_fd;
|
||||||
}
|
}
|
||||||
if (fd2p)
|
if (fd2p)
|
||||||
{
|
{
|
||||||
fd2s = duplicate_socket (fd2s);
|
fd2s = set_socket_inheritance (fd2s);
|
||||||
|
|
||||||
fdsock (*fd2p, "/dev/tcp", fd2s);
|
fdsock (*fd2p, "/dev/tcp", fd2s);
|
||||||
}
|
}
|
||||||
@ -1585,7 +1584,7 @@ cygwin_rresvport (int *port)
|
|||||||
goto done;
|
goto done;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
res = duplicate_socket (res);
|
res = set_socket_inheritance (res);
|
||||||
|
|
||||||
fdsock (res_fd, "/dev/tcp", res);
|
fdsock (res_fd, "/dev/tcp", res);
|
||||||
res = res_fd;
|
res = res_fd;
|
||||||
@ -1618,14 +1617,14 @@ cygwin_rexec (char **ahost, unsigned short inport, char *locuser,
|
|||||||
goto done;
|
goto done;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
res = duplicate_socket (res);
|
res = set_socket_inheritance (res);
|
||||||
|
|
||||||
fdsock (res_fd, "/dev/tcp", res);
|
fdsock (res_fd, "/dev/tcp", res);
|
||||||
res = res_fd;
|
res = res_fd;
|
||||||
}
|
}
|
||||||
if (fd2p)
|
if (fd2p)
|
||||||
{
|
{
|
||||||
fd2s = duplicate_socket (fd2s);
|
fd2s = set_socket_inheritance (fd2s);
|
||||||
fdsock (*fd2p, "/dev/tcp", fd2s);
|
fdsock (*fd2p, "/dev/tcp", fd2s);
|
||||||
}
|
}
|
||||||
done:
|
done:
|
||||||
@ -1726,11 +1725,11 @@ socketpair (int, int type, int, int *sb)
|
|||||||
closesocket (newsock);
|
closesocket (newsock);
|
||||||
res = 0;
|
res = 0;
|
||||||
|
|
||||||
insock = duplicate_socket (insock);
|
insock = set_socket_inheritance (insock);
|
||||||
|
|
||||||
fdsock (sb[0], "/dev/tcp", insock);
|
fdsock (sb[0], "/dev/tcp", insock);
|
||||||
|
|
||||||
outsock = duplicate_socket (outsock);
|
outsock = set_socket_inheritance (outsock);
|
||||||
fdsock (sb[1], "/dev/tcp", outsock);
|
fdsock (sb[1], "/dev/tcp", outsock);
|
||||||
|
|
||||||
done:
|
done:
|
||||||
|
@ -168,6 +168,7 @@ path_conv::check (const char *src, unsigned opt,
|
|||||||
char path_copy[MAX_PATH];
|
char path_copy[MAX_PATH];
|
||||||
char tmp_buf[MAX_PATH];
|
char tmp_buf[MAX_PATH];
|
||||||
symlink_info sym;
|
symlink_info sym;
|
||||||
|
bool need_directory = 0;
|
||||||
|
|
||||||
char *rel_path, *full_path;
|
char *rel_path, *full_path;
|
||||||
|
|
||||||
@ -189,16 +190,15 @@ path_conv::check (const char *src, unsigned opt,
|
|||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
MALLOC_CHECK;
|
MALLOC_CHECK;
|
||||||
DWORD need_directory = 0;
|
|
||||||
char *p = strrchr (src, '/');
|
char *p = strrchr (src, '/');
|
||||||
if (p)
|
if (p)
|
||||||
{
|
{
|
||||||
if (strcmp (p, "/") == 0 || strcmp (p, "/.") == 0)
|
if (p[1] == '\0' || strcmp (p, "/.") == 0)
|
||||||
need_directory = PATH_NEEDDIR;
|
need_directory = 1;
|
||||||
}
|
}
|
||||||
else if ((p = strrchr (src, '\\')) &&
|
else if ((p = strrchr (src, '\\')) &&
|
||||||
(strcmp (p, "\\") == 0 || strcmp (p, "\\.") == 0))
|
(p[1] == '\0' || strcmp (p, "\\.") == 0))
|
||||||
need_directory = PATH_NEEDDIR;
|
need_directory = 1;
|
||||||
/* Must look up path in mount table, etc. */
|
/* Must look up path in mount table, etc. */
|
||||||
error = cygwin_shared->mount.conv_to_win32_path (src, rel_path,
|
error = cygwin_shared->mount.conv_to_win32_path (src, rel_path,
|
||||||
full_path,
|
full_path,
|
||||||
@ -285,7 +285,7 @@ path_conv::check (const char *src, unsigned opt,
|
|||||||
these operations again on the newly derived path. */
|
these operations again on the newly derived path. */
|
||||||
else if (len > 0)
|
else if (len > 0)
|
||||||
{
|
{
|
||||||
if (component == 0 && !(opt & PC_SYM_FOLLOW))
|
if (component == 0 && !need_directory && !(opt & PC_SYM_FOLLOW))
|
||||||
{
|
{
|
||||||
set_symlink (); // last component of path is a symlink.
|
set_symlink (); // last component of path is a symlink.
|
||||||
fileattr = sym.fileattr;
|
fileattr = sym.fileattr;
|
||||||
@ -363,6 +363,18 @@ fillin:
|
|||||||
}
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
/* Deal with Windows stupidity which considers filename\. to be valid
|
||||||
|
even when "filename" is not a directory. */
|
||||||
|
if (!need_directory || error)
|
||||||
|
/* nothing to do */;
|
||||||
|
else if (fileattr & FILE_ATTRIBUTE_DIRECTORY)
|
||||||
|
path_flags &= ~PATH_SYMLINK;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
debug_printf ("%s is a non-directory", path);
|
||||||
|
error = ENOTDIR;
|
||||||
|
return;
|
||||||
|
}
|
||||||
DWORD serial, volflags;
|
DWORD serial, volflags;
|
||||||
|
|
||||||
strcpy (tmp_buf, full_path);
|
strcpy (tmp_buf, full_path);
|
||||||
@ -2187,7 +2199,6 @@ symlink_info::check (const char *in_path, const suffix_info *suffixes)
|
|||||||
HANDLE h;
|
HANDLE h;
|
||||||
int res = 0;
|
int res = 0;
|
||||||
char extbuf[MAX_PATH + 5];
|
char extbuf[MAX_PATH + 5];
|
||||||
int needdir;
|
|
||||||
const char *path = in_path;
|
const char *path = in_path;
|
||||||
|
|
||||||
if (!suffixes)
|
if (!suffixes)
|
||||||
@ -2206,13 +2217,6 @@ symlink_info::check (const char *in_path, const suffix_info *suffixes)
|
|||||||
is_symlink = TRUE;
|
is_symlink = TRUE;
|
||||||
|
|
||||||
error = 0;
|
error = 0;
|
||||||
if (!(pflags & PATH_NEEDDIR))
|
|
||||||
needdir = 0;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
pflags &= ~PATH_NEEDDIR;
|
|
||||||
needdir = 1;
|
|
||||||
}
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (!next_suffix (ext_here, suffixes))
|
if (!next_suffix (ext_here, suffixes))
|
||||||
@ -2229,22 +2233,6 @@ symlink_info::check (const char *in_path, const suffix_info *suffixes)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Windows allows path\. even when `path' isn't a directory.
|
|
||||||
Detect this scenario and disallow it, since it is non-UNIX like.
|
|
||||||
FIXME: This code actually checks for things like foo/ and foo/..
|
|
||||||
even though those usages have already been (erroneously?) eaten
|
|
||||||
by cygwin_shared->mount.conv_to_win32_path in path_conv::check. */
|
|
||||||
|
|
||||||
char *p = strrchr (path, '\\');
|
|
||||||
if (p && !(fileattr & FILE_ATTRIBUTE_DIRECTORY) &&
|
|
||||||
(needdir || *++p == '\0' ||
|
|
||||||
(*p == '.' && (*++p == '\0' || (*p == '.' && p[1] == '\0')))))
|
|
||||||
{
|
|
||||||
debug_printf ("%s is a non-directory", path);
|
|
||||||
error = ENOTDIR;
|
|
||||||
goto file_not_symlink;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* A symlink will have the `system' file attribute. */
|
/* A symlink will have the `system' file attribute. */
|
||||||
/* Only files can be symlinks (which can be symlinks to directories). */
|
/* Only files can be symlinks (which can be symlinks to directories). */
|
||||||
if (!(pflags & PATH_SYMLINK) && !SYMLINKATTR (fileattr))
|
if (!(pflags & PATH_SYMLINK) && !SYMLINKATTR (fileattr))
|
||||||
|
@ -36,7 +36,6 @@ enum path_types
|
|||||||
PATH_BINARY = MOUNT_BINARY,
|
PATH_BINARY = MOUNT_BINARY,
|
||||||
PATH_EXEC = MOUNT_EXEC,
|
PATH_EXEC = MOUNT_EXEC,
|
||||||
PATH_CYGWIN_EXEC = MOUNT_CYGWIN_EXEC,
|
PATH_CYGWIN_EXEC = MOUNT_CYGWIN_EXEC,
|
||||||
PATH_NEEDDIR = 0x20000000,
|
|
||||||
PATH_SOCKET = 0x40000000,
|
PATH_SOCKET = 0x40000000,
|
||||||
PATH_HASACLS = 0x80000000
|
PATH_HASACLS = 0x80000000
|
||||||
};
|
};
|
||||||
|
@ -201,7 +201,8 @@ long __stdcall to_time_t (FILETIME * ptr);
|
|||||||
void __stdcall set_console_title (char *);
|
void __stdcall set_console_title (char *);
|
||||||
void set_console_handler ();
|
void set_console_handler ();
|
||||||
|
|
||||||
void set_winsock_errno ();
|
#define set_winsock_errno() __set_winsock_errno (__FUNCTION__, __LINE__)
|
||||||
|
void __set_winsock_errno (const char *fn, int ln);
|
||||||
|
|
||||||
/* Printf type functions */
|
/* Printf type functions */
|
||||||
extern "C" void __api_fatal (const char *, ...) __attribute__ ((noreturn));
|
extern "C" void __api_fatal (const char *, ...) __attribute__ ((noreturn));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user