Commit Graph

12219 Commits

Author SHA1 Message Date
Ken Brown d79aa0f593 Cygwin: FIFO: respect the O_CLOEXEC flag
Set the inheritance of the Windows pipe handles according to the
O_CLOEXEC flag.  Previously the pipe was always created and opened
with OBJ_INHERIT.
2019-05-28 15:50:05 -04:00
Ken Brown 5bb8d445f4 Cygwin: FIFO: Open only one handle to NPFS
Make npfs_handle a static member function of fhandler_fifo, as in
fhandler_socket_unix.
2019-05-23 08:39:33 -04:00
Ken Brown e91bc190ff Cygwin: FIFO: code simplifications.
There's no longer a need to consider the connect_evt after fork/exec.
After stopping the listen_client thread, all client handlers should be
in the fc_connected or fc_invalid states, so their connect_evt members
won't be used again.

Also remove code in fhandler_fifo::dup that just repeats things
already done in stop_listen_client.
2019-05-09 14:41:29 -04:00
Ken Brown 0771fc7031 Cygwin: FIFO: make read_ready an auto-reset event
There's no point in allowing a writer to attempt to open until we've
created a pipe instance.
2019-05-09 14:41:29 -04:00
Ken Brown 102571f85d Cygwin: FIFO: improve the check for the listen_client thread
Add a method fhandler_fifo::check_listen_client_thread that checks
whether the thread is running.  Use it in raw_read instead of just
testing the handle listen_client_thr.
2019-05-09 14:41:29 -04:00
Ken Brown 7ad80b3c23 Cygwin: FIFO: set client handler flags more accurately
Reflect the fact that client handlers are only used for reading and
that, after connection, they are always nonblocking.
2019-05-09 14:41:29 -04:00
Ken Brown c12053a793 Cygwin: FIFO: don't leave a pending listen request
On exit from the listen_client thread, make sure there's no pending
FSCTL_PIPE_LISTEN request.  Otherwise we might get a client connection
after restarting the thread, and we won't have a handle for
communicating with that client.

Remove the retry loop in the case of STATUS_PIPE_LISTENING; that case
shouldn't occur.

Remove the now-unused fc_connecting value from
fifo_client_connect_state.
2019-05-09 14:41:29 -04:00
Ken Brown 816c6da53a Cygwin: FIFO: add a HANDLE parameter to open_pipe
It's now up to the caller to pass a handle to open_pipe and, if
desired, to call set_handle on return.

This will be useful for a future commit, in which we will open a
client connection without setting an io_handle.
2019-05-09 14:41:29 -04:00
Ken Brown 00b2e56d31 Cygwin: FIFO: re-implement duplexers
When opening a duplexer, open a client connection to the first client
handler.  Previously we gave the duplexer a bogus write handle, which
was just a duplicate of the first client handler's handle.  This meant
that we had a pipe server with no clients connected, and all I/O
attempts failed with STATUS_PIPE_LISTENING.

Extend the last fcntl change to duplexers.

Remove a now unused fifo_client_handler constructor, as well as the
long unusued method fifo_client_handler::connect.

Don't create the pipe in duplex mode; the server handle will only be
used for reading.
2019-05-09 14:41:29 -04:00
Ken Brown f3d1fe2ff8 Cygwin: FIFO: add 'record_connection' method
Future commits will have to re-use the code for recording a client
connection.  For convenience, factor out this code into a new method.
2019-05-09 14:41:29 -04:00
Ken Brown 1372021a2d Cygwin: FIFO: remove incorrect duplexer code
raw_read had some code that was based on an incorrect implementation
of duplexers.
2019-05-09 14:41:28 -04:00
Ken Brown 674b4fe995 Revert "Cygwin: check for STATUS_PENDING in fhandler_base::raw_read"
This reverts commit 10bf30bebf.  It was
made because an incorrect implementation of duplex FIFOs.
2019-05-09 14:41:28 -04:00
Michael Haubenwallner b6ebca61e3 Cygwin: dll_list: drop unused read_fbi method 2019-05-05 10:04:43 -04:00
Corinna Vinschen 4ac32559c0 Cygwin: Add release info for 3.0.7
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
(cherry picked from commit 01c253a4c58b6c1da01615431bdc4c88fcba48ea)
2019-04-30 18:49:23 +02:00
Michael Haubenwallner e33db96a14 Cygwin: dll_list: query dll file id at load time
NtQueryVirtualMemory for MemorySectionName does not reliable return the
changed dll file name when another process does move the file around,
and we may end up creating forkable hardlinks to wrong dll files.
So query the file id when loading the dll rather than before fork.
2019-04-30 18:10:08 +02:00
Michael Haubenwallner 0f5776c47c Cygwin: dll_list: stat_real_file_once as dll method
Make stat_real_file_once a method of struct dll, to be more flexible on
where to use.  Also, debug print memory section name queried for a dll.
This is a preparation to query the file id when loading the dll.
2019-04-30 18:10:08 +02:00
Michael Haubenwallner 4c79da8017 Cygwin: dll_list: drop FILE_BASIC_INFORMATION
Querying FILE_BASIC_INFORMATION is needless since using win pid+threadid
for forkables dirname rather than newest last write time.
2019-04-30 18:10:08 +02:00
Corinna Vinschen a4e62e3a4c Cygwin: update era and message locale data
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-04-30 11:55:04 +02:00
Ken Brown 440559c40a Cygwin: FIFO: synchronize the blocking mode of a writer's pipe
The blocking mode of the Windows pipe underlying a writer is set to
match that of the writer itself when the latter is opened.  Define
fhandler_fifo::fcntl to keep the pipe and the writer in sync if the
blocking mode is changed via fcntl.
2019-04-26 07:45:37 -04:00
Corinna Vinschen f527171a93 Cygwin: define MSG_EOR and refuse in send(2)
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-04-25 19:00:08 +02:00
Erik M. Bray 489e7e2048 Minor improvements to socket error handling:
* Change default fallback for failed winsock error -> POSIX error
  mappings to EACCES, which is a valid errno for more socket-related
  syscalls.

* Added a few previously missing entries to the wsock_errmap table
  that have obvious POSIX errno.h analogues.
2019-04-23 17:20:57 +02:00
Ken Brown 9957a7895b Cygwin: FIFO: restart listen_client thread after fork/exec
This allows writers to connect immediately.  Previously the lct wasn't
restarted until the reader attempted to read.
2019-04-22 07:55:58 -04:00
Ken Brown 4443100b53 Cygwin: FIFO: stop the listen_client thread before fork/exec
Add methods need_fixup_before, init_fixup_before, and
fixup_before_fork_exec to accomplish this.  Stopping the thread makes
sure that the client handler lists of the parent and child remain in
sync while the forking/execing is in progress.
2019-04-20 14:31:07 -04:00
Ken Brown 252cd0ce2b Cygwin: FIFO: close connect_evt handles as soon as possible
Keeping them open too long can cause an attempt to close them twice
after a fork or exec.
2019-04-20 14:31:07 -04:00
Ken Brown 24c56e5a2c Cygwin: FIFO: avoid WFMO error in listen_client_thread
Don't set lct_termination_evt to NULL too early in
fhandler_fifo::stop_listen_client.  Doing so leads to an "Invalid
Handle" error in WFMO.
2019-04-20 14:31:07 -04:00
Ken Brown ef269531a9 Cygwin: FIFO: duplicate the i/o handle when opening a duplexer
Don't use the same i/o handle for the first client handler as is used
for the fhandler itself; this can lead to a later attempt to close the
same handle twice.  Instead use a duplicate.
2019-04-20 14:31:07 -04:00
Ken Brown 4ecea14a58 Cygwin: FIFO: stop the listen_client thread on an opening error
Don't just close the thread handle.
2019-04-20 14:31:07 -04:00
Corinna Vinschen 28182bca18 Cygwin: drop unsupported Windows 10 versions
* Pre-release version still reporting kernel version 6.4.
* Windows 10 1511 is out of support since 2017-10-10.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-04-19 18:13:02 +02:00
Ken Brown 230c5df2df Cygwin: FIFO: avoid hang after exec
Define fhandler:fifo::fixup_after_exec, which sets listen_client_thr
and lct_termination_evt to NULL.  This forces the listen_client thread
to restart on the first attempt to read after an exec.  Previously the
exec'd process could hang in fhandler_fifo::raw_read.
2019-04-18 19:34:07 +02:00
Ken Brown 2b4cf7622e Cygwin: FIFO: fix and simplify listen_client_thread
Remove fifo_client_handler::connect and move its code into
listen_client_thread.  That way we can check the return status when a
client handler's connect_evt is signaled.  Previously we incorrectly
assumed there was a successful connection.

Also simplify listen_client_thread in the following ways:

- Replace fhandler_fifo::disconnect_and_reconnect by a new
  delete_client_handler method.  Now we just delete invalid client
  handlers rather than trying to re-use them.

- Try to maintain a client handler list that consists of connected
  client handlers and exactly one that is listening for a connection.
  This allows us to call WaitForMultipleObjects with only two wait
  objects.

- Remove 'dummy_evt' from the fifo_client_handler struct; it is no
  longer needed.

- On exit from listen_client_thread, delete the "extra" (listening)
  client handler.  Otherwise there could be a connection that doesn't
  get recorded in the client handler list.  This could happen when a
  file descriptor is being duplicated.
2019-04-16 12:54:43 +02:00
Ken Brown bb46627871 Cygwin: FIFO: improve raw_write
Don't set the write end of the pipe to non-blocking mode if the FIFO
is opened in blocking mode.

In fhandler_fifo::raw_write in blocking mode, wait for the write to
complete rather than returning -1 with EAGAIN.

If the amount to write is large, write in smaller chunks (of size
determined by a new data member max_atomic_write), as in
fhandler_base_overlapped.

For convenience, add two new NTSTATUS codes, STATUS_THREAD_SIGNALED
and STATUS_THREAD_CANCELED, to ntdll.h.
2019-04-16 12:54:43 +02:00
Ken Brown a7d08b3ecd Cygwin: FIFO: start the listen_client thread when duping a reader
Otherwise it doesn't get started until the dup'd fd tries to read,
which delays client connections.
2019-04-16 12:54:43 +02:00
Ken Brown 7b28776d3f Cygwin: FIFO: fix clone
After copyto is called, make the new fhandler's pipe_name point to the
new fhandler's pipe_name_buf, which is a *copy* of the old fhandler's
pipe_name_buf.  Previously, get_pipe_name would return the wrong
result after a clone/dup, causing create_pipe_instance and open_pipe
to fail.

Also, stop the listen_client thread when cloning.  Otherwise the
thread can keep accepting connections that the cloned fhandler won't
know about.

Do this via a new method fhandler_fifo::stop_listen_client, extracted
from fhandler_fifo::close.
2019-04-16 12:54:43 +02:00
Ken Brown c5bc7a8065 Cygwin: FIFO: use a retry loop when opening a writer
There may be short periods when there's no pipe instance available.
Keep trying.
2019-04-16 12:54:43 +02:00
Ken Brown 6b20be0944 Cygwin: FIFO: fix the use of the read_ready event
Make read_ready a manual reset event.  It should always be set shortly
after startup of the listen_client thread and remain set until the
thread terminates.  (We don't want writers to connect without being
recorded in the client handler list.)

Remove the unnecessary code that checks for read_ready when a reader
is opening.
2019-04-16 12:54:43 +02:00
Ken Brown 3ef03376c5 Cygwin: FIFO: fix fifo_client_handler::close
Make sure that fhandler_base::close rather than fhandler_fifo::close
is called on the fhandler.  Also, delete the fhandler, since we
allocated it.
2019-04-16 12:54:43 +02:00
Ken Brown d243b3c70e Cygwin: FIFO: code simplification: don't overload get_handle
Rename fhandler_fifo::get_handle(int) to get_fc_handle(int), and
remove fhandler_fifo::get_handle(void).
2019-04-16 12:54:43 +02:00
Ken Brown 10bf30bebf Cygwin: check for STATUS_PENDING in fhandler_base::raw_read
If NtReadFile returns STATUS_PENDING, wait for the read to complete.
This can happen, for instance, in the case of a FIFO opened with
O_RDRW.
2019-04-16 12:54:43 +02:00
Ken Brown 513f050cbf Cygwin: FIFO: fix the error checking in raw_read
If the pipe is empty, we can get either ERROR_NO_DATA or
ERROR_PIPE_LISTENING.
2019-04-16 12:54:43 +02:00
Ken Brown 0c72e766e2 Cygwin: FIFO: fix a thinko in listen_client_thread 2019-04-16 12:54:43 +02:00
Ken Brown 1643789517 Cygwin: FIFO: remember the type of the fhandler
Add data members 'reader', 'writer', and 'duplexer' to the
fhandler_fifo class.  Set them in fhandler_fifo::open.  ('duplexer'
replaces the previous '_duplexer'.)

This will be useful in later commits.
2019-04-16 12:54:43 +02:00
Ken Brown 5281699926 Cygwin: FIFO: hit_eof: add a call to fifo_client_lock
The second check of nconnected needs to be protected by a lock as well
as the first.
2019-04-16 12:54:43 +02:00
Ken Brown b63843ed56 Cygwin: FIFO: rename client[] to fc_handler[]
The word "client" suggests something that holds a handle to the client
side of the pipe (in Windows terminology).  But our
fifo_client_handlers hold a handle the server side of the pipe, and
they *connect* to clients.
2019-04-16 12:54:43 +02:00
Michael Haubenwallner 204efa6bba Cygwin: use win pid+threadid for forkables dirname
Rather than newest last write time of all dlls loaded, use the forking
process' windows pid and windows thread id as directory name to create
the forkable hardlinks into.  While this may create hardlinks more
often, it does avoid conflicts between dlls not having the newest last
write time.
2019-04-12 20:01:04 +02:00
Erik M. Bray 2607639992 Improve error handling in /proc/[pid]/ virtual files.
* Changes error handling to allow /proc/[pid]/ virtual files to be
  empty in some cases (in this case the file's formatter should return
  -1 upon error, not 0).

* Better error handling of /proc/[pid]/stat for zombie processes:
  previously trying to open this file on zombie processes resulted
  in an EINVAL being returned by open().  Now the file can be read,
  and fields that can no longer be read are just zeroed.

* Similarly for /proc/[pid]/statm for zombie processes.

* Similarly for /proc/[pid]/maps for zombie processes (in this case the
  file can be read but is zero-length, which is consistent with observed
  behavior on Linux.
2019-04-10 18:17:14 +02:00
Corinna Vinschen f0ea836b75 Cygwin: add latest signal handling fixes to release notes
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-04-06 18:09:41 +02:00
Corinna Vinschen 372874364e Cygwin: signals: setcontext: fix setting sigmask
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-04-05 12:13:44 +02:00
Corinna Vinschen 181ca73e49 Cygwin: follow context if changed inside SA_SIGINFO signal handler
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-04-05 11:25:19 +02:00
Corinna Vinschen c5f9eed1c0 Cygwin: signals: make setcontext work from signal handlers
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-04-04 21:25:47 +02:00
Takashi Yano 6a06c6bc8f Cygwin: console: fix key input for native console application
- After 24 bit color support patch, arrow keys and function keys
  do not work properly in native console applications if they
  are started in cygwin console. This patch fixes this issue.
2019-04-03 18:45:14 +02:00
Corinna Vinschen d3a69d32b1 Cygwin: signals: restore sigmask from context given to signal handler
In case SA_SIGINFO flag is given, the signal handler may change
the context and the application is supposed to pick up from the
changed context.  So far we don't do that, so the context given
to the signal handler is basically read-only, unless the signal
handler calls setcontext or swapcontext.

For a start, restore the thread's signal mask from the uc_sigmask
value of the context given to the signal handler.

If that's feasible for Cygwin, we restore the entire context from
the context changed by the signal handler in a followup patch.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-04-03 18:14:30 +02:00
Corinna Vinschen 557227dda3 Cygwin: winpids: Fix getting process multiple times, take 2
commit d1be0a59d4,
"Cygwin: winpids: Fix getting process multiple times"
fixed duplicate processes in ps -W output, but it fixed
the symptom, not the cause.  It also didn't fix the problem
that the `ps' process itself may show up twice in its own
output.

This patch fixes it.  The spawn worker only deleted the
"winpid.PID" symlink of the current process if the child is
a non-Cygwin process, under the assumption that the exec'ing
process exits anyway.  However, the Window in which both
winpid.PID symlinks point to the same cygpid.PID area is just
too long.  The spawn worker now also deletes its own winpid.PID
symlink if the exec'ed process is a Cygwin process.

Additionally the fix from d1be0a59d4
is now performed on the calling process, too.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-04-02 13:00:22 +02:00
Corinna Vinschen de3c82ee6d Cygwin: Add console patches to release notes
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-03-31 19:37:55 +02:00
Takashi Yano f4b47827cf Cygwin: console: Make I/O functions thread-safe
- POSIX states I/O functions shall be thread-safe, however, cygwin
  console I/O functions were not. This patch makes console I/O
  functions thread-safe.
2019-03-31 18:34:58 +02:00
Takashi Yano 8382778cdb Cygwin: console: fix select() behaviour
- Previously, select() would return when only one key is typed even
  in canonical mode. With this patch, it returns after one line is
  completed.
2019-03-31 18:34:58 +02:00
Takashi Yano bd627864ab Cygwin: console: support 24 bit color
- Add 24 bit color support using xterm compatibility mode in
  Windows 10 1703 or later.
- Add fake 24 bit color support for legacy console, which uses
  the nearest color from 16 system colors.
2019-03-31 18:34:58 +02:00
Corinna Vinschen 7b8049f7a3 Cygwin: document ps -W duplication bug fix
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-03-31 12:50:50 +02:00
Takashi Yano a9c661a94d Cygwin: [gs]et_io_handle(): renamed to [gs]et_handle().
- Unify get_io_handle() and get_handle() to get_handle().
  Both of them returned same value; io_handle.
- Rename set_io_handle() to set_handle().
2019-03-30 20:08:36 +01:00
Michael Haubenwallner 023c107a22 Cygwin: fork: reserve dynloaded dll areas earlier
In dll_crt0_0, both threadinterface->Init and sigproc_init allocate
windows object handles using unpredictable memory regions, which may
collide with dynamically loaded dlls when they were relocated.
2019-03-28 10:09:53 +01:00
Ken Brown e0fd15c91b Cygwin: FIFO: implement clear_readahead
Make fhandler_base::clear_readahead virtual, and implement
fhandler_fifo::clear_readahead.  This is called by
dtable::fixup_after_exec; it clears the readahead in each client.
2019-03-28 09:36:34 +01:00
Ken Brown 298581868a Cygwin: document the recent FIFO changes 2019-03-27 19:47:59 +01:00
J.H. van de Water f46c9ab46c Cygwin: fix: seteuid32() must return EPERM if privileges are not held.
Starting w/ the intro of S4U, seteuid32() calls lsaprivkeyauth(), then
s4uauth(). s4uauth calls LsaRegisterLogonProcess().
LsaRegisterLogonProcess fails w/ STATUS_PORT_CONNECTION_REFUSED, if the
proper privileges are not held.
Because of RtlNtStatusToDosError(), this status would be mapped to
ERROR_ACCESS_DENIED, which in turn would map to EACCES. Therefore it is
useless to add this status to errmap[] (errno.cc), as s4auauth() should
return EPERM as errno here (i.e. if process is not privileged).

Hence the kludge.

Before the intro of S4U, seteuid32() called lsaprivkeyauth(), then
lsaauth(), then create_token(). Before the intro of Vista, the latter
would have called NtCreateToken().
NtCreateToken() would have failed w/ STATUS_PRIVILEGE_NOT_HELD for a
process w/o the proper privileges. In that case, calling seteuid32()
would have returned EPERM (as required).

Since the intro of Vista, and if the process had been started from an
UNelevated shell, create_token() does NOT reach NtCreateToken()!
As create_token() failed to properly set errno in that case, calling
seteuid32() would return errno as set by lsaauth(), i.e. EACCES, not
in agreement w/ Posix (a bug which was present for years).
(lsaauth() called LsaRegisterLogonProcess() which would fail)
2019-03-27 17:08:49 +01:00
Ken Brown a137da74ba Cygwin: FIFO: add support for the duplex case
If a FIFO is opened with O_RDWR access, create the pipe with
read/write access, and make the first client have the handle of that
pipe as its I/O handle.

Adjust fhandler_fifo::raw_read to account for the result of trying to
read from that client if there's no data.
2019-03-27 14:01:45 +01:00
Ken Brown 40db74128a Cygwin: FIFO: avoid crashes when cloning a client
fhandler_fifo::clone called fhandler_base::clone on each client
fhandler.  But those fhandlers are actually fhandler_fifo objects, so
when fhandler_base::clone calls copyto, it's actually
fhandler_fifo::copyto that gets called.  This can lead to mysterious
crashes.

Fix this by simply calling clone (which translates to
fhandler_fifo::clone) on each client fhandler.
2019-03-27 14:01:45 +01:00
Ken Brown ee394c311e Cygwin: FIFO: update select
Add static functions peek_fifo, thread_fifo, start_thread_fifo, and
fifo_cleanup to select.cc.  These are based on the corresponding pipe
functions, the main difference being that peek_fifo loops through the
connected clients to see if any of them have data available for
reading.

Add the fhandler_fifo methods select_read, select_write, and
select_except.

Add accessor methods get_nclients, get_handle, and is_connected that
are needed by peek_fifo.
2019-03-27 14:01:45 +01:00
Ken Brown 1aa438a94c Cygwin: FIFO: update set_close_on_exec
Deal with each client.
2019-03-27 14:01:45 +01:00
Ken Brown e02a0f7295 Cygwin: FIFO: update fixup_after_fork
Fixup each client.  Reset listen_client_thr and lct_termination_evt.
2019-03-27 14:01:45 +01:00
Ken Brown 035bf7dc84 Cygwin: FIFO: update clone and dup
Deal with all clients.
2019-03-27 14:01:45 +01:00
Ken Brown c6e221c036 Cygwin: FIFO: improve EOF detection
Add a hit_eof method that tries to detect whether any clients are
connected.  Before concluding that there are none, it gives the
listen_client thread time to update the client data.
2019-03-27 14:01:45 +01:00
Ken Brown c75e077f99 Cygwin: FIFO: add a spinlock
Don't let listen_client_thread and raw_read access the client list
simultaneously.
2019-03-27 14:01:45 +01:00
Ken Brown 48d4cce3be Cygwin: FIFO: allow multiple writers
Introduce a 'fifo_client_handler' structure that can be used by a
reader to communicate with a writer using an instance of the named
pipe.  An fhandler_fifo opened for reading creates a thread that does
the following:

 - maintains a list of fifo_client_handlers
 - listens for_clients trying to connect
 - creates new pipe instances as needed so that there's always at
   least one available for connecting.

The pipe instances are initially created in blocking mode, but they
are set to be non-blocking after a connection is made.

fhandler_fifo::raw_read now loops through the connected clients and
reads from the first one that has data available.

New fhandler_fifo methods: add_client, listen_client,
listen_client_thread, check_listen_client_thread.

Replace the create_pipe method by create_pipe_instance, which allows
unlimited pipe instances.

New helper functions: create_event, set_pipe_non_blocking.
2019-03-27 14:01:45 +01:00
Ken Brown 5955da96e2 Cygwin: FIFO: stop using overlapped I/O
Make fhandler_fifo a derived class of fhandler_base instead of
fhandler_base_overlapped.

Replace the create_pipe macro, which is based on
fhandler_pipe::create, by new create_pipe and open_pipe methods.
These use NT functions instead of Win32 functions.  Replace fifo_name
by get_pipe_name, which returns a pointer to a UNICODE_STRING.

Remove the fnevent macro, which would now be needed only once.

Add a raw_write method, adapted from fhandler_base::raw_write.

Adapt all functions to the changes above.
2019-03-27 14:01:45 +01:00
Corinna Vinschen 9fd429e6a7 Cygwin: Bump DLL version to 3.1
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-03-27 14:01:44 +01:00
Corinna Vinschen d1be0a59d4 Cygwin: winpids: Fix getting process multiple times
Switching to Cywin-only PIDs introduced a new problem when collecting
Cygwin processes for `ps -W': A process can show up multiple times
again, if the Cygwin procinfo has been opened for a just execing
process.  The execed process then shows up twice, once as Cygwin
process, but with the wrong Windows PID of the execing process,
once as Windows-only process.

The mechanism used to exclude these stray processes didn't work with
the new Cygwin pid handling anymore.  To fix this

* check if the incoming Windows PID is the same as the PID in the
  procinfo.  If not, we have the PID of the execing process while
  procinfo was already changed,
* always check if the process has already been handled, not only
  for processes we got a procinfo for,
* simplify adding pid to pidlist since pid is now always correct.

While at it, fix comments and comment formatting.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-03-27 13:54:36 +01:00
Brian Inglis 23bb2f6608 get and convert boot time once and use as needed 2019-03-25 11:26:17 +01:00
Brian Inglis ee1ad64234 default ps -W process start time to system boot time when inaccessible, 0, -1 2019-03-25 11:26:17 +01:00
Corinna Vinschen 5737045c00 Cygwin: ctrl_c_handler: Use 64 bit timer
Just don't use GetTickCount for obvious reasons

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-03-24 22:13:00 +01:00
Corinna Vinschen 4afc52d57c Cygwin: sys/cygwin.h: fix formatting
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-03-23 17:50:47 +01:00
Corinna Vinschen ae3370bb9d Cygwin: strace: print windows and cygwin pid in event output
strace only printed the Windows PID in event output so far.

Especially now that Windows and Cygwin PID are decoupled, the
strace user might like to see the Cygwin pid in event output as
well.  However, at process startup, the process might not have
a Cygwin PID yet.

To mitigate this, always print the Windows PID and only add the
Cygwin pid if it exists.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-03-23 17:50:00 +01:00
Corinna Vinschen 10900b98d1 Cygwin: wcsxfrm_l: Only byte swap if dest size is > 0
commit c0d7d3e1a2 removed the usage of the
LCMAP_BYTEREV flag in the call to LCMapStringW to workaround a strange
bug in LCMapStringW.  This patch didn't take a userspace call of
wcsxfrm{_l} with NULL buffer and 0 size to evaluate the required buffer
size into account.  This introduced a crash trying to byte swap the
NULL buffer.  This patch fixes that problem.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-03-19 21:03:06 +01:00
Corinna Vinschen 38322b9bf6 Cygwin: proc: fix /proc/version output after uname change
3.0.0 changed uname but missed to align /proc/version
which then used the old uname function on the new uname
struct.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-03-18 11:34:00 +01:00
Corinna Vinschen df960cb954 Cygwin: bump version to 3.0.5
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-03-18 11:29:00 +01:00
Corinna Vinschen 004d8adfa2 Cygwin: acls: allow converting empty acl to text
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-03-13 12:09:11 +01:00
Corinna Vinschen 111b34bb1b Cygwin: proc: add missing LF to /proc/<PID>/stat output
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-03-13 11:26:58 +01:00
Corinna Vinschen 1def2148d2 Cygwin: ps: simplify code
Always use NtQuerySystemInformation(SystemProcessIdInformation).
This drops two code paths calling NtQueryInformationProcess or
GetModuleFileNameExW and only requires to open the process
to fetch system time info.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-03-12 21:21:13 +01:00
Corinna Vinschen 37a046181e Cygwin: ps: show *all* processes in ps -W output
There's a long-standing bug in ps -W.  It only shows processes which ps
can open with PROCESS_QUERY_LIMITED_INFORMATION permissions.  However,
that fails for a lot of system processes. Due to that, output is
basically restricted to processes in the same session, as well as Cygwin
processes... which isn't *quite* what ps -W was supposed to do.

Basically we only need to open the process to fetch the image name.  If
that fails, utilize the undocumented SystemProcessIdInformation info
class introduced with Windows Vista, which allows to fetch the image
name by specifying the PID.  Restructure the code a bit.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-03-12 20:55:29 +01:00
Corinna Vinschen a2693428b9 Cygwin: ntdll.h: Add SystemProcessIdInformation
Add SystemProcessIdInformation to SYSTEM_INFORMATION_CLASS
and define struct _SYSTEM_PROCESS_ID_INFORMATION.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-03-12 20:11:38 +01:00
Corinna Vinschen de7f13aa9a Cygwin: loadavg: improve debugging of load_init
When logging in via ssh with an unprivileged account,
PdhAddEnglishCounter returns with status 0x800007D0,
PDH_CSTATUS_NO_MACHINE.  We didn't find any workaround
but the changes to improve debugging output may help
in future.  Using UNICODE instead of ANSI functions is
a result of trying to fix this problem.

Also drop the prototype workaround for PdhAddEnglishCounterA.
It's not required anymore since Mingw-w64's pdh.h catched up.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-03-12 17:09:42 +01:00
Corinna Vinschen 673a3daa84 Cygwin: add /proc changes to release notes
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-03-12 11:47:31 +01:00
Corinna Vinschen 24f9cb015e Cygwin: fork/exec: Allow all users PROCESS_QUERY_LIMITED_INFORMATION
Create process with standard rights, plus
PROCESS_QUERY_LIMITED_INFORMATION for authenticated users.  This
allows to fetch basic process information and thus /proc/<PID>/stat
to succeed on foreign processes.

While at it, fix formatting in CreateProcess calls.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-03-12 11:41:35 +01:00
Corinna Vinschen 57f1c81fb3 Cygwin: proc: let stat info always succeed
There's no good reason to return blank if some of the info
couldn't be collected.  Drop useless call collecting
SystemProcessorPerformanceInformation.  Always return some
valid start_time, even if we couldn't collect ProcessTimes.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-03-12 11:34:50 +01:00
Corinna Vinschen 4ce7e1bbaa Cygwin: proc: don't request PROCESS_VM_READ perms for stat
The OpenProcess call to generate /proc/<PID>/stat info requests
PROCESS_VM_READ, but that's not required.  Drop it.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-03-12 11:20:42 +01:00
Corinna Vinschen 048f28bfe4 Cygwin: proc: return more useful cmdline
Creating /proc/<PID>/cmdline requires permissions to communicate
with the target process via its signal pipe.  If that fails, the
output is "<defunct>" which doesn't make sense most of the time.
Rather, call format_process_exename in this case to get more useful
process name info, albeit not the full cmdline.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-03-12 11:17:11 +01:00
Corinna Vinschen d9f934c9e9 Cygwin: fix permissions of winpid symlinks
The winpid symlinks got created with no query permissions, so
only admins could see all Cygwin processes.  Create symlinks
so everyone has query permissions instead.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-03-11 21:40:04 +01:00
Corinna Vinschen 7cbe4b59d6 Cygwin: bump version to 3.0.4
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-03-09 20:13:50 +01:00
Corinna Vinschen 4ec5ffc198 Cygwin: posix timers: fix a deadlock
Canceling the timer thread runs under lock.  The thread uses the same
lock to guard its timer_tracker struct access.  If the timing is bad,
timer_settime or timer_delete grab the lock at the same time, the timer
expires.  In the end, cancel waits for the thread sync while the thread
waits for ther lock to be released.

Fix this by not waiting for the thread sync under lock.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-03-08 12:57:42 +01:00
Corinna Vinschen 094a2a17ad Cygwin: posix timers: fix resource leak
On setting the timer, the thread is accidentally only canceled when
disarming the timer.  This leaks one thread per timer_settimer call.
Move the thread cancellation where it belongs.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-03-06 22:19:16 +01:00
Corinna Vinschen 633278b877 Cygwin: bump version to 3.0.3
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-03-05 20:00:30 +01:00
Corinna Vinschen 8551226961 Cygwin: seteuid: do not verify lsaprivkeyauth token
We don't support setting groups via /etc/groups anymore.  Also, the
initgroups group list is created via S4U, so we have "Interactive" vs.
"Network" token, an artificial and entirely irrelevant difference.

So,  "verifying" the lsaprivkeyauth token may lead to rejecting a prefectly
valid token.  Just remove the verify_token call.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-03-04 20:36:26 +01:00
Corinna Vinschen ad49232083 Revert "Cygwin: load_user_profile: temporarily extend debug output"
This reverts commit 6aef5a46d7.
2019-03-04 17:31:34 +01:00