per
https://pubs.opengroup.org/onlinepubs/9799919799/functions/posix_close.html
Add a flag value to fhandler_*::close() and close_with_arch() methods,
taking -1 as default argument, used to indicate default close(2)
behaviour.
The only fhandlers capable of returning EINTR are the INET based
socket fhandlers. Handle -1 and POSIX_CLOSE_RESTART equivalent,
making close() and posix_close(POSIX_CLOSE_RESTART) behaving
identically.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
The isclosed flag is only used in pipe and FIFO code, so move the
flag down into the fhandler_pipe_fifo class.
Note that such a flag is not sufficient to avoid evil, like closing
an already closing fhandler from another thread. If we ever need this,
it has to be implemented threadsafe.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Deadlocks have been observed if the message queue functions are called
from different threads in the same process.
Remove incorrectly locking the descriptor table while accessing the
message queue fhandler, potentially calling blocking functions.
Fixes: 46f3b0ce85a9 ("Cygwin: POSIX msg queues: move all mq_* functionality into fhandler_mqueue")
Reported-by: Christian Franke <Christian.Franke@t-online.de>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Message queues are basically just files and in most cases can be handled
like normal files. So it was a mistake to set the "on-disk-device" flag
for them to fix the mq_unlink() problem reported in
https://cygwin.com/pipermail/cygwin/2025-January/257119.html
Rather, given that unlink() just checks if the object to be deleted
has an on-disk representation, make sure message queues are added to
the path_conv::isondisk() predicate.
This also reverts commit d870655f570f25393dcefbaf0b1dc807f277749c.
Fixes: d870655f570f ("Cygwin: path_conv: set on-disk-device flag for message queue files")
Reported-by: Christian Franke <Christian.Franke@t-online.de>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
The debug statement supposed to be printed when deleting with POSIX
semantics failed with STATUS_CANNOT_DELETE or STATUS_INVALID_PARAMETER
is in the wrong spot. While at it, simplify the related comment.
Fixes: 9fa22dba558f ("Cygwin: unlink: allow fallback from POSIX to default method")
Fixes: 527dd1b407e7 ("Cygwin: fix unlink in container")
Fixes: 87ab6c7b26bf ("Cygwin: log disabling posix semantics")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
New APIs tcgetwinsize/tcsetwinsize are added, which is added in
POSIX.1-2024.
Reviewed-by: Corinna Vinschen <corinna@vinschen.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
posix_devctl is now part of POSIX-1.2024, thus the requirement to
define _POSIX_26_C_SOURCE has been dropped.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Commentary wording now refers to tasks (i.e., threads) rather than
processes. This makes it somewhat easier to justify adding two kinds of
counters together. After researching what "load average" has meant over
time, we have what seems like a reasonable implementation, modulo
Windows differences to Linux. The best resource I found is:
https://www.brendangregg.com/blog/2017-08-08/linux-load-averages.html
At end of load_init(), obtain and discard the first measure of the
counters to deal with the first call always returning error, no data.
Follow this with a specific short delay so the next measure actually has
data to report.
At least one older version of Windows, i.e. Win10 Pro 21H1, has a different
name/location for the '% Processor Time' counter and is missing the
'Processor Queue Length' counter entirely. Code is changed to support
both possible locations of the former and treat the missing latter as always
reporting 0.0.
A release note is added for 3.5.6.
Reported-by: Mark Liam Brown <brownmarkliam@gmail.com>
Addresses: https://cygwin.com/pipermail/cygwin/2024-August/256361.html
Signed-off-by: Mark Geisert <mark@maxrnd.com>
Fixes: 4dc982ddf60b (Cygwin: loadavg: improve debugging of load_init)
This reinstates with one change commit 74017d229d5e ("Cygwin: mmap:
use 64K pages for bookkeeping"), which was reverted in commit
fd57eea5617a. The change is that in mmap_record::match, we now align
the record length to the 4K Windows page boundary rather than the 64K
Windows allocation granularity. The reason for this is explained in
an extensive comment in the code.
Addresses: https://cygwin.com/pipermail/cygwin-patches/2025q1/013240.html
Fixes: 74017d229d5e ("Cygwin: mmap: use 64K pages for bookkeeping")
Signed-off-by: Ken Brown <kbrown@cornell.edu>
It seems that current _cygtls::handle_SIGCONT() code sometimes falls
into a deadlock due to frequent TLS lock/unlock operation in the
yield() loop. With this patch, the yield() in the wait loop is placed
outside the TLS lock to avoid frequent TLS lock/unlock.
Fixes: 9ae51bcc51a7 ("Cygwin: signal: Fix another deadlock between main and sig thread")
Reviewed-by: Corinna Vinschen <corinna@vinschen.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Checking EPERM only makes sense if the file exists, so
let the EEXIST check change places with the EPERM check.
Add a debug statement to the EPERM condition.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Some checks in path_conv are checking for various properties
to generate a boolean value, mostly to indicate different
combinations of on-disk files and devices.
Simplify these checks and, especially, document them inline.
Drop the isdevice() check in favor of a new isondisk() check.
Fixes: 4fc922b2c8a5 ("Cygwin: POSIX msg queues: Convert mqd_t to a descriptor")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This simplifies further checks for on-disk-devices in places with
special handling for such files.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Validate the fd returned by cygheap_getfd operating on given mqd.
A release note is provided for 3.5.6.
Reported-by: Christian Franke <Christian.Franke@t-online.de>
Addresses: https://cygwin.com/pipermail/cygwin/2025-January/257090.html
Signed-off-by: Mark Geisert <mark@maxrnd.com>
Fixes: 46f3b0ce85a9 (Cygwin: POSIX msg queues: move all mq_* functionality into fhandler_mqueue)
The commit a22a0ad7c4f0 was not entirely correct. Even with the patch,
some hangs still occur. This patch overrides the previous commit along
with the patch that makes cygwait() reentrant, to fix these hangs.
Addresses: https://cygwin.com/pipermail/cygwin/2024-December/256954.html
Addresses: https://cygwin.com/pipermail/cygwin/2024-December/256987.html
Fixes: d243e51ef1d3 ("Cygwin: signal: Fix deadlock between main thread and sig thread")
Fixes: a22a0ad7c4f0 ("Cygwin: signal: Do not handle signal when __SIGFLUSHFAST is sent")
Reported-by: Daisuke Fujimura <booleanlabel@gmail.com>
Reported-by: Jeremy Drake <cygwin@jdrake.com>
Reviewed-by: Corinna Vinschen <corinna@vinshcen.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
To allow cygwait() to be called in the signal handler, a locally
created timer is used instead of _cygtls::locals.cw_timer if it is
in use.
Co-Authored-By: Corinna Vinschen <corinna@vinschen.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
The call to TranslateNameW in s4uauth can fail and the code
leaves the function indicating an error, if so. It just
misses to set errno in this case, so add that.
Fixes: 0fb497165f85 ("Cygwin: seteuid: use Kerberos/MsV1_0 S4U authentication by default")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
If the macros REENTRANT_SYSCALLS_PROVIDED and MISSING_SYSCALL_NAMES are defined some
_reent_*-functions are replaced by the system-call and this leads to compile-warning
or a runtime-failure.
* newlib/libc/stdio/fopen.c _open_r is replaces by open(), declared in <fcntl.h>
* newlib/libc/stdio64/fopen64.c ditto
* newlib/libc/stdio/rename.c _rename_r is rename() itself; i.e, fix recursion
Use "Cygwin Setup program" and add a link to the homepage in some
cases.
Reported-by: David Dyck <david.dyck@gmail.com>
Reviewed-by: Jon Turney <jon.turney@dronecode.org.uk>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
When Microsoft started to claim the "sshd" service name, we had
to rename our service to "cygsshd" but we never updated the docs.
Make sure the docs reflect the changed service name and fix a
few bumpy expression.
Reported-by: Mario Emmenlauer <mario@emmenlauer.de>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
POSIX®.1-2024 now defines posix_spawn_file_actions_addchdir and
posix_spawn_file_actions_addfchdir. Add these interfaces to spawn.h,
guarded as POSIX 202405 symbols.
Cygwin-only: Export them as aliases of the *_np counterparts. Bump
API minor.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
FS_COMPR_FL is the Linux-compatible macro name. Redefine
FS_COMPRESSED_FL as an alias of FS_COMPR_FL for backward
compatibility.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This reverts commit 74017d229d5e46867c8a3ec01bf653e4392bf14c.
After this commit, gdb exits with a fatal error on startup.
Addresses: https://cygwin.com/pipermail/cygwin-patches/2025q1/013240.html
Fixes: 74017d229d5e ("Cygwin: mmap: use 64K pages for bookkeeping")
Signed-off-by: Ken Brown <kbrown@cornell.edu>
The code merging permissions relies on `pos' being set to the number
of current entries in the local aclent_t buffer. Commit 0e6d36766c83
("Cygwin: get_posix_access: move umask masking to the end") moved that
code to run earlier, but neglected to move setting `pos' correctly
as well.
Make sure to set `pos' inside the code block, as well as in the
final array size check, so `pos' is set correctly where it belongs.
Fixes: 0e6d36766c83 ("Cygwin: get_posix_access: move umask masking to the end")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
umask handling for new file gets overriden by subsequent merging of
permissions in Windows-generated ACLs. Fix this by performing
umask masking after all other ACL manipulations.
Fixes: a8716448cecc ("Simplify "Windows-standard-like" permissions")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Add a second loop to the code snippet merging permissions in old-style
or Windows-generated ACLs. This loop fixes up default ACL permissions
created from ACEs which are valid for the directory itself, as well as
getting inherited to child objects.
The FULL_ACE bit utilized for this is removed from the ACE at the
end of the function, together with the temporary DENY bits.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This reverts commit 971d2dffea7848270aa9dfb5c14dcd946c8971c0.
This patch was supposed to fix lots of FAILs in our own
testsuite/winsup.api/ltp/umask03.c test. The reason was
that umask masking in get_posix_access when generating new files
was overriden by later code in the same function, merging
permissions in old-style or Windows generated ACLs.
However, the solution to skip merging was not the right thing,
because this breaks handling of Windows-generated ACLs.
Rather, umask masking should be performed pretty late, certainly
after merging permissions. This will be done by a followup patch.
Fixes: 971d2dffea78 ("Cygwin: get_posix_access: do not merge permissions for just created files")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Setting the a_id in the default:user and default:group entries to
the actual uid and gid of the current owner/group doesn't make
sense. Change to ACL_UNDEFINED_ID.
Fixes: bc444e5aa4ca ("Reapply POSIX ACL changes.")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
The permissions of entries for SYSTEM and the Administrators group
are not added to the CLASS_OBJ entry, so they don't set the class
perms to rwx all the time.
This shouldn't be done for default perms, otherwise the resulting
permissions when generating new files might be surprisingly restricted
for Admins and SYSTEM.
Fixes: bc444e5aa4ca ("Reapply POSIX ACL changes.")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
When generating a default:group (Windows: CREATOR GROUP) ACL entry,
make sure to copy over user perms to the new default group entry.
Fixes: bc444e5aa4ca ("Reapply POSIX ACL changes.")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
After the commit d243e51ef1d3, zsh sometimes hangs at startup. This
occurs because SIGCHLD, which should trigger sigsuspend(), is handled
in cygwait() that is used to wait for a wakeup event in sig_send(),
even when __SIGFLUSHFAST is sent. Despite __SIGFLUSHFAST being
required to return before handling the signal, this does not happen.
With this patch, if the signal currently being sent is __SIGFLUSHFAST,
do not handle the received signal and keep it asserted after the
cygwait() for the wakeup event. Apply the same logic to the cygwait()
in the retrying loop for WriteFile() as well.
Addresses: https://cygwin.com/pipermail/cygwin/2024-December/256954.html
Fixes: d243e51ef1d3 ("Cygwin: signal: Fix deadlock between main thread and sig thread")
Reported-by: Daisuke Fujimura <booleanlabel@gmail.com>
Reviewed-by: Corinna Vinschen <corinna@vinschen.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
It was convenient to use pages of size 4K (Windows page size) for
bookkeeping when we were using filler pages. But all references to
filler pages were removed in commit ceda26c9d35b ("Cygwin: mmap:
remove __PROT_FILLER and the associated methods"), so this is no
longer necessary. Switch to using pages of size 64K (Windows
allocation granularity) for everything.
Signed-off-by: Ken Brown <kbrown@cornell.edu>
unlink_nt() and rename2 () both check for the FILE_SUPPORTS_OPEN_BY_FILE_ID
flag to use POSIX delete/rename semantics. Both erroneously check the flag
against the file attributes using has_attributes().
Given that this flag is a filesystem flag, check using fs_flags() instead.
Fixes: fe2545e9faaf ("Cygwin: don't use unlink/rename POSIX semantics on certain NTFS")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Save the result of mmap_record::find_unused pages, and then pass that
result to the appropriate version of mmap_record::map_pages. Add a
new parameter of type off_t to the latter to make this possible, and
change its return type from off_t to bool. This saves map_pages from
having to call find_unused_pages again.
Signed-off-by: Ken Brown <kbrown@cornell.edu>