Commit Graph

696 Commits

Author SHA1 Message Date
Takashi Yano c4fb5da278 Cygwin: pty: Avoid client deadlock when pty master stops to read.
Previsouly, the following commands hangs:
  mintty -e timeout 1 dash -c 'yes aaaaaaaaaaaaaaaaaaaaaaaaa | cat'

The mechanism is as follows.

When the child process (timeout) is terminated, mintty seems to stop
reading pty master even if yes or cat still alive.

If the the pipe used to transfer output from pty slave to pty master
is full due to lack of master reader, WriteFile() to the pipe is
blocked. WriteFile() cannot be canceled by cygwin signal, therefore,
pty slave hangs.

This patch avoids hanging by checking pipe space before calling
WriteFile() and prevents writing data more than space.

Addresses: https://cygwin.com/pipermail/cygwin/2024-June/256178.html
Reported-by: jojelino <jojelino@gmail.com>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-07-01 17:45:00 +09:00
Jeremy Drake via Cygwin-patches 10b9216811 Cygwin: disable high-entropy VA for ldh
If ldd is run against a DLL which links to the Cygwin DLL, ldh will end
up loading the Cygwin DLL dynamically, much like cygcheck or strace.

Addresses: https://cygwin.com/pipermail/cygwin/2024-May/255991.html
Fixes: 60675f1a7e ("Cygwin: decouple shared mem regions from Cygwin DLL")
Reviewed-by: Ken Brown <kbrown@cornell.edu>, Takashi Yano <takashi.yano@nifty.ne.jp>
Signed-off-by: Jeremy Drake <cygwin@jdrake.com>
2024-06-03 05:31:18 +09:00
Takashi Yano 5a859642f0 Cygwin: pthread: Fix a race issue introduced by the commit 2c5433e5da
To avoid race issues, pthread::once() uses pthread_mutex. This caused
the handle leak which was fixed by the commit 2c5433e5da. However,
this fix introduced another race issue, i.e., the mutex may be used
after it is destroyed. This patch fixes the issue. Special thanks to
Bruno Haible for discussing how to fix this.

Addresses: https://cygwin.com/pipermail/cygwin/2024-May/255987.html
Reported-by: Bruno Haible <bruno@clisp.org>
Fixes: 2c5433e5da ("Cygwin: pthread: Fix handle leak in pthread_once.")
Reviewed-by: Ken Brown <kbrown@cornell.edu>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-06-02 23:18:29 +09:00
Corinna Vinschen 579064bf4d Cygwin: globify: read full 32 bit character
While commit 0321fb5736 ("Cygwin: glob: convert wchar_t to wint_t")
switched the entire glob mechanism from wchar_t to wint_t, the globify
function calling glob on a DOS command line did not catch up and only
checked for the next character constituting a 16 bit wchar_t. This
broke reading surrogate pairs from incoming DOS command lines if the
string had to go through glob(3).

Check for an entire 32 bit unicode char instead.

Fixes: 0321fb5736 ("Cygwin: glob: convert wchar_t to wint_t")
Reported-by: David Allsopp <david@tarides.com>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-04-09 22:30:03 +02:00
Corinna Vinschen 56e7563b9a Cygwin: FILE_OPEN_NO_RECALL is incompatible with FILE_DIRECTORY_FILE
If FILE_DIRECTORY_FILE is given, FILE_OPEN_NO_RECALL is not allowed,
otherwise NtCreateFile returns STATUS_INVALID_PARAMETER.

Drop FILE_OPEN_NO_RECALL where FILE_DIRECTORY_FILE is specified.

Fixes: f6b56abec1 ("Cygwin: try to avoid recalling offline files")
Reported-by: Bruce Jerrick <bmj001@gmail.com>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-04-04 18:21:13 +02:00
Corinna Vinschen db454e9868 Cygwin: add a fake 3.5.3 release file
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-04-03 19:47:58 +02:00
Corinna Vinschen 9761c6cca1 Cygwin: add //tsclient and //wsl$ support to relnotes
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-03-24 20:06:13 +01:00
Corinna Vinschen 7db1c6fc4e Cygwin: //server: revert to using WNet and support NFS shares
Continue using WSD for enumerating //, but switch back to
WNet for enumerating shares.

Add trying to enumerate NFS shares for machine names given as FQDN.

Only downcase server names, keep case of shares intact.
Move downcasing into dir_cache class.

Add a comment to explain an extrem weirdness in Windows.

Fixes: 205190a80b ("Cygwin: // and //server: switch to Network Discovery")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-03-23 22:32:42 +01:00
Corinna Vinschen b9ed33dec0 Cygwin: readdir: drop support for NT4/Win2K shares and Samba < 3.0.22
These systems are at least 18 years old and so buggy that they are
hopefully not used anymore.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-03-20 17:45:41 +01:00
Corinna Vinschen 205190a80b Cygwin: // and //server: switch to Network Discovery
SMBv1 is ultimately deprecated since Novemer 2023.  It's also
not installed by default on latest Windows versions.

Drop using the WNet (SMBv1) API in favor of using Network Discovery.
Given there's no documented Win32 API for that, the code now uses
the Shell API.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-03-20 14:46:49 +01:00
Corinna Vinschen 1719169604 Cygwin: (mostly) drop NT4 and Samba < 3.0 support
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-03-20 12:31:50 +01:00
Corinna Vinschen 89afbb8d8a Revert "Cygwin: glob: perform ignore_case_with_glob on input"
This reverts commit a51147467e.

Dumb thinko on my part.  What was supposed to be an optimization
actually broke caseinsensitive globbing in that the entire input
of globbed expressions were downcased.

Drop the unused CCHAR() macro nevertheless.

Fixes: a51147467e ("Cygwin: glob: perform ignore_case_with_glob on input")
Reported-by: Michael Goldshteyn <mgold10000@gmail.com>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-03-18 11:10:13 +01:00
Corinna Vinschen 3af5d2bbdd Cygwin: 3.6.0: add release entries for pinned/unpinned flag handling
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-03-11 12:53:50 +01:00
Corinna Vinschen 775069553b Cygwin: add 3.5.2 release entries for latest commits
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-03-11 12:53:24 +01:00
Takashi Yano 46bb999a89 Cygwin: pipe: Give up to use query_hdl for non-cygwin apps.
Non-cygwin app may call ReadFile() for empty pipe, which makes
NtQueryObject() for ObjectNameInformation block in fhandler_pipe::
get_query_hdl_per_process. Therefore, do not to try to get query_hdl
for non-cygwin apps.

Addresses: https://github.com/msys2/msys2-runtime/issues/202

Fixes: b531d6b06e ("Cygwin: pipe: Introduce temporary query_hdl.")
Reported-by: Alisa Sireneva, Johannes Schindelin <Johannes.Schindelin@gmx.de>
Reviewed-by: Corinna Vinschen <corinna@vinschen.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-03-05 22:03:01 +09:00
Takashi Yano b160b690b6 Cygwin: console: Fix a race issue between close() and open().
The open() call for console sometimes fails if the console owner
process is closing the console by close() at the same time. This
is due to mismatch state of con.owner variable and attaching state
to the console. With this patch, checking con.owner and attaching
to con.owner sequence in open(), and resetting con.owner and freeing
console sequence in close() are guarded by output_mutex to avoid
such a race issue.
Addresses: https://cygwin.com/pipermail/cygwin/2024-March/255575.html

Fixes: 3721a756b0 ("Cygwin: console: Make the console accessible from other terminals.")
Reported-by: Kate Deplaix <kit-ty-kate@outlook.com>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-03-04 11:58:09 +09:00
Takashi Yano c77a5689f7 Cygwin: console: Do not unmap shared console memory belonging to ctty.
In the condition that console setup for CTTY and close run at the
sametime, accessing shared console memory which is already unmapped
may occur. With this patch, to avoid this race issue, shared console
memory which belongs to contorolling terminal (CTTY) is kept mapped
as before.
Addresses: https://cygwin.com/pipermail/cygwin/2024-February/255561.html

Fixes: 3721a756b0 ("Cygwin: console: Make the console accessible from other terminals.")
Reported-by: Kate Deplaix <kit-ty-kate@outlook.com>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-03-01 20:00:11 +09:00
Corinna Vinschen 7a89f7261d Cygwin: add release text for getgrent local SAM enumeration patch
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-02-26 15:56:10 +01:00
Corinna Vinschen 388da83dce Cygwin: add newgrp release notes
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-02-24 13:12:14 +01:00
Corinna Vinschen a0d7758359 Cygwin: strptime: add release note
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-02-21 20:00:29 +01:00
Corinna Vinschen 70653fd8f1 Cygwin: gettimeofday: allow tv NULL pointer
Add a missing check for the struct timeval pointer being NULL.

Reported-by: 109224573 <109224573@qq.com>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-02-20 12:30:34 +01:00
Corinna Vinschen a7bf7c7dd5 Cygwin: timespec_get: implement C11 function
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-02-16 20:44:31 +01:00
Takashi Yano 4dd3dc876c Cygwin: console: Fix a bug that cannot handle consoles more than 32.
Fixes: 3721a756b0 ("Cygwin: console: Make the console accessible from other terminals.")
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-02-16 02:37:46 +09:00
Takashi Yano ac92c4c9f5 Cygwin: console: Make VMIN and VTIME work.
Previously, VMIN and VTIME did not work at all. This patch fixes that.

Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-02-13 23:26:50 +09:00
Takashi Yano 06992ed6b4 Cygwin: pty: Fix handle leak in master process.
If non-cygwin process is started in pty, closing from_master_nat
pipe handle was missing in fhandler_pty_slave::input_transfer().
This occured because the handle was duplicated but not closed.

https://github.com/msys2/msys2-runtime/issues/198

Fixes: 29431fcb5b ("Cygwin: pty: Inherit typeahead data between two input pipes.")
Reported-by: Hakkin Lain
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-02-13 23:23:52 +09:00
Corinna Vinschen 918c3eda41 Cygwin: document new winjitdebug option
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-02-03 20:03:12 +01:00
Takashi Yano b91d38db37 Cygwin: net: Make if_nametoindex, etc. consistent with if_nameindex.
Currently, if_nametoindex() and if_indextoname() handle interface names
such as "ethernet_32777", while if_nameindex() returns the names such
as "{5AF7ACD0-D52E-4DFC-A4D0-54D3E6D6B2AC}". This patch unifies the
interface names to the latter.

Fixes: c356901f0d ("Rename if_indextoname to cygwin_if_indextoname (analag for if_nametoindex)")
Reviewed-by: Corinna Vinschen <corinna@vinschen.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-02-03 23:47:44 +09:00
Takashi Yano ad75a40cd8 Cygwin: Document recent bug fix in release note. 2024-02-03 23:37:46 +09:00
Corinna Vinschen 2e7f7b96e5 Cygwin: implement setproctitle
Make sure to create commandline according to setting of setproctitle.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-01-31 20:11:58 +01:00
Corinna Vinschen 1ce9756ee6 Cygwin: ps -f: output command line
So far ps(1) always prints the full path of the executable under
the COMMAND heading.

With -f, print the command line instead.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-01-31 20:11:58 +01:00
Corinna Vinschen 62ca95721a Cygwin: posix_getdents: implement per SUS Base Specifications Issue 8 draft
- Basically maintain a hidden DIR* inside fhandlers.

- lseek has to be tweaked to allow basic seeking on the directory
  descriptor.

- the current implementation does not keep the dir positions
  between duplicated descriptor in sync.  In fact, every descriptor
  keeps its own copy of the DIR* and after dup/fork/exec, the
  directory position is reset to 0, i. e., to the start of the
  directory, as if rewinddir() has been called on the new descriptors.

  While this behaviour isn't yet covered by the Issue 8 draft,
  a bug report along these lines exists and will probably be
  picked up for TC1.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-01-31 20:11:58 +01:00
Corinna Vinschen d72be712aa Cygwin: implement fdclosedir
fdclosedir is BSD-only but already present in dirent.h for a couple
of years.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-01-31 20:11:57 +01:00
Corinna Vinschen cd260e4daa Cygwin: export getlocalename_l
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-01-31 20:11:57 +01:00
Corinna Vinschen 030a762535 Cygwin: fix arc4random after fork(2)
After using fork(), arc4random does not reseed itself, which
causes the results to become predictable.  Activate droppingfork-recognition

Fixes: e0fc33322d ("Delete Cygwin's arc4random in favor of new Newlib implementation")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-01-29 13:43:36 +01:00
Corinna Vinschen 70b27cee0c Cygwin: copy doc changes from commit 241b50a7ab to release notes
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-01-17 12:39:50 +01:00
Jon Turney b7868e7410
Cygwin: Disable writing core dumps by default.
Change the default core limit from unlimited to 0 (disabled)
2024-01-16 14:07:05 +00:00
Jon Turney 91457377d6
Cygwin: Make 'ulimit -c' control writing a coredump
Pre-format a command to be executed on a fatal error to run 'dumper'
(using an absolute path).

Factor out executing a pre-formatted command, so we can use that for
invoking the JIT debugger in try_to_debug() (if error_start is present
in the CYGWIN env var) and to invoke dumper when a fatal error occurs.

On a fatal error, if the core file size limit is greater than 1MB,
invoke dumper to write a core dump. Otherwise, if that limit is greater
than 0, write a .stackdump file, as previously.

Adjust and clarify the associated documentation.

Also: Fix so that the error_start JIT debugger is now invoked, even when
ulimit -c is zero.

Also: Fix uses of console_printf() inside exec_prepared_command(). It's
output is written via the Windows console device, so needs to use
Windows-style line endings.

Also: consistently return non-zero from try_to_debug() if we debugged.

Future work: Truncate or remove the file written, if it exceeds the
maximum size set by the ulimit.

Future work: Using the words "fatal error" could probably be improved
on. This means exiting on one of the "certain signals whose default
action is to cause the process to terminate and produce a core dump
file".
2024-01-16 14:07:03 +00:00
Christian Franke d8c0fb090c Cygwin: introduce close_range(2)
This function closes or sets the close-on-exec flag for a specified
range of file descriptors.  It is available on FreeBSD and Linux.

Signed-off-by: Christian Franke <christian.franke@t-online.de>
2024-01-15 12:52:56 +01:00
Corinna Vinschen 832e91422c Cygwin: sparse support: enable automatic sparsifying of files on SSDs
Given that SSDs don't have a seek penalty, we can enable
automatic sparsifying of files on SSDs, even if the "sparse"
mount option is not set.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-11-30 22:37:35 +01:00
Corinna Vinschen 7f9caa4a36 Cygwin: open(2): reset sparseness on O_TRUNCated files
open(2) implements O_TRUNC by just reducing the size of the file
to 0, to make sure EAs stay available.

Turns out, file sparseness is not removed this way either, so add
code to do just that.

Fixes: 603ef545bd ("* fhandler.cc (fhandler_base::open): Never open files with  FILE_OVERWITE/FILE_OVERWRITE_IF.")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-11-28 10:55:33 +01:00
Corinna Vinschen e01c50c7b0 Cygwin: introduce fallocate(2)
First cut of the new, Linux-specific fallocate(2) function.
Do not add any functionality yet, except of basic handling
of FALLOC_FL_KEEP_SIZE.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-11-28 10:52:05 +01:00
Corinna Vinschen fedd7fae77 Cygwin: posix_fallocate: return ENODEV
The fhandler method ftruncate returns either EISDIR if it has been
called on directories, or EINVAL if called on files other than
regular files.  This matches what ftruncate(2) is supposed to return,
but it doesn't match posix_fallocate(3), which is supposed to return
ENODEV in both cases.

To accomplish that, return ENODEV from fhandler_base::ftruncate()
and convert it to EINVAL in ftruncate(2). In posix_fallocate(3),
convert EISDIR to ENODEV.

Fixes: 7636b58590 ("* autoload.cc (NtSetInformationFile): Define.")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-11-28 10:51:47 +01:00
Christian Franke 643275ed18 Cygwin: Document /dev/disk/by-* subdirectories
Signed-off-by: Christian Franke <christian.franke@t-online.de>
2023-11-17 20:37:29 +01:00
Corinna Vinschen 324ace778f Cygwin: rand(3): implement in terms of random(3)
This makes rand(3) ISO C compliant and adds locking to avoid
race conditions.

Reported-by: Bruno Haible <bruno@clisp.org>
Fixes: 8a0efa53e4 ("import newlib-2000-02-17 snapshot")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-11-14 17:52:48 +01:00
Mark Geisert c4008b8bc0 Fix profiler error() definition and usage
Minor updates to profiler and gmondump, which share some code:
- fix operation of error() so it actually works as intended
- resize 4K-size auto buffer reservations to BUFSIZ (==1K)
- remove trailing '\n' from 2nd arg on error() calls everywhere
- provide consistent annotation of Windows error number displays

Fixes: 9887fb27f6126 ("Cygwin: New tool: profiler")
Fixes: 087a3d76d7335 ("Cygwin: New tool: gmondump")
Signed-off-by: Mark Geisert <mark@maxrnd.com>
2023-11-14 11:48:11 +01:00
Corinna Vinschen d223f09590 Add release text for random(3) fix
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-11-13 20:01:54 +01:00
Christian Franke 7236f22f71 Cygwin: Document /dev/disk/by-id and /dev/disk/by-partuuid
Signed-off-by: Christian Franke <christian.franke@t-online.de>
2023-11-07 16:15:12 +01:00
Corinna Vinschen 2ef627c46e Cygwin: let feraiseexcept actually raise an exception
The exception handling inside of Cygwin functions marked as SIGFE
covers exceptions and lets the library code handle them gracefully.
If these functions want to raise an exception, they have to send a
signal explicitely via raise(3).

That's not what we want in feraiseexcept(). It triggers a floating
point exception explicitely by calling the i387 op "fwait".  Being
marked as SIGFE, this exception will be suppressed and the normal
exception handling won't kick in.

Fix this by moving feraiseexcept into the NOSIGFE realm.

Fixes: 0f81b5d4bc ("* Makefile.in (DLL_OFILES): Add new fenv.o module.")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-10-31 13:27:51 +01:00
Corinna Vinschen 60d1eeac6c Cygwin: cwd: avoid releasing the cwdstuff SRW Lock twice
cwdstuff::set has a code snippet handling the case where a process
can't create a handle to a directory, e. g., due to permissions.

Commit 88443b0a22 ("cwdstuff: Don't leave from setting the CWD
prematurely on init") introduced a special case to handle this
situation at process initialization. It also introduces an early
mutex release, which is not required, but ok, because we're in the
init phase. Releasing the mutex twice is no problem since the mutexes
are recursive.

Fast forward to commit 0819679a7a ("Cygwin: cwd: use SRWLOCK
instead of muto"). The mechanical change from a recursive mutex
to a non-recursive SRWLOCK failed to notice that this very specific
situation will release the SRWLOCK twice.

Remove the superfluous release action. While at it, don't set dir to
NULL, but h, since dir will get the value of h anyway later on.
Setting h to NULL may not be necessary, but better safe than sorry.

Reported-by: tryandbuy >tryandbuy@proton.me>
Fixes: 88443b0a22 ("cwdstuff: Don't leave from setting the CWD prematurely on init")
Fixes: 0819679a7a ("Cygwin: cwd: use SRWLOCK instead of muto")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-10-30 19:40:31 +01:00
Mark Geisert 27e8815535 Cygwin: Add relnote to 3.4.10 release file
Document the most recent update to include/sys/cpuset.h.
2023-09-09 23:28:55 +02:00