Commit Graph

8689 Commits

Author SHA1 Message Date
Corinna Vinschen 530b866c8e Cygwin: fix quoting when starting invisible console process
fhandler_console::create_invisible_console_workaround() does not use the
lpApplicationName parameter and neglects to quote its command name on
lpCommandLine in the call to CreateProcessW.

Given CreateProcessW's brain-dead method to evaluate the application
path given on the command line, this opens up a security problem if
Cygwin is installed into a path with spaces in it.

Fix this by using the lpApplicationName parameter and quoting of the
application path in the lpCommandLine parameter (used as argv[0] in
the called console helper.

For extended paranoia, make the argument string array big enough to
fit full 64 bit pointer values into it.  Handles usually only use
the lower 32 bit, but better safe than sorry.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-11-05 11:51:55 +01:00
Corinna Vinschen 7a26e19d4f Cygwin: devices: drop MAX_CONSOLES and fix FH_CONS_MAX
FH_CONS_MAX should refelect the fact that we allow 128 consoles, even if
it's unused.

Suggested-by: Achim Gratz <Stromeko@nexgo.de>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-11-04 10:34:59 +01:00
Corinna Vinschen 57640bee75 Cygwin: fix process parent/child relationship after execve
Commit 5a0f2c00aa "Cygwin: fork/exec: fix child process permissions"
removed the PROCESS_DUP_HANDLE handle permission of the parent process
handle in the child to avoid a security problem.

It turned out that this broke the following scenario: If a process forks
and then the parent execs, the child loses the ability to register the
parent's death.  To wit, after the parent died the child process does
not set its own PPID to 1 anymore.

The current exec mechanism copies required handle values (handles to
keep contact to the child processes) into the child_info for the
about-to-be-exec'ed process.  The exec'ed process is supposed to
duplicate these handles.  This fails, given that we don't allow the
exec'ed process PROCESS_DUP_HANDLE access to the exec'ing process since
commit 5a0f2c00aa.

The fix is to avoid the DuplicateHandle calls in the exec'ed process.

This patch sets the affected handles to "inheritable" in the exec'ing
process at exec time.  The exec'ed process just copies the handle values
and resets handle inheritance to "non-inheritable".  The exec'ing
process doesn't have to reset handle inheritance, it exits after setting
up the exec'ed process anyway.

Testcase: $ ssh-agent /bin/sleep 3

ssh-agent forks and the parent exec's sleep.  After sleep exits, `ps'
should show ssh-agent to have PPID 1, and eventually ssh-agent exits.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-11-02 19:55:24 +01:00
Anton Lavrentiev via cygwin-patches fe239aef1b Cygwin: getpriority() consistent with process priority
https://cygwin.com/ml/cygwin/2019-08/msg00122.html
2019-10-31 21:40:22 +01:00
Achim Gratz 25ce0e1213 Cygwin: Provide more COM devices
Provide for 128 COM devices since Windows likes to create lots of these
over time (one per identifiable device and USB port).
2019-10-23 10:05:42 +02:00
Ken Brown b61dc22ada Cygwin: spawnvp, spawnvpe: fail if executable is not in $PATH
Call find_exec with the FE_NNF flag to enforce a NULL return when the
executable isn't found in $PATH.  Convert NULL to "".  This aligns
spawnvp and spawnvpe with execvp and execvpe.
2019-10-18 10:38:52 -04:00
Takashi Yano 43d7f33e2c Cygwin: pty: Change the timing of clear screen. 2019-10-16 15:15:47 -04:00
Takashi Yano 9bedd6807d Cygwin: pty: Avoid detach console in the process running as service. 2019-10-16 15:15:47 -04:00
Ken Brown c561a625af Cygwin: mkdir and rmdir: treat drive names specially
If the directory name has the form 'x:' followed by one or more
slashes or backslashes, and if there's at least one backslash, assume
that the user is referring to 'x:\', the root directory of drive x,
and don't strip the backslash.

Previously all trailing slashes and backslashes were stripped, and the
name was treated as a relative file name containing a literal colon.

Addresses https://cygwin.com/ml/cygwin/2019-08/msg00334.html.
2019-10-07 16:09:41 -04:00
Ken Brown e82a0c959a Cygwin: document recent changes to format_proc_cpuinfo 2019-10-07 16:06:28 -04:00
Brian Inglis 2160c52a49 fhandler_proc.cc(format_proc_cpuinfo): or model extension bits
or model extension bits into model high bits instead of adding
arithmetically like family extension.
2019-10-07 15:50:33 -04:00
Brian Inglis 8cf614a88b fhandler_proc.cc(format_proc_cpuinfo): comment flags not reported
Comment out flags not reported by Linux in cpuinfo, although some
flags may not be used at all by Linux.
2019-10-07 15:50:33 -04:00
Brian Inglis f723e3caae fhandler_proc.cc(format_proc_cpuinfo): add feature flags
Add 99 feature flags including AVX512 extensions, AES, SHA with 20
cpuid calls.
2019-10-07 15:50:33 -04:00
Brian Inglis 08d1ae0543 fhandler_proc.cc(format_proc_cpuinfo): use feature test print macro
Add feature test print macro that makes feature, bit, and flag text
comparison and checking easier.  Handle as common former Intel only
feature flags also supported on AMD.  Change order and some flag names
to agree with current Linux.
2019-10-07 15:50:33 -04:00
Brian Inglis b8ccc22762 fhandler_proc.cc(format_proc_cpuinfo): add microcode
Add microcode from Windows registry Update Revision REG_BINARY.
2019-10-07 15:50:33 -04:00
Brian Inglis 9682c25bb3 fhandler_proc.cc(format_proc_cpuinfo): add bogomips
Add bogomips which has been cpu MHz*2 since Pentium MMX.
2019-10-07 15:50:33 -04:00
Brian Inglis 70e834ea7c fhandler_proc.cc(format_proc_cpuinfo): round cpu MHz
Round cpu MHz to correct Windows and match Linux cpuinfo.
2019-10-07 15:50:32 -04:00
Brian Inglis 7a0496f78f fhandler_proc.cc(format_proc_cpuinfo): fix AMD physical cores count
Fix AMD physical cores count documented as core_info low byte + 1.
2019-10-07 15:50:32 -04:00
Brian Inglis 74aa6e3cdb fhandler_proc.cc(format_proc_cpuinfo): fix cpuid level count
Fix cpuid level count as number of non-zero leafs excluding sub-leafs.
2019-10-07 15:50:32 -04:00
Brian Inglis acc8849f84 fhandler_proc.cc(format_proc_cpuinfo): fix cache size
Fix cache size return code handling and make AMD/Intel code common.
2019-10-07 15:50:32 -04:00
Takashi Yano df5c79f30c Cygwin: Fix signal handling issue introduced by PTY related change.
- After commit 4186409101, there is a
  regression in signal handling reported in
  https://www.cygwin.com/ml/cygwin/2019-10/msg00010.html. This patch
  fixes the issue.
2019-10-03 09:28:10 -04:00
Ken Brown 6061f9c76f Document the last bug fix 2019-09-27 13:36:45 -04:00
Ken Brown 283cb372e4 Cygwin: normalize_win32_path: improve error checking
If the source path starts with the Win32 long path prefix '\\?\' or
the NT object directory prefix '\??\', require the prefix to be
followed by 'UNC\' or '<drive letter>:\'.  Otherwise return EINVAL.

This fixes the assertion failure in symlink_info::check that was
reported here:

  https://cygwin.com/ml/cygwin/2019-09/msg00228.html

That assertion failure was caused by normalize_win32_path returning a
path with no backslashes when the source path was '\\?\DRIVE'.
2019-09-26 08:52:13 -04:00
Takashi Yano e1a0775dc0 Cygwin: pty: Fix PTY so that cygwin setup shows help with -h option.
- After commit 169d65a577, cygwin
  setup fails to show help message when -h option is specified, as
  reported in https://cygwin.com/ml/cygwin/2019-09/msg00248.html.
  This patch fixes the problem.
2019-09-26 08:42:52 -04:00
Ken Brown a9724c3904 Document the last change 2019-09-24 20:04:28 -04:00
Ken Brown d1b5feef82 Cygwin: rmdir: fail if last component is a symlink, as on Linux
If the last component of the directory name is a symlink followed by a
slash, rmdir now fails, following Linux but not POSIX, even if the
symlink resolves to an existing empty directory.

mkdir was similarly changed in 2009 in commit
52dba6a5c4.  Modify a comment to clarify
the purpose of that commit.

Addresses https://cygwin.com/ml/cygwin/2019-09/msg00221.html.
2019-09-24 20:03:30 -04:00
Ken Brown 9f24260ee9 Cygwin: remove old cruft from path_conv::check
Prior to commit b0717aae, path_conv::check had the following code:

      if (strncmp (path, "\\\\.\\", 4))
        {
          /* Windows ignores trailing dots and spaces in the last path
             component, and ignores exactly one trailing dot in inner
             path components. */
          char *tail = NULL;
          [...]
          if (!tail || tail == path)
            /* nothing */;
          else if (tail[-1] != '\\')
            {
              *tail = '\0';
          [...]
        }

Commit b0717aae0 intended to disable this code, but it inadvertently
disabled only part of it.  In particular, the declaration of the local
tail variable was in the disabled code, but the following remained:

          if (!tail || tail == path)
            /* nothing */;
          else if (tail[-1] != '\\')
            {
              *tail = '\0';
          [...]
        }

[A later commit removed the disabled code.]

The tail variable here points into a string different from path,
causing that string to be truncated under some circumstances.  See

  https://cygwin.com/ml/cygwin/2019-09/msg00001.html

for more details.

This commit fixes the problem by removing the leftover code
that was intended to be removed in b0717aae.
2019-09-21 13:09:09 -04:00
Takashi Yano 4186409101 Cygwin: Fix incorrect TTY for non-cygwin process.
- After commit d4045fdbef, the TTY
  displayed by ps command is incorrect if the process is non-cygwin
  process. This patch fixes this issue.
2019-09-20 17:48:37 -04:00
Takashi Yano aa529d00ea Cygwin: console: Make console input work in GDB and strace.
- After commit 2232498c71, console
  input cause error in GDB or strace. This patch fixes this issue.
2019-09-20 17:48:37 -04:00
Takashi Yano 81c55654e6 Cygwin: pty: Add missing guard when PTY is in the legacy mode. 2019-09-20 16:18:47 -04:00
Takashi Yano b757a21d85 Cygwin: pty: Add charset conversion for console apps in legacy PTY. 2019-09-20 16:18:47 -04:00
Takashi Yano 24554ab923 Cygwin: pty: Unify the charset conversion codes into a function. 2019-09-20 16:18:47 -04:00
Takashi Yano ac5357b9fe Cygwin: pty: Make GDB work again on pty. 2019-09-20 16:18:47 -04:00
Takashi Yano 831b1569dc Cygwin: pty: Avoid potential segfault in PTY code when ppid = 1. 2019-09-20 16:18:47 -04:00
Takashi Yano 1a44ad03e0 Cygwin: console: Revive Win7 compatibility.
- The commit fca4cda7a4 broke Win7
  compatibility. This patch fixes the issue.
2019-09-19 22:17:54 -04:00
Ken Brown bbc625da81 Cygwin: document last change 2019-09-15 13:40:12 -04:00
Achim Gratz d5f84126e5 winsup/cygwin/times.cc (times): follow Linux and allow for a NULL buf argument
Adresses the problem reported here:

  https://cygwin.com/ml/cygwin/2019-09/msg00141.html
2019-09-15 13:12:03 -04:00
Takashi Yano 70cd49e204 Cygwin: pty: Use autoload feature for pseudo console system calls.
- The autoload feature is used rather than GetModuleHandle(),
  GetProcAddress() for CreatePseudoConsole(), ResizePseudoConsole()
  and ClosePseudoConsole().
2019-09-15 11:12:45 -04:00
Takashi Yano fac5a01aec Cygwin: pty: Correct typos that do not fit the coding style. 2019-09-15 11:12:20 -04:00
Takashi Yano 244f03627d Cygwin: pty: Change the timing of clearing screen.
- The code which clears screen is moved from reset_switch_to_pcon()
  to fixup_after_exec() because it seems not too early even at this
  timing.
2019-09-15 11:09:06 -04:00
Takashi Yano d83c45b46c Cygwin: pty: Use system NLS function instead of PTY's own one.
- Since calling system __loadlocale() caused execution error,
  PTY used its own NLS function. The cause of the error has been
  found, the corresponding code has been rewritten using system
  function.
2019-09-15 11:09:06 -04:00
Takashi Yano 6983433f8e Cygwin: pty: Fix bad file descriptor error in some environment.
- The bad file descriptor problem reported in:
  https://cygwin.com/ml/cygwin-patches/2019-q3/msg00104.html
  was recurring. Fixed again.
2019-09-15 11:09:06 -04:00
Mark Geisert a083a4f266 Cygwin: fix CPU_SET macro visibility
The CPU_SET macros defined in Cygwin's include/sys/cpuset.h must not
be visible in an application's namespace unless _GNU_SOURCE has been
#defined.  Internally this means wrapping them in #if __GNU_VISIBLE.
2019-09-14 11:31:17 -04:00
Takashi Yano fca4cda7a4 Cygwin: console: Fix read() in non-canonical mode.
- In non-canonical mode, cygwin console returned only one character
  even if several keys are typed before read() called. This patch
  fixes this behaviour.
2019-09-14 09:19:04 -04:00
Takashi Yano 3355a6d4b9 Cygwin: pty: Switch input and output pipes individually.
- Previously, input and output pipes were switched together between
  the traditional pty and the pseudo console. However, for example,
  if stdin is redirected to another device, it is better to leave
  input pipe traditional pty side even for non-cygwin program. This
  patch realizes such behaviour.
2019-09-14 09:19:04 -04:00
Takashi Yano bd31b7c5d5 Cygwin: pty: Fix screen alternation while pseudo console switching.
- If screen alternated while pseudo console switching, it sometimes
  failed. This might happen when the output of the non-cygwin program
  is piped to less. This patch fixes this issue.
2019-09-14 09:17:27 -04:00
Takashi Yano b088f50426 Cygwin: pty: Fix the behaviour of Ctrl-C in the pseudo console mode.
- When the I/O pipe is switched to the pseudo console side, the
  behaviour of Ctrl-C was unstable. This rarely happens, however,
  for example, shell sometimes crashes by Ctrl-C in that situation.
  Furthermore, Ctrl-C was ignored if output of non-cygwin program
  is redirected to pipe. This patch fixes these issues.
2019-09-14 08:58:35 -04:00
Takashi Yano f39a694c46 Cygwin: pty: Make SetConsoleCursorPosition() to be hooked.
- Win32 API SetConsoleCursorPosition() injects ANSI escape sequence
  to pseudo console. Therefore, it should be added to the API list
  to be hooked.
2019-09-06 12:31:17 -04:00
Takashi Yano 46d3953d64 Cygwin: pty: Make sure to show system error messages
- Forcibly attach to pseudo console in advance so that the error
  messages by system_printf() are displayed to screen reliably.
  This is needed when stdout is redirected to another pty. In this
  case, process has two ptys opened. However, process can attach
  to only one console. So it is necessary to change console attached.
2019-09-05 11:42:26 -04:00
Takashi Yano b7e4294200 Cygwin: pty: Fix potential state mismatch regarding pseudo console.
- PTY with pseudo console support sitll has problem which potentially
  cause state mismatch between state variable and real console state.
  This patch fixes this issue.
2019-09-05 13:59:37 +02:00
Takashi Yano 915fcd0ae8 Cygwin: pty: Fix select() with pseudo console support.
- select() did not work correctly when both read and except are
  polled simultaneously for the same fd and the r/w pipe is switched
  to pseudo console side. This patch fixes this isseu.
2019-09-05 13:59:37 +02:00
Takashi Yano 433c6b8e0a Cygwin: pty: Disable clear screen on new pty if TERM=dumb or emacs*.
- Pseudo console support introduced by commit
  169d65a577 shows garbage ^[[H^[[J in
  some of emacs screens. These screens do not handle ANSI escape
  sequences. Therefore, clear screen is disabled on these screens.
2019-09-05 13:59:37 +02:00
Takashi Yano d4045fdbef Cygwin: pty: Add a workaround for ^C handling.
- Pseudo console support introduced by commit
  169d65a577 sometimes cause random
  crash or freeze by pressing ^C while cygwin and non-cygwin
  processes are executed simultaneously in the same pty. This
  patch is a workaround for this issue.
2019-09-04 16:01:07 +02:00
Takashi Yano 83b2d576c8 Cygwin: pty: Limit API hook to the program linked with the APIs.
- API hook used for pseudo console support causes slow down.
  This patch limits API hook to only program which is linked
  with the corresponding APIs. Normal cygwin program is not
  linked with such APIs (such as WriteFile, etc...) directly,
  therefore, no slow down occurs. However, console access by
  cygwin.dll itself cannot switch the r/w pipe to pseudo console
  side. Therefore, the code to switch it forcely to pseudo
  console side is added to smallprint.cc and strace.cc.
2019-09-04 15:59:38 +02:00
Takashi Yano 583102e7c9 Cygwin: pty: Fix state management for pseudo console support.
- Pseudo console support introduced by commit
  169d65a577 has some bugs which
  cause mismatch between state variables and real pseudo console
  state regarding console attaching and r/w pipe switching. This
  patch fixes this issue by redesigning the state management.
2019-09-04 12:05:15 +02:00
Takashi Yano ffbb9b4971 Cygwin: pty: Move function hook_api() into hookapi.cc.
- PTY uses Win32 API hook for pseudo console suppot. The function
  hook_api() is used for this purpose and defined in fhandler_tty.cc
  previously. This patch moves it into hookapi.cc.
2019-09-04 11:59:46 +02:00
Takashi Yano bddb018e10 Cygwin: pty: Speed up a little hooked Win32 API for pseudo console.
- Some Win32 APIs are hooked in pty code for pseudo console support.
  This causes slow down. This patch improves speed a little.
2019-09-04 11:59:46 +02:00
Takashi Yano 9adb260181 Cygwin: pty: Code cleanup
- Cleanup the code which is commented out by #if 0 regarding pseudo
  console.
- Remove #if 1 for experimental code which seems to be stable.
2019-09-04 11:59:46 +02:00
Corinna Vinschen 7630c77026 Cygwin: sys/wait.h: Add _wait prototype to avoid compiler warning
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-09-03 17:00:43 +02:00
Corinna Vinschen 483fb49ea0 Cygwin: add W10 pseudo console support to release notes
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-08-29 13:56:43 +02:00
Takashi Yano 169d65a577 Cygwin: pty: add pseudo console support.
- Support pseudo console in PTY. Pseudo console is a new feature
  in Windows 10 1809, which provides console APIs on virtual
  terminal. With this patch, native console applications can work
  in PTYs such as mintty, ssh, gnu screen or tmux.
2019-08-29 13:47:40 +02:00
Ken Brown 398476acd2 Cygwin: get_posix_access: avoid negative subscript
Don't refer to lacl[pos] unless we know that pos >= 0.
2019-08-26 13:38:31 -04:00
Martin Storsjö f7f296b46f Cygwin: math: Properly propagate input NANs in a few functions
While the C99 standard doesn't explicitly require this, the standard
says it is recommended (F.9.13).

Signed-off-by: Martin Storsjö <martin@martin.st>
2019-08-20 18:15:16 +02:00
Martin Storsjö 8dee6fe6a5 Cygwin: math: Fix cosh(-INFINITY) to return +INFINITY
Signed-off-by: Martin Storsjö <martin@martin.st>
2019-08-20 18:15:16 +02:00
Martin Storsjö f4e7849fa9 Cygwin: math: Fix the return value for tgammal for zero and negative integers
For zero, it should return HUGE_VAL (INFINITY), for negative integers,
it should return NAN.

Signed-off-by: Martin Storsjö <martin@martin.st>
2019-08-20 18:15:16 +02:00
Corinna Vinschen 7097b05eda Cygwin: select: revamp non-polling code for signalfd
Rather than waiting for signalfd_select_wait in a thread, which is racy,
create a global event "my_pendingsigs_evt" which is set and reset by
wait_sig depending only on the fact if blocked signals are pending or not.

This in turn allows to WFMO on this event in select as soon as signalfds
are present in the read descriptor set.  Select's peek and verify
will then check if one of the present signalfds is affected.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-08-18 14:02:01 +02:00
Corinna Vinschen b7399d5e6f Revert "Cygwin: fix potential SEGV in sigwaitinfo/signalfd scenario"
This reverts commit 92115a83a4.

This was utterly wrong.
2019-08-17 10:12:16 +02:00
Takashi Yano 3a929f27f8 Cygwin: console: Fix the condition to interrupt select() by SIGWINCH
- Add code so that select() is not interrupted by SIGWINCH if it is
  ignored (SIG_IGN or SIG_DFL).
2019-08-15 09:53:33 +02:00
Takashi Yano e6910dfff6 Cygwin: console: Fix workaround for horizontal tab position
- The workaround commit 33a21904a7
  does not work as expected if window size is changed while screen
  is alternated. Fixed.
2019-08-15 09:53:33 +02:00
Corinna Vinschen 92115a83a4 Cygwin: fix potential SEGV in sigwaitinfo/signalfd scenario
On sigwaitinfo or reading from a signalfd, signal processing sets up
signal handling via sigdelayed even if the handler address is NULL.
This doesn't have any impact on sigwaitinfo scenarios (or at least, I
wasn't able to come up with a reproducer) but it breaks signalfd
scenarios, where eventually a call to call_signal_handler from
sigdelayed will try to call the NULL function.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-08-13 12:21:05 +02:00
Takashi Yano d178de278a Cygwin: console: Fix cursor position restore after screen alternation.
- If screen is alternated on console, cursor position is not restored
  correctly in the case of xterm compatible mode is enabled. For example,
  the shell prompt is shown at incorrect position after using vim.
  This patch fixes this problem.
2019-08-12 17:08:48 +02:00
Takashi Yano 33a21904a7 Cygwin: console: Add workaround for windows xterm compatible mode bug.
- The horizontal tab positions are broken after resizing console window.
  This seems to be a bug of xterm compatible mode of windows console.
  This workaround fixes this problem.
2019-08-12 17:08:48 +02:00
Takashi Yano 92e2c1ad9d Cygwin: console: Fix deadlock at calling fork().
- Calling fork() on console occasionally falls into deadlock. The reason
  is not clear, however, this patch fixes this problem anyway.
2019-08-12 17:08:48 +02:00
Joel Sherrill eae68bfc87 Add default implementation of fenv.h and all methods
The default implementation of the fenv.h methods return
	-EOPNOTSUP. Some of these have implementations appropriate
        for soft-float.

	The intention of the new fenv.h is that it be portable
	and that architectures provide their own implementation
	of sys/fenv.h.
2019-08-09 17:49:16 +02:00
Corinna Vinschen d59c2c9b82 Cygwin: drop preliminary 3.0.8 release file
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-08-09 17:49:16 +02:00
Corinna Vinschen 449e9a73d1 Cygwin: add missing bugfix release messages for 3.1.0
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-08-09 17:47:55 +02:00
Corinna Vinschen 1f34405fea Cygwin: shmat: use mmap allocator strategy on 64 bit
This avoids collisions of shmat maps with Windows own datastructures
when allocating top-down.

This patch moves the mmap_allocator class definition into its
own files and just uses it from mmap and shmat.
2019-08-08 11:27:52 +02:00
Lavrentiev, Anton 5fa9a0e708 Cygwin: getpriority() and top display for priority is inconsistent
Fix this by aligning /proc/[PID]/stat to the values returned by getpriority().
2019-08-08 09:56:49 +02:00
Michael Haubenwallner 472fbb8b97 Cygwin: build_env: fix off-by-one bug when re-adding PATH
Adding default winvar 'PATH=C:\cygwin64\binZ' to an environment that is
already allocated for 'SYSTEMROOT=ZWINDIR=Z', we need to count that
trailing (Z)ero as well.  Otherwise we trigger this assertion failure:

$ /bin/env -i SYSTEMROOT= WINDIR= /bin/env
assertion "(s - envblock) <= tl" failed: file "/home/corinna/src/cygwin/cygwin-3.0.7/cygwin-3.0.7-1.x86_64/src/newlib-cygwin/winsup/cygwin/environ.cc", line 1302, function: char** build_env(const char* const*, WCHAR*&, int&, bool, HANDLE)
Aborted (core dumped)
2019-08-07 11:08:01 +02:00
Corinna Vinschen 98669a2476 Cygwin: exec: check execute bit prior to evaluating script
When the exec family of functions is called for a script-like
file, the av::setup function handles the exec[vl]p case as
well.  The execve case for files not starting with a she-bang
is handled first by returning ENOEXEC.  Only after that, the
file's executability is checked.

This leads to the problem that ENOEXEC is returned for non-executable
files as well.  A calling shell interprets this as a file it should try
to run as script.  This is not desired for non-executable files.

Fix this problem by checking the file for executability first.  Only
after that, follow the other potential code paths.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-08-06 10:50:42 +02:00
Mark Geisert 362b98b49a Cygwin: Implement CPU_SET(3) macros
This patch supplies an implementation of the CPU_SET(3) processor
affinity macros as documented on the relevant Linux man page.

There is a mostly superset implementation of cpusets under newlib's
libc/sys/RTEMS/include/sys that has Linux and FreeBSD compatibility
and is built on top of FreeBSD bitsets.  This Cygwin implementation
and the RTEMS one could be combined if desired at some future point.
2019-08-05 13:22:04 +02:00
Michael Haubenwallner 2986a524d8 Cygwin: fork: attach child not before success
Do not attach to the child before it was successfully initialized, or we
would need more sophisticated cleanup on child initialization failure,
like suppressing SIGCHILD delivery with multiple threads ("waitproc")
involved.

Improves "Cygwin: fork: Remember child not before success.",
commit f03ea8e1c5, which leads to fork
problems if cygserver is running:

https://cygwin.com/ml/cygwin-patches/2019-q2/msg00155.html
2019-07-31 13:27:51 +02:00
Michael Haubenwallner 23a779bf3d Cygwin: pinfo: stop remember doing reattach
During fork, the child process requires the process table to be
initialized for fixup_shms_after_fork, while still allowing subsequent
dlls.load_after_fork to fail silently (for when the "forkable" hardlinks
are not created yet).
pinfo::remember not performing reattach anymore requires explicit
pinfo::reattach now where appropriate.

Prepares to improve "Cygwin: fork: Remember child not before success."
commit f03ea8e1c5, which leads to fork
problems if cygserver is running:

https://cygwin.com/ml/cygwin-patches/2019-q2/msg00155.html
2019-07-31 13:27:47 +02:00
Corinna Vinschen 3a72edc124 Cygwin: Fix the address of myself
Introducing an independent Cygwin PID introduced a regression:

The expectation is that the myself pinfo pointer always points to a
specific address right in front of the loaded Cygwin DLL.

However, the independent Cygwin PID changes broke this.  To create
myself at the right address requires to call init with h0 set to
INVALID_HANDLE_VALUE or an existing address:

void
pinfo::init (pid_t n, DWORD flag, HANDLE h0)
{
  [...]
  if (!h0 || myself.h)
    [...]
  else
    {
      shloc = SH_MYSELF;
      if (h0 == INVALID_HANDLE_VALUE)       <-- !!!
        h0 = NULL;
    }

The aforementioned commits changed that so h0 was always NULL, this way
creating myself at an arbitrary address.

This patch makes sure to set the handle to INVALID_HANDLE_VALUE again
when creating a new process, so init knows that myself has to be created
in the right spot.  While at it, fix a potential uninitialized handle
value in child_info_spawn::handle_spawn.

Fixes: b5e1003722 ("Cygwin: processes: use dedicated Cygwin PID rather than Windows PID")
Fixes: 88605243a1 ("Cygwin: fix child getting another pid after spawnve")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-07-25 10:45:52 +02:00
Corinna Vinschen 2232498c71 Cygwin: Don't change pgid to ctty pgid under debugger
_pinfo::set_ctty sets myself's pgid to the ctty pgid if the process has
been started from a non-Cygwin process.  This isn't the right thing to
do when started from GDB.  GDB starts the application via standard
Windows means, not via Cygwin fork/exec, so it's treated as being
a non-Cygwin parent.

But we want the app running in it's own process group.  So skip this
step when running under a debugger

Signed-off-by: Corinna Vinschen <corinna-cygwin@cygwin.com>
2019-07-25 10:45:52 +02:00
Corinna Vinschen a13145a30d Cygwin: Export newlib ndbm functions
Signed-off-by: Corinna Vinschen <corinna-cygwin@cygwin.com>
2019-07-24 22:32:48 +02:00
Ken Brown 6b843b82a8 Cygwin: document the last bug fix 2019-07-24 14:56:21 -04:00
Ken Brown 8a46b8ede2 Cygwin: fhandler_termios::tcsetpgrp: check that argument is non-negative
Return -1 with EINVAL if pgid < 0.

Previously tcsetpgrp() would blindly go ahead and set the pgid of the
controlling terminal to a negative value, causing later calls to
various functions to fail.

For example, gdb has code like the following:

  tcsetpgrp (0, getpgid (inf->pid));

If getpgid (inf->pid) fails (returns -1), then this code would set the
pgid of fd 0 to -1, so that some later calls to getpgid() would also
return -1.  This caused the problem reported here:

  https://cygwin.com/ml/cygwin/2019-07/msg00166.html.
2019-07-24 13:26:08 -04:00
Ken Brown ae59d09308 Cygwin: fix one more check for positive virtual_ftype_t values
Also drop more comments referring to numerical virtual_ftype_t values.
2019-07-22 14:06:35 -04:00
Corinna Vinschen dec444bee3 Cygwin: change virtual_ftype_t to not rely on negative values
So far negative values were denoting files, positive values
denoting directories.  We should prefer a less error prone
method.  Redefine virtual_ftype_t to contain only positive
values and replace checks for negativ or positive values with
inline functions virt_ftype_isfile() and virt_ftype_isdir().

Drop outdcated comments referring to numerical virtual_ftype_t
values.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-07-22 18:42:39 +02:00
Corinna Vinschen e118a605e2 Cygwin: fix /proc/PID/fd return value in error case
commit 2607639992 "Improve error handling in /proc/[pid]/
virtual files." changed the return value of the /proc/PID
formatting functions to return -1 instead of 0 in the error
case to allow a filesize of 0.

The patch neglected to change this behaviour for /proc/PID/fd
content.  This patch fixes that.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-07-22 18:42:38 +02:00
Ken Brown 86817773c5 Cygwin: add release notes for 3.0.8 2019-07-22 08:18:16 -04:00
Ken Brown 73f819534d Cygwin: socket files are not lnk special files
Change path_conv::is_lnk_special() so that it returns false on socket
files.

is_lnk_special() is called by rename2() in order to deal with special
files (FIFOs and symlinks, for example) whose Win32 names usually have
a ".lnk" suffix.  Socket files do not fall into this category, and
this change prevents ".lnk" from being appended erroneously when such
files are renamed.

Remove a now redundant !pc.issocket() from fhandler_disk_file::link().
2019-07-22 08:15:16 -04:00
Ken Brown af4d29e106 Cygwin: remove path_conv::is_fs_device()
It is used only once.
2019-07-22 08:15:16 -04:00
Ken Brown fb5ce26cfd Cygwin: remove path_conv::is_auto_device()
It is used only once, and the name is supposed to suggest "device that
is not based on the filesystem".  This intended meaning is clearer if
we just replace is_auto_device() by its definition at the place where
it's used.
2019-07-22 08:15:16 -04:00
Ken Brown 4beb9da118 Cygwin: fhandler_*: remove isdevice() and is_auto_device()
isdevice() is used only in the definition of is_auto_device().  And
the latter is used only once, in a context where isdevice() always
returns true.
2019-07-22 08:15:16 -04:00
Ken Brown 6b7723a830 Cygwin: unbreak the build with GCC 7
The recent port to GCC 8 used the 'nonstring' attribute, which is
unknown to GCC 7.  Define and use an 'ATTRIBUTE_NONSTRING' macro
instead.
2019-07-19 14:14:33 -04:00
Ken Brown 81421eda7d Cygwin: fix GCC 8.3 'asm volatile' errors
Remove the volatile qualifier, which is no longer allowed outside of
the function body.  See
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89585 for discussion.
2019-07-17 10:39:27 -04:00
Ken Brown b66dddb56d Cygwin: avoid GCC 8.3 errors with -Werror=stringop-truncation 2019-07-16 13:19:05 -04:00
Ken Brown f0cf44dc7d Cygwin: avoid GCC 8.3 errors with -Werror=class-memaccess 2019-07-16 13:17:43 -04:00