* fhandler.cc (fhandler_base::read): Remove unused signal state tweaks.
* fhandler.h (fhandler_pipe::create_selectable): Declare. (fhandler_fifo::close_one_end): Declare. * fhandler_fifo.cc (fhandler_fifo::close_one_end): Define. (fhandler_fifo::open_not_mine): Use close_one_end to close appropriate end of pipe. * pinfo.cc (_pinfo::commune_recv): Ditto. * pipe.cc (fhandler_pipe::create_selectable): Rename from create_selectable_pipe. Reorganize. (fhandler_pipe::create): Use create_selectable.
This commit is contained in:
parent
b13aa00489
commit
fb201f9270
|
@ -1,3 +1,16 @@
|
||||||
|
2005-04-22 Christopher Faylor <cgf@timesys.com>
|
||||||
|
|
||||||
|
* fhandler.cc (fhandler_base::read): Remove unused signal state tweaks.
|
||||||
|
* fhandler.h (fhandler_pipe::create_selectable): Declare.
|
||||||
|
(fhandler_fifo::close_one_end): Declare.
|
||||||
|
* fhandler_fifo.cc (fhandler_fifo::close_one_end): Define.
|
||||||
|
(fhandler_fifo::open_not_mine): Use close_one_end to close appropriate
|
||||||
|
end of pipe.
|
||||||
|
* pinfo.cc (_pinfo::commune_recv): Ditto.
|
||||||
|
* pipe.cc (fhandler_pipe::create_selectable): Rename from
|
||||||
|
create_selectable_pipe. Reorganize.
|
||||||
|
(fhandler_pipe::create): Use create_selectable.
|
||||||
|
|
||||||
2005-04-21 Christopher Faylor <cgf@timesys.com>
|
2005-04-21 Christopher Faylor <cgf@timesys.com>
|
||||||
|
|
||||||
* shared.cc (shared_info::initialize): Test previous version of shared
|
* shared.cc (shared_info::initialize): Test previous version of shared
|
||||||
|
|
|
@ -699,7 +699,6 @@ fhandler_base::read (void *in_ptr, size_t& len)
|
||||||
{
|
{
|
||||||
char *ptr = (char *) in_ptr;
|
char *ptr = (char *) in_ptr;
|
||||||
ssize_t copied_chars = 0;
|
ssize_t copied_chars = 0;
|
||||||
bool need_signal = !!read_state;
|
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
while (len)
|
while (len)
|
||||||
|
@ -723,7 +722,6 @@ fhandler_base::read (void *in_ptr, size_t& len)
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
need_signal = false;
|
|
||||||
raw_read (ptr + copied_chars, len);
|
raw_read (ptr + copied_chars, len);
|
||||||
if (!copied_chars)
|
if (!copied_chars)
|
||||||
/* nothing */;
|
/* nothing */;
|
||||||
|
@ -792,9 +790,6 @@ fhandler_base::read (void *in_ptr, size_t& len)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
out:
|
out:
|
||||||
if (need_signal)
|
|
||||||
signal_read_state (2);
|
|
||||||
|
|
||||||
debug_printf ("returning %d, %s mode", len, rbinary () ? "binary" : "text");
|
debug_printf ("returning %d, %s mode", len, rbinary () ? "binary" : "text");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -503,7 +503,8 @@ public:
|
||||||
HANDLE get_guard () const {return guard;}
|
HANDLE get_guard () const {return guard;}
|
||||||
int ready_for_read (int fd, DWORD howlong);
|
int ready_for_read (int fd, DWORD howlong);
|
||||||
static int create (fhandler_pipe *[2], unsigned, int, bool = false);
|
static int create (fhandler_pipe *[2], unsigned, int, bool = false);
|
||||||
bool is_slow () {return 1;}
|
bool is_slow () {return true;}
|
||||||
|
static int create_selectable (LPSECURITY_ATTRIBUTES, HANDLE&, HANDLE&, DWORD, bool);
|
||||||
friend class fhandler_fifo;
|
friend class fhandler_fifo;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -525,6 +526,7 @@ public:
|
||||||
void set_use ();
|
void set_use ();
|
||||||
int dup (fhandler_base *child);
|
int dup (fhandler_base *child);
|
||||||
bool is_slow () {return 1;}
|
bool is_slow () {return 1;}
|
||||||
|
void close_one_end ();
|
||||||
};
|
};
|
||||||
|
|
||||||
class fhandler_dev_raw: public fhandler_base
|
class fhandler_dev_raw: public fhandler_base
|
||||||
|
|
|
@ -67,14 +67,30 @@ fhandler_fifo::close ()
|
||||||
}
|
}
|
||||||
|
|
||||||
#define DUMMY_O_RDONLY 4
|
#define DUMMY_O_RDONLY 4
|
||||||
|
|
||||||
|
void
|
||||||
|
fhandler_fifo::close_one_end ()
|
||||||
|
{
|
||||||
|
int testflags = (get_flags () & (O_RDWR | O_WRONLY | O_APPEND)) ?: DUMMY_O_RDONLY;
|
||||||
|
static int flagtypes[] = {DUMMY_O_RDONLY | O_RDWR, O_WRONLY | O_APPEND | O_RDWR};
|
||||||
|
HANDLE *handles[2] = {&(get_handle ()), &(get_output_handle ())};
|
||||||
|
for (int i = 0; i < 2; i++)
|
||||||
|
if (!(testflags & flagtypes[i]))
|
||||||
|
{
|
||||||
|
CloseHandle (*handles[i]);
|
||||||
|
*handles[i] = NULL;
|
||||||
|
}
|
||||||
|
else if (i == 0 && !read_state)
|
||||||
|
{
|
||||||
|
create_read_state (2);
|
||||||
|
need_fork_fixup (true);
|
||||||
|
}
|
||||||
|
}
|
||||||
int
|
int
|
||||||
fhandler_fifo::open_not_mine (int flags)
|
fhandler_fifo::open_not_mine (int flags)
|
||||||
{
|
{
|
||||||
winpids pids;
|
winpids pids;
|
||||||
static int flagtypes[] = {DUMMY_O_RDONLY | O_RDWR, O_WRONLY | O_APPEND | O_RDWR};
|
|
||||||
HANDLE *usehandles[2] = {&(get_handle ()), &(get_output_handle ())};
|
|
||||||
int res = 0;
|
int res = 0;
|
||||||
int testflags = (flags & (O_RDWR | O_WRONLY | O_APPEND)) ?: DUMMY_O_RDONLY;
|
|
||||||
|
|
||||||
for (unsigned i = 0; i < pids.npids; i++)
|
for (unsigned i = 0; i < pids.npids; i++)
|
||||||
{
|
{
|
||||||
|
@ -109,22 +125,11 @@ fhandler_fifo::open_not_mine (int flags)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < 2; i++)
|
set_io_handle (r.handles[0]);
|
||||||
if (!(testflags & flagtypes[i]))
|
set_output_handle (r.handles[1]);
|
||||||
CloseHandle (r.handles[i]);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
*usehandles[i] = r.handles[i];
|
|
||||||
|
|
||||||
if (i == 0)
|
|
||||||
{
|
|
||||||
read_state = CreateEvent (&sec_none_nih, FALSE, FALSE, NULL);
|
|
||||||
need_fork_fixup (true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
res = 1;
|
|
||||||
set_flags (flags);
|
set_flags (flags);
|
||||||
|
close_one_end ();
|
||||||
|
res = 1;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -611,6 +611,7 @@ _pinfo::commune_recv ()
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
debug_printf ("fifo found %p, %p", it[0], it[1]);
|
debug_printf ("fifo found %p, %p", it[0], it[1]);
|
||||||
|
fh->close_one_end (); /* FIXME: not quite right - need more handshaking */
|
||||||
}
|
}
|
||||||
|
|
||||||
CloseHandle (hp);
|
CloseHandle (hp);
|
||||||
|
|
|
@ -318,21 +318,17 @@ leave:
|
||||||
FILE_READ_ATTRIBUTES access, on later versions of win32 where
|
FILE_READ_ATTRIBUTES access, on later versions of win32 where
|
||||||
this is supported. This access is needed by NtQueryInformationFile,
|
this is supported. This access is needed by NtQueryInformationFile,
|
||||||
which is used to implement select and nonblocking writes.
|
which is used to implement select and nonblocking writes.
|
||||||
Note that the return value is either NO_ERROR or GetLastError,
|
Note that the return value is either 0 or GetLastError,
|
||||||
unlike CreatePipe, which returns a bool for success or failure. */
|
unlike CreatePipe, which returns a bool for success or failure. */
|
||||||
static int
|
int
|
||||||
create_selectable_pipe (PHANDLE read_pipe_ptr,
|
fhandler_pipe::create_selectable (LPSECURITY_ATTRIBUTES sa_ptr, HANDLE& r,
|
||||||
PHANDLE write_pipe_ptr,
|
HANDLE& w, DWORD psize, bool fifo)
|
||||||
LPSECURITY_ATTRIBUTES sa_ptr,
|
|
||||||
DWORD psize)
|
|
||||||
{
|
{
|
||||||
/* Default to error. */
|
/* Default to error. */
|
||||||
*read_pipe_ptr = *write_pipe_ptr = INVALID_HANDLE_VALUE;
|
r = w = INVALID_HANDLE_VALUE;
|
||||||
|
|
||||||
HANDLE read_pipe = INVALID_HANDLE_VALUE, write_pipe = INVALID_HANDLE_VALUE;
|
|
||||||
|
|
||||||
/* Ensure that there is enough pipe buffer space for atomic writes. */
|
/* Ensure that there is enough pipe buffer space for atomic writes. */
|
||||||
if (psize < PIPE_BUF)
|
if (!fifo && psize < PIPE_BUF)
|
||||||
psize = PIPE_BUF;
|
psize = PIPE_BUF;
|
||||||
|
|
||||||
char pipename[CYG_MAX_PATH];
|
char pipename[CYG_MAX_PATH];
|
||||||
|
@ -342,9 +338,9 @@ create_selectable_pipe (PHANDLE read_pipe_ptr,
|
||||||
to be as robust as possible. */
|
to be as robust as possible. */
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
static volatile LONG pipe_unique_id;
|
static volatile ULONG pipe_unique_id;
|
||||||
|
|
||||||
__small_sprintf (pipename, "\\\\.\\pipe\\cygwin-%d-%ld", myself->pid,
|
__small_sprintf (pipename, "\\\\.\\pipe\\cygwin-%p-%p", myself->pid,
|
||||||
InterlockedIncrement ((LONG *) &pipe_unique_id));
|
InterlockedIncrement ((LONG *) &pipe_unique_id));
|
||||||
|
|
||||||
debug_printf ("CreateNamedPipe: name %s, size %lu", pipename, psize);
|
debug_printf ("CreateNamedPipe: name %s, size %lu", pipename, psize);
|
||||||
|
@ -358,84 +354,67 @@ create_selectable_pipe (PHANDLE read_pipe_ptr,
|
||||||
the pipe was not created earlier by some other process, even if
|
the pipe was not created earlier by some other process, even if
|
||||||
the pid has been reused. We avoid FILE_FLAG_FIRST_PIPE_INSTANCE
|
the pid has been reused. We avoid FILE_FLAG_FIRST_PIPE_INSTANCE
|
||||||
because that is only available for Win2k SP2 and WinXP. */
|
because that is only available for Win2k SP2 and WinXP. */
|
||||||
SetLastError (0);
|
r = CreateNamedPipe (pipename, PIPE_ACCESS_INBOUND,
|
||||||
read_pipe = CreateNamedPipe (pipename,
|
PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, 1, psize,
|
||||||
PIPE_ACCESS_INBOUND,
|
psize, NMPWAIT_USE_DEFAULT_WAIT, sa_ptr);
|
||||||
PIPE_TYPE_BYTE | PIPE_READMODE_BYTE,
|
|
||||||
1, /* max instances */
|
|
||||||
psize, /* output buffer size */
|
|
||||||
psize, /* input buffer size */
|
|
||||||
NMPWAIT_USE_DEFAULT_WAIT,
|
|
||||||
sa_ptr);
|
|
||||||
|
|
||||||
DWORD err = GetLastError ();
|
|
||||||
/* Win 95 seems to return NULL instead of INVALID_HANDLE_VALUE */
|
/* Win 95 seems to return NULL instead of INVALID_HANDLE_VALUE */
|
||||||
if ((read_pipe || !err) && read_pipe != INVALID_HANDLE_VALUE)
|
if (r && r != INVALID_HANDLE_VALUE)
|
||||||
{
|
{
|
||||||
debug_printf ("pipe read handle %p", read_pipe);
|
debug_printf ("pipe read handle %p", r);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DWORD err = GetLastError ();
|
||||||
switch (err)
|
switch (err)
|
||||||
{
|
{
|
||||||
case ERROR_PIPE_BUSY:
|
case ERROR_PIPE_BUSY:
|
||||||
/* The pipe is already open with compatible parameters.
|
/* The pipe is already open with compatible parameters.
|
||||||
Pick a new name and retry. */
|
Pick a new name and retry. */
|
||||||
debug_printf ("pipe busy, retrying");
|
debug_printf ("pipe busy, retrying");
|
||||||
continue;
|
break;
|
||||||
case ERROR_ACCESS_DENIED:
|
case ERROR_ACCESS_DENIED:
|
||||||
/* The pipe is already open with incompatible parameters.
|
/* The pipe is already open with incompatible parameters.
|
||||||
Pick a new name and retry. */
|
Pick a new name and retry. */
|
||||||
debug_printf ("pipe access denied, retrying");
|
debug_printf ("pipe access denied, retrying");
|
||||||
continue;
|
break;
|
||||||
case ERROR_CALL_NOT_IMPLEMENTED:
|
default:
|
||||||
/* We are on an older Win9x platform without named pipes.
|
/* CreateNamePipe failed. Maybe we are on an older Win9x platform without
|
||||||
Return an anonymous pipe as the best approximation. */
|
named pipes. Return an anonymous pipe as the best approximation. */
|
||||||
debug_printf ("CreateNamedPipe not implemented, resorting to "
|
debug_printf ("CreateNamedPipe failed, resorting to CreatePipe size %lu",
|
||||||
"CreatePipe size %lu", psize);
|
psize);
|
||||||
if (CreatePipe (read_pipe_ptr, write_pipe_ptr, sa_ptr, psize))
|
if (CreatePipe (&r, &w, sa_ptr, psize))
|
||||||
{
|
{
|
||||||
debug_printf ("pipe read handle %p", *read_pipe_ptr);
|
debug_printf ("pipe read handle %p", r);
|
||||||
debug_printf ("pipe write handle %p", *write_pipe_ptr);
|
debug_printf ("pipe write handle %p", w);
|
||||||
return NO_ERROR;
|
return 0;
|
||||||
}
|
}
|
||||||
err = GetLastError ();
|
err = GetLastError ();
|
||||||
debug_printf ("CreatePipe failed, %E");
|
debug_printf ("CreatePipe failed, %E");
|
||||||
return err;
|
return err;
|
||||||
default:
|
|
||||||
debug_printf ("CreateNamedPipe failed, %E");
|
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
/* NOTREACHED */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
debug_printf ("CreateFile: name %s", pipename);
|
debug_printf ("CreateFile: name %s", pipename);
|
||||||
|
|
||||||
/* Open the named pipe for writing.
|
/* Open the named pipe for writing.
|
||||||
Be sure to permit FILE_READ_ATTRIBUTES access. */
|
Be sure to permit FILE_READ_ATTRIBUTES access. */
|
||||||
write_pipe = CreateFile (pipename,
|
w = CreateFile (pipename, GENERIC_WRITE | FILE_READ_ATTRIBUTES, 0, sa_ptr,
|
||||||
GENERIC_WRITE | FILE_READ_ATTRIBUTES,
|
OPEN_EXISTING, 0, 0);
|
||||||
0, /* share mode */
|
|
||||||
sa_ptr,
|
|
||||||
OPEN_EXISTING,
|
|
||||||
0, /* flags and attributes */
|
|
||||||
0); /* handle to template file */
|
|
||||||
|
|
||||||
if (write_pipe == INVALID_HANDLE_VALUE)
|
if (!w || w == INVALID_HANDLE_VALUE)
|
||||||
{
|
{
|
||||||
/* Failure. */
|
/* Failure. */
|
||||||
DWORD err = GetLastError ();
|
DWORD err = GetLastError ();
|
||||||
debug_printf ("CreateFile failed, %E");
|
debug_printf ("CreateFile failed, %E");
|
||||||
CloseHandle (read_pipe);
|
CloseHandle (r);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
debug_printf ("pipe write handle %p", write_pipe);
|
debug_printf ("pipe write handle %p", w);
|
||||||
|
|
||||||
/* Success. */
|
/* Success. */
|
||||||
*read_pipe_ptr = read_pipe;
|
return 0;
|
||||||
*write_pipe_ptr = write_pipe;
|
|
||||||
return NO_ERROR;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -444,9 +423,9 @@ fhandler_pipe::create (fhandler_pipe *fhs[2], unsigned psize, int mode, bool fif
|
||||||
HANDLE r, w;
|
HANDLE r, w;
|
||||||
SECURITY_ATTRIBUTES *sa = (mode & O_NOINHERIT) ? &sec_none_nih : &sec_none;
|
SECURITY_ATTRIBUTES *sa = (mode & O_NOINHERIT) ? &sec_none_nih : &sec_none;
|
||||||
int res = -1;
|
int res = -1;
|
||||||
int ret;
|
|
||||||
|
|
||||||
if ((ret = create_selectable_pipe (&r, &w, sa, psize)) != NO_ERROR)
|
int ret = create_selectable (sa, r, w, psize, fifo);
|
||||||
|
if (ret)
|
||||||
__seterrno_from_win_error (ret);
|
__seterrno_from_win_error (ret);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -54,7 +54,9 @@ strace::hello ()
|
||||||
if (active)
|
if (active)
|
||||||
{
|
{
|
||||||
prntf (1, NULL, "**********************************************");
|
prntf (1, NULL, "**********************************************");
|
||||||
prntf (1, NULL, "Program name: %s (%d)", myself->progname, myself->pid ?: GetCurrentProcessId ());
|
prntf (1, NULL, "Program name: %s (pid %d, ppid %d)", myself->progname,
|
||||||
|
myself->pid ?: GetCurrentProcessId (),
|
||||||
|
myself->ppid ?: 1);
|
||||||
prntf (1, NULL, "App version: %d.%d, api: %d.%d",
|
prntf (1, NULL, "App version: %d.%d, api: %d.%d",
|
||||||
user_data->dll_major, user_data->dll_minor,
|
user_data->dll_major, user_data->dll_minor,
|
||||||
user_data->api_major, user_data->api_minor);
|
user_data->api_major, user_data->api_minor);
|
||||||
|
|
Loading…
Reference in New Issue