* 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.
+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.
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;
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;
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)
{
}
int
-fhandler_disk_file::open (const char *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)
+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;
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.");
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,
/* 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 *);
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);
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);
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);
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; }
/* 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 ();
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); }
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);
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 ();
{
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);
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);
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);
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);
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 *);
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 *);
{
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;
}
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;
}
int
-fhandler_console::open (const char *, int flags, mode_t)
+fhandler_console::open (path_conv *, int flags, mode_t)
{
HANDLE h;
{
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;
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 */
/* 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 ())
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 ())
}
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)
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");
}
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.
* 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
}
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 ())
{
}
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 ();
}
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)
}
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;
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;
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;
}
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;
/* 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]);
}
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)
}
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);
}
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 ();
*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;
}
int pid = vf->pid;
vf->pid = 0;
+ debug_printf ("exiting vfork, pid %d", pid);
sig_dispatch_pending ();
return pid;
#endif
#endif
}
-#define deveq(s) (strcasematch (name, (s)))
-#define deveqn(s, n) (strncasematch (name, (s), (n)))
-
static __inline int
digits (const char *name)
{
"\\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;
+ int devn = FH_BAD;
+ 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;
- if (strncasematch (w32path, "\\\\.\\tape", 8))
+ 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))
{
- devn = FH_TAPE;
- unit = digits (w32path + 8);
+ unit = digits (w32_path + 4);
// norewind tape devices have leading n in name
- if (strncasematch (uxname, "/dev/n", 6))
+ if (udeveqn ("/dev/n", 6))
unit += 128;
+ devn = FH_TAPE;
}
- else if (isdrive (w32path + 4))
+ else if (isdrive (w32_path))
{
+ unit = cyg_tolower (w32_path[0]) - 'a';
devn = FH_FLOPPY;
- unit = cyg_tolower (w32path[4]) - 'a';
}
- else if (strncasematch (w32path, "\\\\.\\physicaldrive", 17))
+ else if (wdeveqn ("physicaldrive", 17))
{
+ unit = digits (w32_path + 13) + 128;
devn = FH_FLOPPY;
- unit = digits (w32path + 17) + 128;
}
+ else
+ devn = FH_BAD;
return devn;
}
-int __stdcall
-get_device_number (const char *name, int &unit, BOOL from_conv)
+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 ((*name == '/' && deveqn ("/dev/", 5)) ||
- (*name == '\\' && deveqn ("\\dev\\", 5)))
- {
- 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);
- }
- else if (deveqn ("com", 3) && (unit = digits (name + 3)) >= 0)
- devn = FH_SERIAL;
- else if (deveqn ("ttyS", 4) && (unit = digits (name + 4)) >= 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;
}
{
const char *devfmt;
- devn = get_device_number (src_path, unit, TRUE);
+ devn = get_device_number (src_path, "", unit);
if (devn == FH_BAD)
return FALSE;
*flags = mi->flags;
}
+ devn = get_device_number (src_path, dst, unit);
+
out:
MALLOC_CHECK;
if (chroot_ok || cygheap->root.ischroot_native (dst))
/* 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=",
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
{
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))
{
&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);
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);
}
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;
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
{
/* 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)
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);
}
}