* dtable.h (dtable::build_fhandler): Make path_conv parameter non-optional.

(dtable::init_std_file_from_handle): Eliminate name parameter.
* dtable.cc (stdio_init): Don't pass bogus name to init_std_file_from_handle.
The function will figure out the name itself.
(dtable::init_std_file_from_handle): Eliminate name parameter.  Assume that
we're always called with an appropriate fd.  Pass name as NULL if we can't
simply figure it out from context.
(cygwin_attach_handle_to_fd): Pass path_conv argument to build_fhandler.
(dtable::build_fhandler): Make path_conv argument mandatory.  Eliminate
specific call to get_device_number.  With unknown device names, set name from
handle context for parsing by path_conv.
(dtable::build_fhandler): Pass path_conv argument to build_fhandler.
* path.h (path_conv::set_isdisk): Set disk device type.
(path_conv::is_device): Don't consider FH_DISK a "device".
* syscalls.cc (_open): Pass path_conv argument by reference.
(stat_worker): Ditto.
(_rename): Use path_conv operators.  Add bounds to DeleteFile/MoveFile for
loop.
This commit is contained in:
Christopher Faylor 2001-10-02 01:58:06 +00:00
parent 47af76d8c8
commit 4ab6034f50
6 changed files with 103 additions and 88 deletions

View File

@ -1,3 +1,27 @@
Mon Oct 1 16:52:23 2001 Christopher Faylor <cgf@cygnus.com>
* dtable.h (dtable::build_fhandler): Make path_conv parameter
non-optional.
(dtable::init_std_file_from_handle): Eliminate name parameter.
* dtable.cc (stdio_init): Don't pass bogus name to
init_std_file_from_handle. The function will figure out the name
itself.
(dtable::init_std_file_from_handle): Eliminate name parameter. Assume
that we're always called with an appropriate fd. Pass name as NULL if
we can't simply figure it out from context.
(cygwin_attach_handle_to_fd): Pass path_conv argument to
build_fhandler.
(dtable::build_fhandler): Make path_conv argument mandatory. Eliminate
specific call to get_device_number. With unknown device names, set
name from handle context for parsing by path_conv.
(dtable::build_fhandler): Pass path_conv argument to build_fhandler.
* path.h (path_conv::set_isdisk): Set disk device type.
(path_conv::is_device): Don't consider FH_DISK a "device".
* syscalls.cc (_open): Pass path_conv argument by reference.
(stat_worker): Ditto.
(_rename): Use path_conv operators. Add bounds to DeleteFile/MoveFile
for loop.
Mon Oct 1 14:25:00 2001 Charles Wilson <cwilson@ece.gatech.edu>
* cygwin.din: export strtoll and strtoull

View File

@ -833,7 +833,12 @@ _dll_crt0 ()
if (_cygwin_testing)
fork_info = NULL;
else if ((fork_info->type & PROC_MAGIC_MASK) == PROC_MAGIC_GENERIC)
api_fatal ("conflicting versions of cygwin1.dll detected. Use only the most recent version.\n");
api_fatal ("\
You have multiple copies of cygwin1.dll on your system.\n\
Search for cygwin1.dll using the Windows Start->Find/Search facility\n\
and delete all but the most recent version. This will probably be\n\
the one that resides in x:\\cygwin\\bin, where 'x' is the drive on which\n\
you have installed the cygwin distribution.\n");
break;
}
}

View File

@ -106,7 +106,7 @@ stdio_init (void)
HANDLE out = GetStdHandle (STD_OUTPUT_HANDLE);
HANDLE err = GetStdHandle (STD_ERROR_HANDLE);
cygheap->fdtab.init_std_file_from_handle (0, in, GENERIC_READ, "{stdin}");
cygheap->fdtab.init_std_file_from_handle (0, in, GENERIC_READ);
/* STD_ERROR_HANDLE has been observed to be the same as
STD_OUTPUT_HANDLE. We need separate handles (e.g. using pipes
@ -124,8 +124,8 @@ stdio_init (void)
}
}
cygheap->fdtab.init_std_file_from_handle (1, out, GENERIC_WRITE, "{stdout}");
cygheap->fdtab.init_std_file_from_handle (2, err, GENERIC_WRITE, "{stderr}");
cygheap->fdtab.init_std_file_from_handle (1, out, GENERIC_WRITE);
cygheap->fdtab.init_std_file_from_handle (2, err, GENERIC_WRITE);
/* Assign the console as the controlling tty for this process if we actually
have a console and no other controlling tty has been assigned. */
if (myself->ctty < 0 && GetConsoleCP () > 0)
@ -170,48 +170,48 @@ dtable::release (int fd)
void
dtable::init_std_file_from_handle (int fd, HANDLE handle,
DWORD myaccess, const char *name)
DWORD myaccess)
{
int bin;
const char *name = NULL;
if (__fmode)
bin = __fmode;
else
bin = binmode ?: 0;
/* Check to see if we're being redirected - if not then
we open then as consoles */
if (fd == 0 || fd == 1 || fd == 2)
{
first_fd_for_open = 0;
/* See if we can consoleify it - if it is a console,
don't open it in binary. That will screw up our crlfs*/
CONSOLE_SCREEN_BUFFER_INFO buf;
if (GetConsoleScreenBufferInfo (handle, &buf))
{
bin = 0;
if (ISSTATE (myself, PID_USETTY))
name = "/dev/tty";
else
name = "/dev/conout";
bin = 0;
}
else if (FlushConsoleInputBuffer (handle))
{
bin = 0;
if (ISSTATE (myself, PID_USETTY))
name = "/dev/tty";
else
name = "/dev/conin";
bin = 0;
}
else if (GetFileType (handle) == FILE_TYPE_PIPE)
{
if (fd == 0)
name = "/dev/piper";
else if (fd == 1 || fd == 2)
name = "/dev/pipew";
if (bin == 0)
bin = O_BINARY;
}
}
path_conv pc;
build_fhandler (fd, name, handle, &pc)->init (handle, myaccess, bin);
build_fhandler (fd, name, handle, pc)->init (handle, myaccess, bin);
set_std_handle (fd);
paranoid_printf ("fd %d, handle %p", fd, handle);
}
@ -223,59 +223,46 @@ cygwin_attach_handle_to_fd (char *name, int fd, HANDLE handle, mode_t bin,
{
if (fd == -1)
fd = cygheap->fdtab.find_unused_handle ();
fhandler_base *res = cygheap->fdtab.build_fhandler (fd, name, handle);
path_conv pc;
fhandler_base *res = cygheap->fdtab.build_fhandler (fd, name, handle, pc);
res->init (handle, myaccess, bin);
return fd;
}
fhandler_base *
dtable::build_fhandler (int fd, const char *name, HANDLE handle, path_conv *pc,
dtable::build_fhandler (int fd, const char *name, HANDLE handle, path_conv& pc,
unsigned opt, suffix_info *si)
{
int unit;
DWORD devn;
fhandler_base *fh;
if (!pc)
devn = get_device_number (name, unit);
else
{
pc->check (name, opt | PC_NULLEMPTY, si);
if (pc->error)
{
set_errno (pc->error);
return NULL;
}
devn = pc->get_devn ();
unit = pc->get_unitn ();
}
if (devn == FH_BAD)
if (!name && handle)
{
struct sockaddr sa;
int sal = sizeof (sa);
CONSOLE_SCREEN_BUFFER_INFO cinfo;
DCB dcb;
if (handle == NULL)
devn = FH_DISK;
else if (GetNumberOfConsoleInputEvents (handle, (DWORD *) &cinfo))
devn = FH_CONIN;
if (GetNumberOfConsoleInputEvents (handle, (DWORD *) &cinfo))
name = "/dev/conin";
else if (GetConsoleScreenBufferInfo (handle, &cinfo))
devn= FH_CONOUT;
name = "/dev/conout";
else if (wsock_started && getpeername ((SOCKET) handle, &sa, &sal) == 0)
devn = FH_SOCKET;
name = "/dev/socket";
else if (GetFileType (handle) == FILE_TYPE_PIPE)
devn = FH_PIPE;
name = "/dev/pipe";
else if (GetCommState (handle, &dcb))
devn = FH_SERIAL;
name = "/dev/ttyS0"; // FIXME - determine correct device
else
devn = FH_DISK;
name = "some disk file";
}
fh = build_fhandler (fd, devn, name, unit);
if (pc)
fh->set_name (name, *pc, unit);
pc.check (name, opt | PC_NULLEMPTY, si);
if (pc.error)
{
set_errno (pc.error);
return NULL;
}
fhandler_base *fh = build_fhandler (fd, pc.get_devn (), name, pc.get_unitn ());
fh->set_name (name, pc, pc.get_unitn ());
return fh;
}
@ -348,8 +335,11 @@ dtable::build_fhandler (int fd, DWORD dev, const char *name, int unit)
fh = new (buf) fhandler_dev_dsp (name);
break;
default:
{
/* FIXME - this could recurse forever */
return build_fhandler (fd, name, NULL);
path_conv pc;
return build_fhandler (fd, name, NULL, pc);
}
}
debug_printf ("%s - cb %d, fd %d, fh %p", fh->get_name () ?: "", fh->cb,

View File

@ -50,9 +50,9 @@ public:
void fixup_after_fork (HANDLE);
fhandler_base *build_fhandler (int fd, DWORD dev, const char *name,
int unit = -1);
fhandler_base *build_fhandler (int fd, const char *name, HANDLE h = NULL,
path_conv *pc = NULL,
unsigned opts = PC_SYM_FOLLOW, suffix_info *si = NULL);
fhandler_base *build_fhandler (int fd, const char *name, HANDLE h,
path_conv& pc, unsigned opts = PC_SYM_FOLLOW,
suffix_info *si = NULL);
inline int not_open (int fd)
{
SetResourceLock (LOCK_FD_LIST, READ_LOCK, "not_open");
@ -66,7 +66,7 @@ public:
int find_unused_handle (int start);
int find_unused_handle () { return find_unused_handle (first_fd_for_open);}
void release (int fd);
void init_std_file_from_handle (int fd, HANDLE handle, DWORD access, const char *name);
void init_std_file_from_handle (int fd, HANDLE handle, DWORD access);
int dup2 (int oldfd, int newfd);
void fixup_after_exec (HANDLE);
inline fhandler_base *operator [](int fd) const { return fds[fd]; }

View File

@ -104,7 +104,7 @@ class path_conv
void set_binary () {path_flags |= PATH_BINARY;}
void set_symlink () {path_flags |= PATH_SYMLINK;}
void set_has_symlinks () {path_flags |= PATH_HAS_SYMLINKS;}
void set_isdisk () {path_flags |= PATH_ISDISK;}
void set_isdisk () {path_flags |= PATH_ISDISK; devn = FH_DISK;}
void set_exec (int x = 1) {path_flags |= x ? PATH_EXEC : PATH_NOTEXEC;}
void set_has_acls (int x = 1) {path_flags |= x ? PATH_HASACLS : PATH_NOTHING;}
void set_has_buggy_open (int x = 1) {path_flags |= x ? PATH_HASBUGGYOPEN : PATH_NOTHING;}
@ -130,7 +130,7 @@ class path_conv
operator char *() {return path; }
operator DWORD &() {return fileattr; }
operator int &() {return (int) fileattr; }
BOOL is_device () {return devn != FH_BAD;}
BOOL is_device () {return devn != FH_BAD && devn != FH_DISK;}
DWORD get_devn () {return devn == FH_BAD ? (DWORD) FH_DISK : devn;}
short get_unitn () {return devn == FH_BAD ? 0 : unit;}
DWORD file_attributes () {return fileattr;}

View File

@ -499,7 +499,7 @@ _open (const char *unix_path, int flags, ...)
else
{
path_conv pc;
if (!(fh = cygheap->fdtab.build_fhandler (fd, unix_path, NULL, &pc)))
if (!(fh = cygheap->fdtab.build_fhandler (fd, unix_path, NULL, pc)))
res = -1; // errno already set
else if (!fh->open (pc, flags, (mode & 07777) & ~cygheap->umask))
{
@ -1087,7 +1087,7 @@ stat_worker (const char *caller, const char *name, struct stat *buf,
if (check_null_invalid_struct_errno (buf))
goto done;
fh = cygheap->fdtab.build_fhandler (-1, name, NULL, &real_path,
fh = cygheap->fdtab.build_fhandler (-1, name, NULL, real_path,
(nofollow ? PC_SYM_NOFOLLOW : PC_SYM_FOLLOW)
| PC_FULL, stat_suffixes);
@ -1327,8 +1327,7 @@ _rename (const char *oldpath, const char *newpath)
return -1;
}
if (!writable_directory (real_old.get_win32 ())
|| !writable_directory (real_new.get_win32 ()))
if (!writable_directory (real_old) || !writable_directory (real_new))
{
syscall_printf ("-1 = rename (%s, %s)", oldpath, newpath);
set_errno (EACCES);
@ -1353,7 +1352,7 @@ _rename (const char *oldpath, const char *newpath)
(lnk_suffix = strrchr (real_new.get_win32 (), '.')))
*lnk_suffix = '\0';
if (!MoveFile (real_old.get_win32 (), real_new.get_win32 ()))
if (!MoveFile (real_old, real_new))
res = -1;
if (res == 0 || (GetLastError () != ERROR_ALREADY_EXISTS
@ -1369,7 +1368,7 @@ _rename (const char *oldpath, const char *newpath)
else
{
syscall_printf ("try win95 hack");
for (;;)
for (int i = 0; i < 2; i++)
{
if (!DeleteFileA (real_new.get_win32 ()) &&
GetLastError () != ERROR_FILE_NOT_FOUND)
@ -1378,16 +1377,13 @@ _rename (const char *oldpath, const char *newpath)
real_new.get_win32 ());
break;
}
else
{
if (MoveFile (real_old.get_win32 (), real_new.get_win32 ()))
else if (MoveFile (real_old.get_win32 (), real_new.get_win32 ()))
{
res = 0;
break;
}
}
}
}
done:
if (res)