Commit Graph

21772 Commits

Author SHA1 Message Date
Corinna Vinschen 343a2a5581 Cygwin: strptime: make sure to fail on invalid input digits
conv_num returns NULL if the input is invalid, e. g., the
numbers are out of range.  However, the code fails to test
this in a lot of places.

Rather than adding checks all over the place, rename conv_num
to __conv_num and create a wrapper macro conv_num to perform
the task of error checking.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-02-21 19:39:37 +01:00
Alexey Lapshin acf176104f strptime: fix am/pm converting to 24-hour system
Fix the issue of parsing 08:00AM, which currently gives a 20:00 representation.
2024-02-21 15:52:14 +01:00
Corinna Vinschen c90b20192d Cygwin: getgrent/getpwent: avoid local enumeration on DCs
...if we're supposed to enumerate the AD accounts anyway.  This
avoids some useless duplication.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-02-20 23:55:51 +01:00
Corinna Vinschen 15e82eef3a Cygwin: getgrent: fix local SAM enumeration on domain member machines
Don't skip output of local SAM groups on domain member machines.
They can have valid, user-defined groups in their SAM.  Just
skip builtin groups if we're enumerating AD as well.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-02-20 23:51:33 +01:00
Corinna Vinschen 5cc6996987 Cygwin: passwd/group: drop Capability SIDs
Capability SIDs (S-1-15-3-...) have been introduced with
Windows 10 1909.  They don't resolve with LookupAccountSid.
We don't need them and they don't map gracefully into out
POSIX account namespace.  Also, add code to make sure to
filter them out *iff* they become resolvable at one point.

While at it, slightly reorder code for non-resolving SIDs
by authority values.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-02-20 17:25:23 +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 f9542a2e8e Cygwin: pty: Re-fix the last bug regarding nat-pipe.
Fixes: f907b5f405 ("Cygwin: pty: Fix failure to revert from nat-pipe in disable_pcon.")
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-02-16 18:18:26 +09:00
Takashi Yano f907b5f405 Cygwin: pty: Fix failure to revert from nat-pipe in disable_pcon.
Fixes: a903878948 ("Cygwin: pty: Additional fix for transferring input at exit.");
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-02-16 17:15:29 +09:00
Takashi Yano f3ba4db2e2 Cygwin: console: Fix a bug that 64th console cannot be handled.
Fixes: 930e553da8 ("Cygwin: console: Unify EnumWindows() callback functions.");
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-02-16 04:06:01 +09: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 930e553da8 Cygwin: console: Unify EnumWindows() callback functions.
Previously, three similar callback fuctions were used in console
code. This patch unifies these functions to ease maintenance cost.

Fixes: 8aad3a7ede ("Cygwin: console: Fix a problem that minor ID is incorrect in ConEmu.")
Suggested-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-02-14 23:18:23 +09:00
Takashi Yano 054f4801e6 Cygwin: pty: Make GNU screen and tmux work in ConEmu cygwin-connector.
Fixes: 3721a756b0 ("Cygwin: console: Make the console accessible from other terminals.")
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-02-14 23:18:04 +09:00
Corinna Vinschen 2a2a6486a0 Cygwin: accommodate gcc -Og option
All three warnings produced with -Og are false positives.
But given we're using -Werror unconditionally it's better
to be safe than sorry.

Reported-by: Kevin Ushey <kevinushey@gmail.com>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-02-14 14:00:34 +01:00
Corinna Vinschen 4e77fa9b8b Cygwin: find_fast_cwd: don't run assembler checking code on ARM64
https://cygwin.com/pipermail/cygwin/2024-February/255397.html
reports a crash on ARM64 probably related to checking x86_64
code on the x86_64 emulator on AArch64.

At least for testing, pull the code checking the host HW
up to be called before trying to evaluate assembler code.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-02-13 16:48:15 +01:00
Takashi Yano 8aad3a7ede Cygwin: console: Fix a problem that minor ID is incorrect in ConEmu.
Previously, minor device number of console was not assigned correctly
in ConEmu environment. This is because console window of ConEmu is
not enumerated by EnumWindows(). This patch fixes the issue.

Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-02-13 23:27:44 +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 8e24d162f4 Cygwin: pty: Fix potential handle leak regarding CallNamedPipe().
In pty master_thread, 6 handles are duplicated when CallNamedPipe()
requests that. Though some of them are not used so should be closed,
they were not. This causes handle leak potentially.

Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-02-13 23:24:45 +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 10c8c1cf4f include/ansidecl.h: import from binutils-gdb
Import include/ansidecl.h version from 2024-01-04,
binutils-gdb commit fd67aa1129fd.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-02-12 13:45:10 +01:00
Corinna Vinschen dace0bfa6c Cygwin: dumper: use void* in place of PTR
The definition of PTR has been dropped from newer versions
of ansidecl.h.

Convert definition of print_section_name to use void * instead,
as required by bfd_map_over_sections.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-02-12 13:43:03 +01:00
Corinna Vinschen bfb68a9e6e getlocalename_l: fix _reent for _REENT_SMALL targets
The new _MB_CAPABALE-only _misc_reent member getlocalename_l_buf was
incorrectly initialized in the _REENT_INIT_MISC macro, so the build
failed for _REENT_SMALL targets, independet of the _MB_CAPABALE setting.

Fixes: 71511d4ac8 ("getlocalename_l: implement per SUS Base Specifications Issue 8 draft")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-02-05 10:38:28 +01:00
Corinna Vinschen 35b10bb8c6 Cygwin: fix typo in winjitdebug description
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-02-03 20:28:46 +01: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
Corinna Vinschen cb34100be8 Cygwin: reorder list of CYGWIN env var options alphabetically again
This has been turned upside down for a short while.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-02-03 19:54:50 +01:00
Johannes Schindelin 07ea90a5d2 Cygwin: Do not show Error dialogs by default
...in a non-Cygwin child process.  Backported from MSYS2.
Downstream commit message follows.

In https://github.com/msys2/msys2-runtime/pull/18, we discussed a change
that would allow default Windows error handling of spawned processes to
kick in (such as registered JIT debuggers). We even agreed that it would
make sense to hide this functionality behind a flag, `winjitdebug`.

However, when this got upstreamed as 21ec498d7f (cygwin: use
CREATE_DEFAULT_ERROR_MODE in spawn, 2020-12-09), that flag was deemed
unnecessary.

But it would appear that it _is_ necessary: As reported in
https://github.com/msys2/MSYS2-packages/pull/2414#issuecomment-810841296
this new behavior is pretty disruptive e.g. in CI scenarios.

So let's introduce that `winjitdebug` flag (settable via the environment
variable `MSYS`) at long last.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-02-03 19:54:50 +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
Takashi Yano c2be9bf5eb Cygwin: console: Avoid slipping past disable_master_thread check.
If disable_master_thread flag is set between the code checking that
flag not be set and the code acquiring input_mutex, input record is
processed once after setting disable_master_thread flag. This patch
prevents that.

Fixes: d4aacd50e6 ("Cygwin: console: Add missing input_mutex guard.")
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-02-03 01:01:53 +09:00
Takashi Yano 084f848ab9 Cygwin: console: Fix exit code for non-cygwin process.
If non-cygwin process is executed in console, the exit code is not
set correctly. This is because the stub process for non-cygwin app
crashes in fhandler_console::set_disable_master_thread() due to NULL
pointer dereference. This bug was introduced by the commit:
3721a756b0 ("Cygwin: console: Make the console accessible from
other terminals."), that the pointer cons is accessed before fixing
when it is NULL. This patch fixes the issue.

Fixes: 3721a756b0 ("Cygwin: console: Make the console accessible from other terminals.")
Reported-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-02-02 14:28:39 +09:00
Corinna Vinschen c414e1b972 Cygwin: ps: avoid long lines on tty
If stdout is a tty, restrict line output to tty width.

Also, rename a weird buffer name.
2024-02-01 17:20:17 +01:00
Corinna Vinschen 6d0769efa9 Cygwin: ps: make sure later format flags override earlier format flags
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-02-01 17:17:57 +01:00
Corinna Vinschen 92b7ba4bb8 Cygwin: CW_CMDLINE_ALLOC: fix a pontentially undefined return value
cmdline has to be initialized, otherwise the return value is
undefined in case generating the command line fails.

Fixes: 732afede93 ("Cygwin: redefine CW_CMDLINE to CW_CMDLINE_ALLOC")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-02-01 13:34:52 +01:00
Corinna Vinschen 76760707ec Cygwin: document showing command line on ps -f
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-02-01 12:44:28 +01: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 61fd870296 Cygwin: commune_process: don't use IsBadStringPtr
IsBadStringPtr is deprecated and just gives a wrong sense
of memory safety.  Replace with check for NULL pointer.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-01-31 20:11:58 +01:00
Corinna Vinschen b2476bc523 Cygwin: globals: make __progname an alias of program_invocation_short_name
On Linux, __progname and program_invocation_short_name are just
different exported names of the same string.  Do the same in Cygwin.
This requires to tweak the mkglobals_h so as not to touch the
EXPORT_ALIAS expression.  Also, use the base variable
program_invocation_short_name throughout.  __progname is just
the export for getopt.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-01-31 20:11:58 +01:00
Corinna Vinschen bded8091c4 Cygwin: cygwin_GetCommandLineW/A: don't rely on __argv[0] content
Since it's possible to change the __argv array, we should not rely
on __argv[0] actually representing the windows executable path in
any way.  Use the real path stored in global_progname instead.

Fixes: 521953a83a ("* common.din: Export GetCommandLine{A,W}.")
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 732afede93 Cygwin: redefine CW_CMDLINE to CW_CMDLINE_ALLOC
Make sure to

- append a trailing \0 as with Windows multistrings, so the end of
  the string can be recognized by the caller, and

- allocate cmdline on the user heap so the caller can free the
  multistring after usage.

Fixes: 831d6fa520 ("* external.cc (cygwin_internal): Implement CW_CMDLINE.")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-01-31 20:11:58 +01:00
Corinna Vinschen b1d64ac265 Cygwin: pinfo: use stpcpy where appropriate
...rather than strcpy/strchr.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-01-31 20:11:58 +01:00
Corinna Vinschen 3600654b78 sys/stat.h: drop __INSIDE_CYGWIN__ guards
These were only necessary until we dropped 32 bit Cygwin.

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 219b2dff77 Cygwin: devices.h: drop useless mode check
use IFTODT to generate type from mode.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-01-31 20:11:57 +01:00
Corinna Vinschen 5353cb8ef8 Cygwin: dirent.h: make definition of struct __DIR opaque
The content of DIR should never have been exposed into userspace.
Move struct __DIR to local dirent.h and only keep forward declaration
in exported dirent.h.

This allows to tweak the structure in future, for instance, to
add thread-safety.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-01-31 20:11:57 +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 7e40e0169a Cygwin: implement dirent.d_reclen
This change is in preparation of adding posix_getdents() from
the upcoming POSIX Base Specification Issue 8.

- Add d_reclen
- Add GLibC compatible test macros for dirent members
- Bump dirent version
- Set d_reclen to the fixed size of the dirent struct
  We can do that because the size is a multiple of 8, so it fits
  snugly in the buffer filled by posix_getdents and keep the
  alignement.

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 71511d4ac8 getlocalename_l: implement per SUS Base Specifications Issue 8 draft
#include <locale.h>
  const char *getlocalename_l(int category, locale_t locobj);

Most notably, we need a per-thread space to store the string
returned if locobj is LC_GLOBAL_LOCALE.  No errors are defined
for getlocalename_l.  So we can't use buffer allocation which
might lead to an ENOMEM error.  We have to use a "static" buffer
in the per-thread state.

Note that the feature test macro in locale.h is not quite correct.
This needs to be fixed as soon as the

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-01-31 20:11:57 +01:00
Corinna Vinschen cb54031e01 Cygwin: path: convert symlink_info to class
encapsulate everything

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-01-31 20:11:57 +01:00