* dcrt0.cc (dll_crt0_1): Don't close hexec_proc if it is NULL.

* fork.cc (vfork): Add debugging statements.
* path.cc (get_device_number): Make static.  Rewrite to inspect both unix and
windows paths.
(get_raw_device_number): Just check for parts of raw device that we care about.
(get_devn): New function, pulled from get_device_number.
(win32_device_name): Accomodate arg changes to get_device_number.
(mount_info::get_device_number): Call get_device_number on translated Windows
path.
* spawn.cc (spawn_guts): Don't treat P_VFORK differently from P_NOWAIT.  Add
handle to child's shared region to child so that it will be preserved if the
parent goes away.
* fhandler.h: Throughout, simplify to one open method for all fhandler classes,
requiring a path_conv first element.
* fhandler.cc (fhandler_base::open): Remove obsolete method.  Generalize to
require path_conv * as first argument.
(fhandler_disk_file::open): Remove obsolete method.
(fhandler_disk_file::open): Use path_conv pointer rather than reference.
* fhandler_clipboard.cc (fhandler_dev_clipboard::dup): Use new open method.
(fhandler_dev_clipboard::open): Accomodate new argument for open methods.
* fhandler_console.cc (fhandler_console::open): Ditto.
(fhandler_console::dup): Use new open method.
(fhandler_console::fixup_after_fork): Ditto.
(fhandler_console::fixup_after_exec): Ditto.
* fhandler_dsp.cc (fhandler_dev_dsp::open): Accomodate new argument for open
methods.
* fhandler_floppy.cc (fhandler_dev_floppy::open): Ditto.
* fhandler_mem.cc (fhandler_dev_mem::open): Ditto.
* fhandler_random (fhandler_dev_random::open): Ditto.
* fhandler_raw.cc (fhandler_dev_raw::open): Ditto.
* fhandler_serial.cc (fhandler_serial::open): Ditto.
* fhandler_tape.cc (fhandler_dev_tape::open): Ditto.
* fhandler_tty.cc (fhandler_tty_slave::open): Ditto.
(fhandler_pty_master::open): Ditto.
* fhandler_windows.cc (fhandler_windows::open): Ditto.
* fhandler_zero.cc (fhandler_dev_zero::open): Ditto.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Accomodate new
argument for open methods.
* syscalls.cc (_open): Ditto.
(stat_worker): Ditto.
This commit is contained in:
Christopher Faylor 2001-10-04 02:34:20 +00:00
parent 34d2d03975
commit 8af0f81d52
22 changed files with 236 additions and 215 deletions

View File

@ -1,3 +1,53 @@
Wed Oct 3 19:40:36 2001 Christopher Faylor <cgf@cygnus.com>
* dcrt0.cc (dll_crt0_1): Don't close hexec_proc if it is NULL.
* fork.cc (vfork): Add debugging statements.
* path.cc (get_device_number): Make static. Rewrite to inspect both unix
and windows paths.
(get_raw_device_number): Just check for parts of raw device that we
care about.
(get_devn): New function, pulled from get_device_number.
(win32_device_name): Accomodate arg changes to get_device_number.
(mount_info::get_device_number): Call get_device_number on translated
Windows path.
* spawn.cc (spawn_guts): Don't treat P_VFORK differently from P_NOWAIT.
Add handle to child's shared region to child so that it will be
preserved if the parent goes away.
* fhandler.h: Throughout, simplify to one open method for all fhandler
classes, requiring a path_conv first element.
* fhandler.cc (fhandler_base::open): Remove obsolete method.
Generalize to require path_conv * as first argument.
(fhandler_disk_file::open): Remove obsolete method.
(fhandler_disk_file::open): Use path_conv pointer rather than
reference.
* fhandler_clipboard.cc (fhandler_dev_clipboard::dup): Use new open
method.
(fhandler_dev_clipboard::open): Accomodate new argument for open
methods.
* fhandler_console.cc (fhandler_console::open): Ditto.
(fhandler_console::dup): Use new open method.
(fhandler_console::fixup_after_fork): Ditto.
(fhandler_console::fixup_after_exec): Ditto.
* fhandler_dsp.cc (fhandler_dev_dsp::open): Accomodate new argument for
open methods.
* fhandler_floppy.cc (fhandler_dev_floppy::open): Ditto.
* fhandler_mem.cc (fhandler_dev_mem::open): Ditto.
* fhandler_random (fhandler_dev_random::open): Ditto.
* fhandler_raw.cc (fhandler_dev_raw::open): Ditto.
* fhandler_serial.cc (fhandler_serial::open): Ditto.
* fhandler_tape.cc (fhandler_dev_tape::open): Ditto.
* fhandler_tty.cc (fhandler_tty_slave::open): Ditto.
(fhandler_pty_master::open): Ditto.
* fhandler_windows.cc (fhandler_windows::open): Ditto.
* fhandler_zero.cc (fhandler_dev_zero::open): Ditto.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Accomodate
new argument for open methods.
* syscalls.cc (_open): Ditto.
(stat_worker): Ditto.
Tue Oct 2 23:49:18 2001 Christopher Faylor <cgf@cygnus.com>
* cygheap.cc (cfree): Remove malloc debugging probe.

View File

@ -598,7 +598,8 @@ dll_crt0_1 ()
ProtectHandle (child_proc_info->forker_finished);
break;
case PROC_SPAWN:
CloseHandle (spawn_info->hexec_proc);
if (spawn_info->hexec_proc)
CloseHandle (spawn_info->hexec_proc);
goto around;
case PROC_EXEC:
hexec_proc = spawn_info->hexec_proc;

View File

@ -305,16 +305,9 @@ fhandler_base::get_default_fmode (int flags)
return __fmode;
}
/* Open system call handler function. */
int
fhandler_base::open (path_conv& real_path, int flags, mode_t mode)
{
return open ((char *) real_path, flags, mode);
}
/* Open system call handler function.
Path is now already checked for symlinks */
int
fhandler_base::open (int flags, mode_t mode)
fhandler_base::open (path_conv *, int flags, mode_t mode)
{
int res = 0;
HANDLE x;
@ -392,15 +385,12 @@ fhandler_base::open (int flags, mode_t mode)
if (flags & O_CREAT && get_device () == FH_DISK && allow_ntsec && has_acls ())
set_security_attribute (mode, &sa, alloca (4096), 4096);
x = CreateFileA (get_win32_name (), access, shared,
&sa, creation_distribution,
file_attributes,
0);
x = CreateFile (get_win32_name (), access, shared, &sa, creation_distribution,
file_attributes, 0);
syscall_printf ("%p = CreateFileA (%s, %p, %p, %p, %p, %p, 0)",
x, get_win32_name (), access, shared,
&sa, creation_distribution,
file_attributes);
x, get_win32_name (), access, shared, &sa,
creation_distribution, file_attributes);
if (x == INVALID_HANDLE_VALUE)
{
@ -1231,44 +1221,21 @@ fhandler_disk_file::fhandler_disk_file (const char *name) :
}
int
fhandler_disk_file::open (const char *path, int flags, mode_t mode)
fhandler_disk_file::open (path_conv *real_path, int flags, mode_t mode)
{
syscall_printf ("(%s, %p)", path, flags);
/* O_NOSYMLINK is an internal flag for implementing lstat, nothing more. */
path_conv real_path (path, (flags & O_NOSYMLINK) ?
PC_SYM_NOFOLLOW : PC_SYM_FOLLOW);
if (real_path.error &&
(flags & O_NOSYMLINK || real_path.error != ENOENT
|| !(flags & O_CREAT) || real_path.case_clash))
{
set_errno (flags & O_CREAT && real_path.case_clash ? ECASECLASH
: real_path.error);
syscall_printf ("0 = fhandler_disk_file::open (%s, %p)", path, flags);
return 0;
}
set_name (path, real_path.get_win32 ());
return open (real_path, flags, mode);
}
int
fhandler_disk_file::open (path_conv& real_path, int flags, mode_t mode)
{
if (real_path.isbinary ())
if (real_path->isbinary ())
{
set_r_binary (1);
set_w_binary (1);
}
set_has_acls (real_path.has_acls ());
set_isremote (real_path.isremote ());
set_has_acls (real_path->has_acls ());
set_isremote (real_path->isremote ());
if (real_path.isdir ())
if (real_path->isdir ())
flags |= O_DIROPEN;
int res = this->fhandler_base::open (flags, mode);
int res = this->fhandler_base::open (real_path, flags, mode);
if (!res)
goto out;
@ -1279,7 +1246,7 @@ fhandler_disk_file::open (path_conv& real_path, int flags, mode_t mode)
The only known file system to date is the SUN NFS Solstice Client 3.1
which returns a valid handle when trying to open a file in a nonexistent
directory. */
if (real_path.has_buggy_open ()
if (real_path->has_buggy_open ()
&& GetFileAttributes (win32_path_name) == (DWORD) -1)
{
debug_printf ("Buggy open detected.");
@ -1291,9 +1258,9 @@ fhandler_disk_file::open (path_conv& real_path, int flags, mode_t mode)
if (flags & O_APPEND)
SetFilePointer (get_handle(), 0, 0, FILE_END);
set_symlink_p (real_path.issymlink ());
set_execable_p (real_path.exec_state ());
set_socket_p (real_path.issocket ());
set_symlink_p (real_path->issymlink ());
set_execable_p (real_path->exec_state ());
set_socket_p (real_path->issocket ());
out:
syscall_printf ("%d = fhandler_disk_file::open (%s, %p)", res,

View File

@ -311,13 +311,7 @@ public:
/* fixup fd possibly non-inherited handles after fork */
void fork_fixup (HANDLE parent, HANDLE &h, const char *name);
/* Potentially overridden virtual functions. */
virtual int open (const char *, int flags, mode_t mode = 0)
{
return open (flags, mode);
}
virtual int open (path_conv& real_path, int flags, mode_t mode);
virtual int open (int flags, mode_t mode = 0);
virtual int open (path_conv * real_path, int flags, mode_t mode = 0);
virtual int close ();
virtual int fstat (struct stat *buf) { return stat_dev (get_device (), get_unit (), get_namehash (), buf); }
virtual int ioctl (unsigned int cmd, void *);
@ -481,7 +475,7 @@ protected:
public:
~fhandler_dev_raw (void);
int open (const char *path, int flags, mode_t mode = 0);
int open (path_conv *, int flags, mode_t mode = 0);
int close (void);
int raw_read (void *ptr, size_t ulen);
@ -506,7 +500,7 @@ protected:
public:
fhandler_dev_floppy (const char *name, int unit);
virtual int open (const char *path, int flags, mode_t mode = 0);
virtual int open (path_conv *, int flags, mode_t mode = 0);
virtual int close (void);
virtual off_t lseek (off_t offset, int whence);
@ -528,7 +522,7 @@ protected:
public:
fhandler_dev_tape (const char *name, int unit);
virtual int open (const char *path, int flags, mode_t mode = 0);
virtual int open (path_conv *, int flags, mode_t mode = 0);
virtual int close (void);
virtual off_t lseek (off_t offset, int whence);
@ -559,8 +553,7 @@ class fhandler_disk_file: public fhandler_base
public:
fhandler_disk_file (const char *name);
int open (const char *path, int flags, mode_t mode = 0);
int open (path_conv& real_path, int flags, mode_t mode);
int open (path_conv * real_path, int flags, mode_t mode);
int close ();
int lock (int, struct flock *);
BOOL is_device () { return FALSE; }
@ -587,7 +580,7 @@ public:
/* Constructor */
fhandler_serial (const char *name, DWORD devtype = FH_SERIAL, int unit = 0);
int open (const char *path, int flags, mode_t mode);
int open (path_conv *, int flags, mode_t mode);
int close ();
void init (HANDLE h, DWORD a, mode_t flags);
void overlapped_setup ();
@ -750,7 +743,7 @@ public:
fhandler_console* is_console () { return this; }
int open (const char *path, int flags, mode_t mode = 0);
int open (path_conv *, int flags, mode_t mode = 0);
int write (const void *ptr, size_t len);
void doecho (const void *str, DWORD len) { (void) write (str, len); }
@ -823,7 +816,7 @@ public:
fhandler_tty_slave (const char *name);
fhandler_tty_slave (int, const char *name);
int open (const char *path, int flags, mode_t mode = 0);
int open (path_conv *, int flags, mode_t mode = 0);
int write (const void *ptr, size_t len);
int read (void *ptr, size_t len);
void init (HANDLE, DWORD, mode_t);
@ -850,7 +843,7 @@ public:
int process_slave_output (char *buf, size_t len, int pktmode_on);
void doecho (const void *str, DWORD len);
int accept_input ();
int open (const char *path, int flags, mode_t mode = 0);
int open (path_conv *, int flags, mode_t mode = 0);
int write (const void *ptr, size_t len);
int read (void *ptr, size_t len);
int close ();
@ -896,7 +889,7 @@ class fhandler_dev_zero: public fhandler_base
{
public:
fhandler_dev_zero (const char *name);
int open (const char *path, int flags, mode_t mode = 0);
int open (path_conv *, int flags, mode_t mode = 0);
int write (const void *ptr, size_t len);
int read (void *ptr, size_t len);
off_t lseek (off_t offset, int whence);
@ -919,7 +912,7 @@ protected:
public:
fhandler_dev_random (const char *name, int unit);
int get_unit () { return unit; }
int open (const char *path, int flags, mode_t mode = 0);
int open (path_conv *, int flags, mode_t mode = 0);
int write (const void *ptr, size_t len);
int read (void *ptr, size_t len);
off_t lseek (off_t offset, int whence);
@ -940,7 +933,7 @@ public:
fhandler_dev_mem (const char *name, int unit);
~fhandler_dev_mem (void);
int open (const char *path, int flags, mode_t mode = 0);
int open (path_conv *, int flags, mode_t mode = 0);
int write (const void *ptr, size_t ulen);
int read (void *ptr, size_t ulen);
off_t lseek (off_t offset, int whence);
@ -962,7 +955,7 @@ class fhandler_dev_clipboard: public fhandler_base
public:
fhandler_dev_clipboard (const char *name);
int is_windows (void) { return 1; }
int open (const char *path, int flags, mode_t mode = 0);
int open (path_conv *, int flags, mode_t mode = 0);
int write (const void *ptr, size_t len);
int read (void *ptr, size_t len);
off_t lseek (off_t offset, int whence);
@ -987,7 +980,7 @@ private:
public:
fhandler_windows (const char *name = 0);
int is_windows (void) { return 1; }
int open (const char *path, int flags, mode_t mode = 0);
int open (path_conv *, int flags, mode_t mode = 0);
int write (const void *ptr, size_t len);
int read (void *ptr, size_t len);
int ioctl (unsigned int cmd, void *);
@ -1014,7 +1007,7 @@ public:
fhandler_dev_dsp (const char *name = 0);
~fhandler_dev_dsp();
int open (const char *path, int flags, mode_t mode = 0);
int open (path_conv *, int flags, mode_t mode = 0);
int write (const void *ptr, size_t len);
int read (void *ptr, size_t len);
int ioctl (unsigned int cmd, void *);

View File

@ -56,7 +56,7 @@ fhandler_dev_clipboard::dup (fhandler_base * child)
{
fhandler_dev_clipboard *fhc = (fhandler_dev_clipboard *) child;
if (!fhc->open (get_name (), get_flags (), 0))
if (!fhc->open (NULL, get_flags (), 0))
system_printf ("error opening clipboard, %E");
fhc->membuffer = membuffer;
@ -67,7 +67,7 @@ fhandler_dev_clipboard::dup (fhandler_base * child)
}
int
fhandler_dev_clipboard::open (const char *, int flags, mode_t)
fhandler_dev_clipboard::open (path_conv *, int flags, mode_t)
{
set_flags (flags);
eof = false;

View File

@ -542,7 +542,7 @@ fhandler_console::scroll_screen (int x1, int y1, int x2, int y2, int xn, int yn)
}
int
fhandler_console::open (const char *, int flags, mode_t)
fhandler_console::open (path_conv *, int flags, mode_t)
{
HANDLE h;
@ -617,7 +617,7 @@ fhandler_console::dup (fhandler_base *child)
{
fhandler_console *fhc = (fhandler_console *) child;
if (!fhc->open (get_name (), get_flags () & ~O_NOCTTY, 0))
if (!fhc->open (NULL, get_flags () & ~O_NOCTTY, 0))
system_printf ("error opening console, %E");
fhc->default_color = default_color;
@ -1723,7 +1723,7 @@ fhandler_console::init (HANDLE f, DWORD a, mode_t bin)
mode = O_WRONLY;
if (a == (GENERIC_READ | GENERIC_WRITE))
mode = O_RDWR;
open (0, mode);
open ((path_conv *) NULL, mode);
if (f != INVALID_HANDLE_VALUE)
CloseHandle (f); /* Reopened by open */
@ -1752,7 +1752,7 @@ fhandler_console::fixup_after_fork (HANDLE)
/* Windows does not allow duplication of console handles between processes
so open the console explicitly. */
if (!open (get_name (), O_NOCTTY | get_flags (), 0))
if (!open (NULL, O_NOCTTY | get_flags (), 0))
system_printf ("error opening console after fork, %E");
if (!get_close_on_exec ())
@ -1782,7 +1782,7 @@ fhandler_console::fixup_after_exec (HANDLE)
HANDLE h = get_handle ();
HANDLE oh = get_output_handle ();
if (!open (get_name (), O_NOCTTY | get_flags (), 0))
if (!open (NULL, O_NOCTTY | get_flags (), 0))
{
int sawerr = 0;
if (!get_io_handle ())

View File

@ -431,7 +431,7 @@ fhandler_dev_dsp::~fhandler_dev_dsp ()
}
int
fhandler_dev_dsp::open (const char *path, int flags, mode_t mode = 0)
fhandler_dev_dsp::open (path_conv *, int flags, mode_t mode = 0)
{
// currently we only support writing
if ((flags & (O_WRONLY | O_RDONLY | O_RDWR)) != O_WRONLY)
@ -443,14 +443,11 @@ fhandler_dev_dsp::open (const char *path, int flags, mode_t mode = 0)
s_audio = new (audio_buf) Audio;
// Work out initial sample format & frequency
if (strcmp (path, "/dev/dsp") == 0L)
{
// dev/dsp defaults
audioformat_ = AFMT_S8;
audiofreq_ = 8000;
audiobits_ = 8;
audiochannels_ = 1;
}
audioformat_ = AFMT_S8;
audiofreq_ = 8000;
audiobits_ = 8;
audiochannels_ = 1;
if (!s_audio->open (audiofreq_, audiobits_, audiochannels_))
debug_printf ("/dev/dsp: failed to open\n");

View File

@ -46,7 +46,7 @@ fhandler_dev_floppy::fhandler_dev_floppy (const char *name, int unit) : fhandler
}
int
fhandler_dev_floppy::open (const char *path, int flags, mode_t)
fhandler_dev_floppy::open (path_conv *real_path, int flags, mode_t)
{
/* The correct size of the buffer would be 512 bytes,
* which is the atomic size, supported by WinNT.
@ -61,7 +61,7 @@ fhandler_dev_floppy::open (const char *path, int flags, mode_t)
* and cpio buffer sizes by default!
*/
devbufsiz = 61440L; /* 512L; */
return fhandler_dev_raw::open (path, flags);
return fhandler_dev_raw::open (real_path, flags);
}
int

View File

@ -72,7 +72,7 @@ fhandler_dev_mem::~fhandler_dev_mem (void)
}
int
fhandler_dev_mem::open (const char *, int flags, mode_t)
fhandler_dev_mem::open (path_conv *, int flags, mode_t)
{
if (!wincap.has_physical_mem_access ())
{

View File

@ -32,7 +32,7 @@ fhandler_dev_random::fhandler_dev_random (const char *name, int nunit)
}
int
fhandler_dev_random::open (const char *, int flags, mode_t)
fhandler_dev_random::open (path_conv *, int flags, mode_t)
{
set_flags (flags);
set_open_status ();

View File

@ -131,17 +131,14 @@ fhandler_dev_raw::~fhandler_dev_raw (void)
}
int
fhandler_dev_raw::open (const char *path, int flags, mode_t)
fhandler_dev_raw::open (path_conv *, int flags, mode_t)
{
path_conv real_path (path, PC_SYM_IGNORE);
int ret;
set_name (path, real_path.get_win32 ());
/* Always open a raw device existing and binary. */
flags &= ~(O_CREAT | O_TRUNC);
flags |= O_BINARY;
ret = fhandler_base::open (path, flags);
ret = fhandler_base::open (NULL, flags);
if (ret)
{
if (devbufsiz > 1L)

View File

@ -212,7 +212,7 @@ fhandler_serial::init (HANDLE f, DWORD flags, mode_t bin)
}
int
fhandler_serial::open (const char *name, int flags, mode_t mode)
fhandler_serial::open (path_conv *, int flags, mode_t mode)
{
int res;
COMMTIMEOUTS to;
@ -221,7 +221,7 @@ fhandler_serial::open (const char *name, int flags, mode_t mode)
syscall_printf ("fhandler_serial::open (%s, %p, %p)",
get_name (), flags, mode);
if (name && !(res = this->fhandler_base::open (flags, mode)))
if (!(res = this->fhandler_base::open (NULL, flags, mode)))
return 0;
else
res = 1;

View File

@ -66,7 +66,7 @@ fhandler_socket::set_connect_secret ()
ENTROPY_SOURCE_DEV_UNIT);
}
if (entropy_source &&
!entropy_source->open (ENTROPY_SOURCE_NAME, O_RDONLY))
!entropy_source->open (NULL, O_RDONLY))
{
delete entropy_source;
entropy_source = NULL;

View File

@ -61,28 +61,21 @@ fhandler_dev_tape::fhandler_dev_tape (const char *name, int unit) : fhandler_dev
}
int
fhandler_dev_tape::open (const char *path, int flags, mode_t)
fhandler_dev_tape::open (path_conv *real_path, int flags, mode_t)
{
int ret;
int minor;
if (get_device_number (path, minor) != FH_TAPE)
{
set_errno (EINVAL);
return -1;
}
norewind = (minor >= 128);
norewind = (real_path->get_unitn () >= 128);
devbufsiz = 1L;
ret = fhandler_dev_raw::open (path, flags);
ret = fhandler_dev_raw::open (real_path, flags);
if (ret)
{
struct mtget get;
struct mtop op;
struct mtpos pos;
if (! ioctl (MTIOCGET, &get))
if (!ioctl (MTIOCGET, &get))
/* Tape drive supports and is set to variable block size. */
if (get.mt_dsreg == 0)
devbufsiz = get.mt_maxblksize;

View File

@ -456,7 +456,7 @@ fhandler_tty_slave::fhandler_tty_slave (const char *name) :
/* FIXME: This function needs to close handles when it has
a failing condition. */
int
fhandler_tty_slave::open (const char *, int flags, mode_t)
fhandler_tty_slave::open (path_conv *, int flags, mode_t)
{
tcinit (cygwin_shared->tty[ttynum]);
@ -961,7 +961,7 @@ fhandler_pty_master::fhandler_pty_master (const char *name, DWORD devtype, int u
}
int
fhandler_pty_master::open (const char *, int flags, mode_t)
fhandler_pty_master::open (path_conv *, int flags, mode_t)
{
ttynum = cygwin_shared->tty.allocate_tty (0);
if (ttynum < 0)

View File

@ -55,7 +55,7 @@ fhandler_windows::fhandler_windows (const char *name) :
}
int
fhandler_windows::open (const char *, int flags, mode_t)
fhandler_windows::open (path_conv *, int flags, mode_t)
{
set_flags (flags);
set_close_on_exec_flag (1);

View File

@ -22,7 +22,7 @@ fhandler_dev_zero::fhandler_dev_zero (const char *name)
}
int
fhandler_dev_zero::open (const char *, int flags, mode_t)
fhandler_dev_zero::open (path_conv *, int flags, mode_t)
{
set_flags (flags);
set_open_status ();

View File

@ -721,6 +721,7 @@ vfork ()
*pp = *esp;
int res = cygheap->fdtab.vfork_child_dup () ? 0 : -1;
debug_printf ("%d = vfork()", res);
debug_printf ("exiting vfork, res %d", res);
return res;
}
@ -743,6 +744,7 @@ vfork ()
int pid = vf->pid;
vf->pid = 0;
debug_printf ("exiting vfork, pid %d", pid);
sig_dispatch_pending ();
return pid;
#endif

View File

@ -728,9 +728,6 @@ out:
#endif
}
#define deveq(s) (strcasematch (name, (s)))
#define deveqn(s, n) (strncasematch (name, (s), (n)))
static __inline int
digits (const char *name)
{
@ -769,106 +766,122 @@ const char *windows_device_names[] NO_COPY =
"\\dev\\dsp"
};
static int
get_raw_device_number (const char *uxname, const char *w32path, int &unit)
#define deveq(s) (strcasematch (name, (s)))
#define deveqn(s, n) (strncasematch (name, (s), (n)))
#define wdeveq(s) (strcasematch (w32_path, (s)))
#define wdeveqn(s, n) (strncasematch (w32_path, (s), (n)))
#define udeveq(s) (strcasematch (unix_path, (s)))
#define udeveqn(s, n) (strncasematch (unix_path, (s), (n)))
static int __stdcall
get_devn (const char *name, int &unit)
{
DWORD devn = FH_BAD;
if (strncasematch (w32path, "\\\\.\\tape", 8))
int devn = FH_BAD;
name += 5;
if (deveq ("tty"))
{
devn = FH_TAPE;
unit = digits (w32path + 8);
// norewind tape devices have leading n in name
if (strncasematch (uxname, "/dev/n", 6))
unit += 128;
if (real_tty_attached (myself))
{
unit = myself->ctty;
devn = FH_TTYS;
}
else if (myself->ctty > 0)
devn = FH_CONSOLE;
}
else if (isdrive (w32path + 4))
else if (deveqn ("tty", 3) && (unit = digits (name + 3)) >= 0)
devn = FH_TTYS;
else if (deveq ("ttym"))
devn = FH_TTYM;
else if (deveq ("ptmx"))
devn = FH_PTYM;
else if (deveq ("windows"))
devn = FH_WINDOWS;
else if (deveq ("dsp"))
devn = FH_OSS_DSP;
else if (deveq ("conin"))
devn = FH_CONIN;
else if (deveq ("conout"))
devn = FH_CONOUT;
else if (deveq ("null"))
devn = FH_NULL;
else if (deveq ("zero"))
devn = FH_ZERO;
else if (deveq ("random") || deveq ("urandom"))
{
devn = FH_FLOPPY;
unit = cyg_tolower (w32path[4]) - 'a';
devn = FH_RANDOM;
unit = 8 + (deveqn ("u", 1) ? 1 : 0); /* Keep unit Linux conformant */
}
else if (strncasematch (w32path, "\\\\.\\physicaldrive", 17))
else if (deveq ("mem"))
{
devn = FH_FLOPPY;
unit = digits (w32path + 17) + 128;
devn = FH_MEM;
unit = 1;
}
return devn;
}
int __stdcall
get_device_number (const char *name, int &unit, BOOL from_conv)
{
DWORD devn = FH_BAD;
unit = 0;
if ((*name == '/' && deveqn ("/dev/", 5)) ||
(*name == '\\' && deveqn ("\\dev\\", 5)))
else if (deveq ("clipboard"))
devn = FH_CLIPBOARD;
else if (deveq ("port"))
{
name += 5;
if (deveq ("tty"))
{
if (real_tty_attached (myself))
{
unit = myself->ctty;
devn = FH_TTYS;
}
else if (myself->ctty > 0)
devn = FH_CONSOLE;
}
else if (deveqn ("tty", 3) && (unit = digits (name + 3)) >= 0)
devn = FH_TTYS;
else if (deveq ("ttym"))
devn = FH_TTYM;
else if (deveq ("ptmx"))
devn = FH_PTYM;
else if (deveq ("windows"))
devn = FH_WINDOWS;
else if (deveq ("dsp"))
devn = FH_OSS_DSP;
else if (deveq ("conin"))
devn = FH_CONIN;
else if (deveq ("conout"))
devn = FH_CONOUT;
else if (deveq ("null"))
devn = FH_NULL;
else if (deveq ("zero"))
devn = FH_ZERO;
else if (deveq ("random") || deveq ("urandom"))
{
devn = FH_RANDOM;
unit = 8 + (deveqn ("u", 1) ? 1 : 0); /* Keep unit Linux conformant */
}
else if (deveq ("mem"))
{
devn = FH_MEM;
unit = 1;
}
else if (deveq ("clipboard"))
devn = FH_CLIPBOARD;
else if (deveq ("port"))
{
devn = FH_MEM;
unit = 4;
}
else if (deveqn ("com", 3) && (unit = digits (name + 3)) >= 0)
devn = FH_SERIAL;
else if (deveqn ("ttyS", 4) && (unit = digits (name + 4)) >= 0)
devn = FH_SERIAL;
else if (deveq ("pipe") || deveq ("piper") || deveq ("pipew"))
devn = FH_PIPE;
else if (deveq ("tcp") || deveq ("udp") || deveq ("streamsocket")
|| deveq ("dgsocket"))
devn = FH_SOCKET;
else if (!from_conv)
devn = get_raw_device_number (name - 5,
path_conv (name - 5,
PC_SYM_IGNORE).get_win32 (),
unit);
devn = FH_MEM;
unit = 4;
}
else if (deveqn ("com", 3) && (unit = digits (name + 3)) >= 0)
devn = FH_SERIAL;
else if (deveqn ("ttyS", 4) && (unit = digits (name + 4)) >= 0)
devn = FH_SERIAL;
else if (deveq ("pipe") || deveq ("piper") || deveq ("pipew"))
devn = FH_PIPE;
else if (deveq ("tcp") || deveq ("udp") || deveq ("streamsocket")
|| deveq ("dgsocket"))
devn = FH_SOCKET;
return devn;
}
static int
get_raw_device_number (const char *unix_path, const char *w32_path, int &unit)
{
int devn;
w32_path += 4;
if (wdeveqn ("tape", 8))
{
unit = digits (w32_path + 4);
// norewind tape devices have leading n in name
if (udeveqn ("/dev/n", 6))
unit += 128;
devn = FH_TAPE;
}
else if (isdrive (w32_path))
{
unit = cyg_tolower (w32_path[0]) - 'a';
devn = FH_FLOPPY;
}
else if (wdeveqn ("physicaldrive", 17))
{
unit = digits (w32_path + 13) + 128;
devn = FH_FLOPPY;
}
else
devn = FH_BAD;
return devn;
}
static int __stdcall get_device_number (const char *unix_path,
const char *w32_path, int &unit)
__attribute__ ((regparm(3)));
static int __stdcall
get_device_number (const char *unix_path, const char *w32_path, int &unit)
{
DWORD devn = FH_BAD;
unit = 0;
if (*unix_path == '/' && udeveqn ("/dev/", 5))
devn = get_devn (unix_path, unit);
if (devn == FH_BAD && *w32_path == '\\' && wdeveqn ("\\dev\\", 5))
devn = get_devn (w32_path, unit);
if (devn == FH_BAD && udeveqn ("com", 3)
&& (unit = digits (unix_path + 3)) >= 0)
devn = FH_SERIAL;
else if (strncmp (w32_path, "\\\\.\\", 4) == 0)
devn = get_raw_device_number (unix_path, w32_path, unit);
return devn;
}
@ -882,7 +895,7 @@ win32_device_name (const char *src_path, char *win32_path,
{
const char *devfmt;
devn = get_device_number (src_path, unit, TRUE);
devn = get_device_number (src_path, "", unit);
if (devn == FH_BAD)
return FALSE;
@ -1298,6 +1311,8 @@ mount_info::conv_to_win32_path (const char *src_path, char *dst,
*flags = mi->flags;
}
devn = get_device_number (src_path, dst, unit);
out:
MALLOC_CHECK;
if (chroot_ok || cygheap->root.ischroot_native (dst))

View File

@ -148,8 +148,6 @@ class path_conv
/* Maximum depth of symlinks (after which ELOOP is issued). */
#define MAX_LINK_DEPTH 10
int __stdcall get_device_number (const char *name, int &unit, BOOL from_conv = FALSE) __attribute__ ((regparm(3)));
int __stdcall slash_unc_prefix_p (const char *path) __attribute__ ((regparm(1)));
const char * __stdcall find_exec (const char *name, path_conv& buf, const char *winenv = "PATH=",

View File

@ -322,13 +322,13 @@ spawn_guts (HANDLE hToken, const char * prog_arg, const char *const *argv,
si.cbReserved2 = sizeof (ciresrv);
DWORD chtype;
if (mode != _P_OVERLAY && mode != _P_VFORK)
if (mode != _P_OVERLAY)
chtype = PROC_SPAWN;
else
chtype = PROC_EXEC;
HANDLE spr;
if (mode != _P_OVERLAY)
if (chtype != PROC_EXEC)
spr = NULL;
else
{
@ -336,7 +336,8 @@ spawn_guts (HANDLE hToken, const char * prog_arg, const char *const *argv,
ProtectHandle (spr);
}
init_child_info (chtype, &ciresrv, (mode == _P_OVERLAY) ? myself->pid : 1, spr);
init_child_info (chtype, &ciresrv, (mode == _P_OVERLAY) ? myself->pid : 1,
spr);
if (!DuplicateHandle (hMainProc, hMainProc, hMainProc, &ciresrv.parent, 0, 1,
DUPLICATE_SAME_ACCESS))
{
@ -674,7 +675,7 @@ spawn_guts (HANDLE hToken, const char * prog_arg, const char *const *argv,
&pi);
/* Restore impersonation. In case of _P_OVERLAY this isn't
allowed since it would overwrite child data. */
if (mode != _P_OVERLAY && mode != _P_VFORK
if (mode != _P_OVERLAY
&& cygheap->user.impersonated
&& cygheap->user.token != INVALID_HANDLE_VALUE)
ImpersonateLoggedOnUser (cygheap->user.token);
@ -746,6 +747,13 @@ spawn_guts (HANDLE hToken, const char * prog_arg, const char *const *argv,
child->hProcess = pi.hProcess;
child.remember ();
strcpy (child->progname, real_path);
/* FIXME: This introduces an unreferenced, open handle into the child.
The purpose is to keep the pid shared memory open so that all of
the fields filled out by child.remember do not disappear and so there
is not a brief period during which the pid is not available.
However, we should try to find another way to do this eventually. */
(void) DuplicateHandle (hMainProc, child.shared_handle (), pi.hProcess,
NULL, 0, 0, DUPLICATE_SAME_ACCESS);
/* Start the child running */
ResumeThread (pi.hThread);
}

View File

@ -501,7 +501,7 @@ _open (const char *unix_path, int flags, ...)
if (!(fh = cygheap->fdtab.build_fhandler_from_name (fd, unix_path,
NULL, pc)))
res = -1; // errno already set
else if (!fh->open (pc, flags, (mode & 07777) & ~cygheap->umask))
else if (!fh->open (&pc, flags, (mode & 07777) & ~cygheap->umask))
{
cygheap->fdtab.release (fd);
res = -1;
@ -1107,7 +1107,7 @@ stat_worker (const char *caller, const char *name, struct stat *buf,
debug_printf ("%d = file_attributes for '%s'", (DWORD) real_path,
(char *) real_path);
if ((oret = fh->open (real_path, open_flags, 0)))
if ((oret = fh->open (&real_path, open_flags, 0)))
/* ok */;
else
{
@ -1115,7 +1115,7 @@ stat_worker (const char *caller, const char *name, struct stat *buf,
/* If we couldn't open the file, try a "query open" with no permissions.
This will allow us to determine *some* things about the file, at least. */
fh->set_query_open (TRUE);
if ((oret = fh->open (real_path, open_flags, 0)))
if ((oret = fh->open (&real_path, open_flags, 0)))
/* ok */;
else if (allow_ntsec && real_path.has_acls () && get_errno () == EACCES
&& !get_file_attribute (TRUE, real_path, &ntsec_atts, &uid, &gid)
@ -1127,7 +1127,7 @@ stat_worker (const char *caller, const char *name, struct stat *buf,
in a failing open call in the same process. Check that
case. */
set_file_attribute (TRUE, real_path, 0400);
oret = fh->open (real_path, open_flags, 0);
oret = fh->open (&real_path, open_flags, 0);
set_file_attribute (TRUE, real_path, ntsec_atts);
}
}