Re: Bug in TIME function

2019-09-15 Thread Achim Gratz
tl...@twcny.rr.com writes:
> The code below returns -1. It shouldn't.

This is hopefully fixed in the 3.1.0-05 test release of Cygwin.


Regards,
Achim.
-- 
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+

SD adaptations for Waldorf Q V3.00R3 and Q+ V3.54R2:
http://Synth.Stromeko.net/Downloads.html#WaldorfSDada

--
Problem reports:   http://cygwin.com/problems.html
FAQ:   http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info:  http://cygwin.com/ml/#unsubscribe-simple



[ANNOUNCEMENT] cygwin 3.1.0-0.5 (TEST)

2019-09-15 Thread Ken Brown
The following packages have been uploaded to the Cygwin distribution
as test releases:

* cygwin-3.1.0-0.5
* cygwin-devel-3.1.0-0.5
* cygwin-doc-3.1.0-0.5

This release comes with a couple of new features and quite a few
bug fixes.

The most interesting changes:

- A revamp of the old FIFO code.  It should now be possible to open
  FIFOs multiple times for writing, something the old code failed on.
  Courtesy Ken Brown.

- Support the new 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 Cygwin PTYs.
  Courtesy Takashi Yano.

There have been a lot of changes in the PTY code since
cygwin-3.1.0-0.4.  Please test!

===

What's new:
---

- 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.

- 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.

- New APIs: sched_getaffinity, sched_setaffinity, pthread_getaffinity_np,
  pthread_setaffinity_np, plus CPU_SET macros.

- New APIs: dbm_clearerr, dbm_close, dbm_delete, dbm_dirfno, dbm_error,
  dbm_fetch, dbm_firstkey, dbm_nextkey, dbm_open, dbm_store.


What changed:
-

- FIFOs can now be opened multiple times for writing.
  Addresses: https://cygwin.com/ml/cygwin/2015-03/msg00047.html
 https://cygwin.com/ml/cygwin/2015-12/msg00311.html

- If a SA_SIGINFO signal handler changes the ucontext_t pointed to by
  the third parameter, follow it after returning from the handler.

- Eliminate a header file name collision with  on case
  insensitive filesystems by reverting  back to .

- Allow times(2) to have a NULL argument, as on Linux.
  Addresses: https://cygwin.com/ml/cygwin/2019-09/msg00141.html


Bug Fixes
-

- Fix select() on console in canonical mode.  Return after one line is
  completed, instead of when only one key is typed.

- Make console I/O functions thread-safe.

- Define missing MSG_EOR.  It's unsupported by the underlying Winsock
  layer so using it in send(2), sendto(2), or sendmsg(2) will return -1
  with errno set to EOPNOTSUPP and recvmsg(2) will never return it.

- Fix a timerfd deadlock.
  Addresses: https://cygwin.com/ml/cygwin/2019-06/msg00096.html

- Fix sigpending() incorrectly returning signals for unrelated threads.
  Addresses: https://cygwin.com/ml/cygwin/2019-07/msg00051.html

- Fix a hang when opening a FIFO with O_PATH.
  Addresses: https://cygwin.com/ml/cygwin-developers/2019-06/msg1.html

- Don't append ".lnk" when renaming a socket file.
  Addresses: https://cygwin.com/ml/cygwin/2019-07/msg00139.html

- Make tcsetpgrp() return -1 if its argument is negative.
  Addresses: https://cygwin.com/ml/cygwin/2019-07/msg00166.html

- Avoid mistakenly moving a process under debugger control into the
  process group of the debugger.
  Addresses a problem visible in GDB 8.1.1, related to
  https://cygwin.com/ml/cygwin/2019-07/msg00166.html

- Return ENOEXEC from execve for arbitrary files only if the files are
  executable.
  Addresses: https://cygwin.com/ml/cygwin/2019-08/msg00054.html

- Fix off-by-one in environment evaluation leading to an abort.
  Addresses: https://cygwin.com/ml/cygwin-patches/2019-q3/msg00069.html

- Make output of /proc/[PID]/stat consistent with getpriority().
  Addresses: https://cygwin.com/ml/cygwin/2019-08/msg00082.html

- 64 bit only: Avoid collisions between memory maps created with shmat
  and Windows datastructures during fork.
  Addresses: https://cygwin.com/ml/cygwin/2019-08/msg00107.html

===


Have fun,

Ken Brown, on behalf of Corinna

--
Problem reports:   http://cygwin.com/problems.html
FAQ:   http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info:  http://cygwin.com/ml/#unsubscribe-simple



Re: Something makes curl hang for 5 minutes after connection refused

2019-09-15 Thread Basin Ilya
Hi.
Any update on this?

01.12.2018 12:51, Corinna Vinschen пишет:
> On Nov 30 20:42, Brian Inglis wrote:
>> On 2018-11-30 12:49, Lee wrote:
>>> On 11/30/18, Basin Ilya  wrote:
 Hi.

 Recently I noticed that `curl` does not fail immediately after connection
 refused, but waits for 5 minutes.

 This only happens on my machine and only with the `Cygwin` version of
 `curl`. The mingw version is unaffected.
 I tried downgrading curl, but it didn't help. I thought there's a rogue
 setting in `/etc` or in home or maybe some environment variable, but I
 couldn't find it.

 basin@BASIN /cygdrive/c/Users/basin
 $ >/dev/null /usr/bin/curl -v http://127.0.0.1:2/
 * STATE: INIT => CONNECT handle 0x80048658; line 1404 (connection
 #-5000)
 * Added connection 0. The cache now contains 1 members
 *   Trying 127.0.0.1...
 * TCP_NODELAY set
 * STATE: CONNECT => WAITCONNECT handle 0x80048658; line 1456 
 (connection
 #0)
>>> <.. snip ..>
 curl: (28) Connection timed out after 300145 milliseconds

 basin@BASIN /cygdrive/c/Users/basin
 $ /usr/bin/curl --version
 curl 7.59.0 (i686-pc-cygwin) libcurl/7.59.0 OpenSSL/1.0.2p zlib/1.2.11
 libidn2/2.0.4 libpsl/0.18.0 (+libidn2/2.0.2) libssh2/1.7.0 nghttp2/1.31.0
>>>
 Can someone try to reproduce it?
>>>
>>> I get the same behavior:
>>> $ /usr/bin/curl -v http://127.0.0.1:2/
>>> * STATE: INIT => CONNECT handle 0x600057ad0; line 1404 (connection #-5000)
>>> * Added connection 0. The cache now contains 1 members
>>> *   Trying 127.0.0.1...
>>> * TCP_NODELAY set
>>> * STATE: CONNECT => WAITCONNECT handle 0x600057ad0; line 1456 (connection 
>>> #0)
>>> * Connection timed out after 300324 milliseconds
>>> * multi_done
>>> * stopped the pause stream!
>>> * Closing connection 0
>>> * The cache now contains 0 members
>>> curl: (28) Connection timed out after 300324 milliseconds
>>>
>>> $ /usr/bin/curl --version
>>> curl 7.59.0 (x86_64-unknown-cygwin) libcurl/7.59.0 OpenSSL/1.0.2p
>>> zlib/1.2.11 libidn2/2.0.4 libpsl/0.18.0 (+libidn2/2.0.2) libssh2/1.7.0
>>> nghttp2/1.31.0
>>>
>>>
>>> I also get an almost immediate 'failed to connect' notice on windows:
>>> C:\>C:\UTIL\curl\curl.exe -v http://127.0.0.1:2/
>>> *   Trying 127.0.0.1...
>>> * TCP_NODELAY set
>>> * connect to 127.0.0.1 port 2 failed: Connection refused
>>> * Failed to connect to 127.0.0.1 port 2: Connection refused
>>> * Closing connection 0
>>> curl: (7) Failed to connect to 127.0.0.1 port 2: Connection refused
>>>
>>> with either version of curl:
>>> C:\>where curl
>>> C:\UTIL\curl\curl.exe
>>> C:\Windows\System32\curl.exe
>>
>> Ditto all the way!
>>
>> Could this be caused by network speed improvements made to Cygwin a while 
>> back?
>> Or were those patches never sent/received/applied from Daniel Havey (MS 
>> Windows
>> Program Manager for Transports and IP)?
> 
> Somebody may want to bisect this...
> 
> 
> Corinna
> 

--
Problem reports:   http://cygwin.com/problems.html
FAQ:   http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info:  http://cygwin.com/ml/#unsubscribe-simple



Re: Cygwin Error

2019-09-15 Thread cygwinautoreply
>Hi

>I am getting the below error while compiling a build from serena dimensions.

>  3 [main] python2.6 4520 find_fast_cwd: WARNING: Couldn't compute FAST=
>_CWD pointer.  Please report this problem to
>the public mailing list cygwin@cygwin.com


>Please check once and let me know what to do..


>Regards,
>Rahul Goel


https://cygwin.com/faq.html#faq.using.fixing-find_fast_cwd-warnings

--
Problem reports:   http://cygwin.com/problems.html
FAQ:   http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info:  http://cygwin.com/ml/#unsubscribe-simple



Cygwin Error

2019-09-15 Thread Goel, Rahul (D COE)
Hi

I am getting the below error while compiling a build from serena dimensions.

  3 [main] python2.6 4520 find_fast_cwd: WARNING: Couldn't compute FAST_CWD 
pointer.  Please report this problem to
the public mailing list cygwin@cygwin.com


Please check once and let me know what to do..


Regards,
Rahul Goel

--
Problem reports:   http://cygwin.com/problems.html
FAQ:   http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info:  http://cygwin.com/ml/#unsubscribe-simple



Re: cygwin 3.0.1-1 breaks my sshd install

2019-09-15 Thread Basin Ilya
Upd: the trick with pre-logging in by other means does not work:

$ /usr/bin/editrights -u git -l
SeBatchLogonRight

I've created the wake-s4u scheduled job following the instructions from the ml 
thread: "sshd problem on WS2008R2 64bit"
cmd.exe is running as that user, but seteuid still fails.

Of course, the whole problem applies to the public key auth. Logging in with 
password works for both domain and local.

15.09.2019 9:12, Basin Ilya пишет:
> Hi.
> The problem is still there.
> With the latest cygwin1.dll you can't have both domain and local users 
> working. cyg_server only allows local users and Local System only allows 
> domain users.
> Downgrading cygwin1.dll to 2x is the only thing that actually works. (have to 
> downgrade sshd.exe too, because of missing symbols)
> 
> Running Wow64 Cygwin on Windows 7. See attached cygcheck.out
> 
> 
> 21.02.2019 0:49, Houder пишет:
>> On Wed, 20 Feb 2019 21:27:22, Andy Moreton  wrote:
>>
>>> I've seen a similar failure, on a domain-joined Windows 10 box running
>>> cygsshd using a local cyg_server user account. I've fixed it by:
>>> 1) Open the "Computer Management" app
>>>Select "Services and Applications", then "Services", and
>>>choose the cygsshd service from the list.
>>> 2) Stop the service
>>> 3) Select the "Log On" tab, choose "Local System Account" and click OK.
>>> 4) Restart the service.
>>>
>>> This changed the account reported by "cygrunsrv -VQ" from "./cyg_server"
>>> to "LocalSystem".
>>
>> 64-@@ uname -a
>> CYGWIN_NT-6.1 Seven 3.0.1(0.338/5/3) 2019-02-20 10:19 x86_64 Cygwin
>>
>> First I replaced cygwin1.dll again w/ the last version, as you can see ...
>>
>> Then I carried out you instruction ...
>>
>> To my surprise it did the trick! Thank you!
>>
>> Perhaps Corinna can give a hint of why the modification made the difference.
>>
>> Henri
>>
>>

--
Problem reports:   http://cygwin.com/problems.html
FAQ:   http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info:  http://cygwin.com/ml/#unsubscribe-simple



Re: [PATCH] Cygwin: pty: Use autoload feature for pseudo console system calls.

2019-09-15 Thread Ken Brown
On 9/15/2019 6:55 AM, Takashi Yano wrote:
> - The autoload feature is used rather than GetModuleHandle(),
>GetProcAddress() for CreatePseudoConsole(), ResizePseudoConsole()
>and ClosePseudoConsole().
> ---
>   winsup/cygwin/autoload.cc |  3 +++
>   winsup/cygwin/fhandler_tty.cc | 36 +--
>   2 files changed, 16 insertions(+), 23 deletions(-)
> 
> diff --git a/winsup/cygwin/autoload.cc b/winsup/cygwin/autoload.cc
> index c4d91611e..1851ab3b6 100644
> --- a/winsup/cygwin/autoload.cc
> +++ b/winsup/cygwin/autoload.cc
> @@ -759,4 +759,7 @@ LoadDLLfunc (PdhAddEnglishCounterW, 16, pdh)
>   LoadDLLfunc (PdhCollectQueryData, 4, pdh)
>   LoadDLLfunc (PdhGetFormattedCounterValue, 16, pdh)
>   LoadDLLfunc (PdhOpenQueryW, 12, pdh)
> +LoadDLLfuncEx (CreatePseudoConsole, 20, kernel32, 1)
> +LoadDLLfuncEx (ResizePseudoConsole, 8, kernel32, 1)
> +LoadDLLfuncEx (ClosePseudoConsole, 4, kernel32, 1)
>   }
> diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc
> index 5072c6243..659e7b595 100644
> --- a/winsup/cygwin/fhandler_tty.cc
> +++ b/winsup/cygwin/fhandler_tty.cc
> @@ -47,6 +47,12 @@ details. */
>   extern "C" int sscanf (const char *, const char *, ...);
>   extern "C" int ttyname_r (int, char*, size_t);
>   
> +extern "C" {
> +  HRESULT WINAPI CreatePseudoConsole (COORD, HANDLE, HANDLE, DWORD, HPCON *);
> +  HRESULT WINAPI ResizePseudoConsole (HPCON, COORD);
> +  VOID WINAPI ClosePseudoConsole (HPCON);
> +}
> +
>   #define close_maybe(h) \
> do { \
>   if (h && h != INVALID_HANDLE_VALUE) \
> @@ -2157,14 +2163,8 @@ fhandler_pty_master::close ()
> /* FIXME: Pseudo console can be accessed via its handle
>only in the process which created it. What else can we do? */
> if (master_pid_tmp == myself->pid)
> - {
> -   /* Release pseudo console */
> -   HMODULE hModule = GetModuleHandle ("kernel32.dll");
> -   FARPROC func = GetProcAddress (hModule, "ClosePseudoConsole");
> -   VOID (WINAPI *ClosePseudoConsole) (HPCON) = NULL;
> -   ClosePseudoConsole = (VOID (WINAPI *) (HPCON)) func;
> -   ClosePseudoConsole (getPseudoConsole ());
> - }
> + /* Release pseudo console */
> + ClosePseudoConsole (getPseudoConsole ());
> get_ttyp ()->switch_to_pcon_in = false;
> get_ttyp ()->switch_to_pcon_out = false;
>   }
> @@ -2348,10 +2348,6 @@ fhandler_pty_master::ioctl (unsigned int cmd, void 
> *arg)
>only in the process which created it. What else can we do? */
> if (getPseudoConsole () && get_ttyp ()->master_pid == myself->pid)
>   {
> -   HMODULE hModule = GetModuleHandle ("kernel32.dll");
> -   FARPROC func = GetProcAddress (hModule, "ResizePseudoConsole");
> -   HRESULT (WINAPI *ResizePseudoConsole) (HPCON, COORD) = NULL;
> -   ResizePseudoConsole = (HRESULT (WINAPI *) (HPCON, COORD)) func;
> COORD size;
> size.X = ((struct winsize *) arg)->ws_col;
> size.Y = ((struct winsize *) arg)->ws_row;
> @@ -3103,22 +3099,16 @@ fhandler_pty_master::setup_pseudoconsole ()
>process in a pseudo console and get them from the helper.
>Slave process will attach to the pseudo console in the
>helper process using AttachConsole(). */
> -  HMODULE hModule = GetModuleHandle ("kernel32.dll");
> -  FARPROC func = GetProcAddress (hModule, "CreatePseudoConsole");
> -  HRESULT (WINAPI *CreatePseudoConsole)
> -(COORD, HANDLE, HANDLE, DWORD, HPCON *) = NULL;
> -  if (!func)
> -return false;
> -  CreatePseudoConsole =
> -(HRESULT (WINAPI *) (COORD, HANDLE, HANDLE, DWORD, HPCON *)) func;
> COORD size = {80, 25};
> CreatePipe (_master, _slave, _none, 0);
> +  SetLastError (ERROR_SUCCESS);
> HRESULT res = CreatePseudoConsole (size, from_master, to_master,
>0, _ttyp ()->hPseudoConsole);
> -  if (res != S_OK)
> +  if (res != S_OK || GetLastError () == ERROR_PROC_NOT_FOUND)
>   {
> -  system_printf ("CreatePseudoConsole() failed. %08x\n",
> -  GetLastError ());
> +  if (res != S_OK)
> + system_printf ("CreatePseudoConsole() failed. %08x\n",
> +GetLastError ());
> CloseHandle (from_master);
> CloseHandle (to_slave);
> from_master = from_master_cyg;

Pushed.  Thanks.

Ken

P.S. I'm building a new test release now, which I'll upload in a few hours 
unless you discover something else and want me to wait.


[PATCH] winsup/cygwin/times.cc (times): follow Linux and allow for a NULL buf argument

2019-09-15 Thread Achim Gratz


Adresses a problem reported on the Cygwin list.

---
 winsup/cygwin/times.cc | 17 +++--
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/winsup/cygwin/times.cc b/winsup/cygwin/times.cc
index 8908d44f1..909cae1f1 100644
--- a/winsup/cygwin/times.cc
+++ b/winsup/cygwin/times.cc
@@ -72,12 +72,17 @@ times (struct tms *buf)
   /* ticks is in in 100ns, convert to clock ticks. */
   tc = (clock_t) (ticks.QuadPart * CLOCKS_PER_SEC / NS100PERSEC);
 
-  buf->tms_stime = __to_clock_t (, 0);
-  buf->tms_utime = __to_clock_t (, 0);
-  timeval_to_filetime (>rusage_children.ru_stime, );
-  buf->tms_cstime = __to_clock_t (, 1);
-  timeval_to_filetime (>rusage_children.ru_utime, );
-  buf->tms_cutime = __to_clock_t (, 1);
+  /* Linux allows a NULL buf and just returns tc in that case, so
+mimic that */
+  if (buf)
+   {
+ buf->tms_stime = __to_clock_t (, 0);
+ buf->tms_utime = __to_clock_t (, 0);
+ timeval_to_filetime (>rusage_children.ru_stime, 
);
+ buf->tms_cstime = __to_clock_t (, 1);
+ timeval_to_filetime (>rusage_children.ru_utime, 
);
+ buf->tms_cutime = __to_clock_t (, 1);
+   }
 }
   __except (EFAULT)
 {
-- 
2.23.0


Achim.
-- 
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+

SD adaptation for Waldorf rackAttack V1.04R1:
http://Synth.Stromeko.net/Downloads.html#WaldorfSDada


cygwin 3.1.0-0.5 (TEST)

2019-09-15 Thread Ken Brown
The following packages have been uploaded to the Cygwin distribution
as test releases:

* cygwin-3.1.0-0.5
* cygwin-devel-3.1.0-0.5
* cygwin-doc-3.1.0-0.5

This release comes with a couple of new features and quite a few
bug fixes.

The most interesting changes:

- A revamp of the old FIFO code.  It should now be possible to open
  FIFOs multiple times for writing, something the old code failed on.
  Courtesy Ken Brown.

- Support the new 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 Cygwin PTYs.
  Courtesy Takashi Yano.

There have been a lot of changes in the PTY code since
cygwin-3.1.0-0.4.  Please test!

===

What's new:
---

- 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.

- 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.

- New APIs: sched_getaffinity, sched_setaffinity, pthread_getaffinity_np,
  pthread_setaffinity_np, plus CPU_SET macros.

- New APIs: dbm_clearerr, dbm_close, dbm_delete, dbm_dirfno, dbm_error,
  dbm_fetch, dbm_firstkey, dbm_nextkey, dbm_open, dbm_store.


What changed:
-

- FIFOs can now be opened multiple times for writing.
  Addresses: https://cygwin.com/ml/cygwin/2015-03/msg00047.html
 https://cygwin.com/ml/cygwin/2015-12/msg00311.html

- If a SA_SIGINFO signal handler changes the ucontext_t pointed to by
  the third parameter, follow it after returning from the handler.

- Eliminate a header file name collision with  on case
  insensitive filesystems by reverting  back to .

- Allow times(2) to have a NULL argument, as on Linux.
  Addresses: https://cygwin.com/ml/cygwin/2019-09/msg00141.html


Bug Fixes
-

- Fix select() on console in canonical mode.  Return after one line is
  completed, instead of when only one key is typed.

- Make console I/O functions thread-safe.

- Define missing MSG_EOR.  It's unsupported by the underlying Winsock
  layer so using it in send(2), sendto(2), or sendmsg(2) will return -1
  with errno set to EOPNOTSUPP and recvmsg(2) will never return it.

- Fix a timerfd deadlock.
  Addresses: https://cygwin.com/ml/cygwin/2019-06/msg00096.html

- Fix sigpending() incorrectly returning signals for unrelated threads.
  Addresses: https://cygwin.com/ml/cygwin/2019-07/msg00051.html

- Fix a hang when opening a FIFO with O_PATH.
  Addresses: https://cygwin.com/ml/cygwin-developers/2019-06/msg1.html

- Don't append ".lnk" when renaming a socket file.
  Addresses: https://cygwin.com/ml/cygwin/2019-07/msg00139.html

- Make tcsetpgrp() return -1 if its argument is negative.
  Addresses: https://cygwin.com/ml/cygwin/2019-07/msg00166.html

- Avoid mistakenly moving a process under debugger control into the
  process group of the debugger.
  Addresses a problem visible in GDB 8.1.1, related to
  https://cygwin.com/ml/cygwin/2019-07/msg00166.html

- Return ENOEXEC from execve for arbitrary files only if the files are
  executable.
  Addresses: https://cygwin.com/ml/cygwin/2019-08/msg00054.html

- Fix off-by-one in environment evaluation leading to an abort.
  Addresses: https://cygwin.com/ml/cygwin-patches/2019-q3/msg00069.html

- Make output of /proc/[PID]/stat consistent with getpriority().
  Addresses: https://cygwin.com/ml/cygwin/2019-08/msg00082.html

- 64 bit only: Avoid collisions between memory maps created with shmat
  and Windows datastructures during fork.
  Addresses: https://cygwin.com/ml/cygwin/2019-08/msg00107.html

===


Have fun,

Ken Brown, on behalf of Corinna


[newlib-cygwin] Cygwin: pty: Use system NLS function instead of PTY's own one.

2019-09-15 Thread Ken Brown
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=d83c45b46cdff9e550bac50ca382392c838b4e68

commit d83c45b46cdff9e550bac50ca382392c838b4e68
Author: Takashi Yano 
Date:   Sun Sep 15 13:05:52 2019 +0900

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.

Diff:
---
 winsup/cygwin/fhandler.h  |   1 +
 winsup/cygwin/fhandler_tty.cc | 499 +-
 winsup/cygwin/tty.cc  |   2 +-
 winsup/cygwin/tty.h   |   2 +-
 4 files changed, 107 insertions(+), 397 deletions(-)

diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h
index 1bf5dfb..4efb6a4 100644
--- a/winsup/cygwin/fhandler.h
+++ b/winsup/cygwin/fhandler.h
@@ -2192,6 +2192,7 @@ class fhandler_pty_slave: public fhandler_pty_common
   {
 return get_ttyp ()->ti.c_lflag & ICANON;
   }
+  void setup_locale (void);
 };
 
 #define __ptsname(buf, unit) __small_sprintf ((buf), "/dev/pty%d", (unit))
diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc
index 1b1d544..3bf8d0b 100644
--- a/winsup/cygwin/fhandler_tty.cc
+++ b/winsup/cygwin/fhandler_tty.cc
@@ -29,11 +29,6 @@ details. */
 
 #define ALWAYS_USE_PCON false
 #define USE_API_HOOK true
-#define USE_OWN_NLS_FUNC true
-
-#if !USE_OWN_NLS_FUNC
-#include "langinfo.h"
-#endif
 
 /* Not yet defined in Mingw-w64 */
 #ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING
@@ -1129,7 +1124,7 @@ fhandler_pty_slave::push_to_pcon_screenbuffer (const char 
*ptr, size_t len)
   size_t nlen;
   DWORD origCP;
   origCP = GetConsoleOutputCP ();
-  SetConsoleOutputCP (get_ttyp ()->TermCodePage);
+  SetConsoleOutputCP (get_ttyp ()->term_code_page);
   /* Just copy */
   buf = (char *) HeapAlloc (GetProcessHeap (), 0, len);
   memcpy (buf, (char *)ptr, len);
@@ -1246,16 +1241,16 @@ fhandler_pty_slave::write (const void *ptr, size_t len)
   char *buf;
   ssize_t nlen;
   UINT targetCodePage = get_ttyp ()->switch_to_pcon_out ?
-GetConsoleOutputCP () : get_ttyp ()->TermCodePage;
-  if (targetCodePage != get_ttyp ()->TermCodePage)
+GetConsoleOutputCP () : get_ttyp ()->term_code_page;
+  if (targetCodePage != get_ttyp ()->term_code_page)
 {
   size_t wlen =
-   MultiByteToWideChar (get_ttyp ()->TermCodePage, 0,
+   MultiByteToWideChar (get_ttyp ()->term_code_page, 0,
 (char *)ptr, len, NULL, 0);
   wchar_t *wbuf = (wchar_t *)
HeapAlloc (GetProcessHeap (), 0, wlen * sizeof (wchar_t));
   wlen =
-   MultiByteToWideChar (get_ttyp ()->TermCodePage, 0,
+   MultiByteToWideChar (get_ttyp ()->term_code_page, 0,
 (char *)ptr, len, wbuf, wlen);
   nlen = WideCharToMultiByte (targetCodePage, 0,
  wbuf, wlen, NULL, 0, NULL, NULL);
@@ -2242,15 +2237,15 @@ fhandler_pty_master::write (const void *ptr, size_t len)
   char *buf;
   size_t nlen;
 
-  if (get_ttyp ()->TermCodePage != CP_UTF8)
+  if (get_ttyp ()->term_code_page != CP_UTF8)
{
  size_t wlen =
-   MultiByteToWideChar (get_ttyp ()->TermCodePage, 0,
+   MultiByteToWideChar (get_ttyp ()->term_code_page, 0,
 (char *)ptr, len, NULL, 0);
  wchar_t *wbuf = (wchar_t *)
HeapAlloc (GetProcessHeap (), 0, wlen * sizeof (wchar_t));
  wlen =
-   MultiByteToWideChar (get_ttyp ()->TermCodePage, 0,
+   MultiByteToWideChar (get_ttyp ()->term_code_page, 0,
 (char *)ptr, len, wbuf, wlen);
  nlen = WideCharToMultiByte (CP_UTF8, 0,
  wbuf, wlen, NULL, 0, NULL, NULL);
@@ -2502,7 +2497,6 @@ get_locale_from_env (char *locale)
   strcpy (locale, env);
 }
 
-#if USE_OWN_NLS_FUNC
 static LCID
 get_langinfo (char *locale_out, char *charset_out)
 {
@@ -2510,318 +2504,52 @@ get_langinfo (char *locale_out, char *charset_out)
   char new_locale[ENCODING_LEN + 1];
   get_locale_from_env (new_locale);
 
-  /* The following code is borrowed from __loadlocale() in
- newlib/libc/locale/locale.c */
-
-  /* At this point a full-featured system would just load the locale
- specific data from the locale files.
- What we do here for now is to check the incoming string for correctness.
- The string must be in one of the allowed locale strings, either
- one in POSIX-style, or one in the old newlib style to maintain
- backward compatibility.  If the local string is correct, the charset
- is extracted and stored in ctype_codeset or message_charset
- dependent on the cateogry. */
-  char *locale = NULL;
-  char charset[ENCODING_LEN + 1];
-  long val = 0;
-  char *end, *c = NULL;
-
-  /* This additional code handles the case that the incoming locale string

[newlib-cygwin] Cygwin: pty: Use autoload feature for pseudo console system calls.

2019-09-15 Thread Ken Brown
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=70cd49e2045bae06faff1955342a1b0e1b038466

commit 70cd49e2045bae06faff1955342a1b0e1b038466
Author: Takashi Yano 
Date:   Sun Sep 15 19:55:44 2019 +0900

Cygwin: pty: Use autoload feature for pseudo console system calls.

- The autoload feature is used rather than GetModuleHandle(),
  GetProcAddress() for CreatePseudoConsole(), ResizePseudoConsole()
  and ClosePseudoConsole().

Diff:
---
 winsup/cygwin/autoload.cc |  3 +++
 winsup/cygwin/fhandler_tty.cc | 36 +---
 2 files changed, 16 insertions(+), 23 deletions(-)

diff --git a/winsup/cygwin/autoload.cc b/winsup/cygwin/autoload.cc
index c4d9161..1851ab3 100644
--- a/winsup/cygwin/autoload.cc
+++ b/winsup/cygwin/autoload.cc
@@ -759,4 +759,7 @@ LoadDLLfunc (PdhAddEnglishCounterW, 16, pdh)
 LoadDLLfunc (PdhCollectQueryData, 4, pdh)
 LoadDLLfunc (PdhGetFormattedCounterValue, 16, pdh)
 LoadDLLfunc (PdhOpenQueryW, 12, pdh)
+LoadDLLfuncEx (CreatePseudoConsole, 20, kernel32, 1)
+LoadDLLfuncEx (ResizePseudoConsole, 8, kernel32, 1)
+LoadDLLfuncEx (ClosePseudoConsole, 4, kernel32, 1)
 }
diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc
index 5072c62..659e7b5 100644
--- a/winsup/cygwin/fhandler_tty.cc
+++ b/winsup/cygwin/fhandler_tty.cc
@@ -47,6 +47,12 @@ details. */
 extern "C" int sscanf (const char *, const char *, ...);
 extern "C" int ttyname_r (int, char*, size_t);
 
+extern "C" {
+  HRESULT WINAPI CreatePseudoConsole (COORD, HANDLE, HANDLE, DWORD, HPCON *);
+  HRESULT WINAPI ResizePseudoConsole (HPCON, COORD);
+  VOID WINAPI ClosePseudoConsole (HPCON);
+}
+
 #define close_maybe(h) \
   do { \
 if (h && h != INVALID_HANDLE_VALUE) \
@@ -2157,14 +2163,8 @@ fhandler_pty_master::close ()
  /* FIXME: Pseudo console can be accessed via its handle
 only in the process which created it. What else can we do? */
  if (master_pid_tmp == myself->pid)
-   {
- /* Release pseudo console */
- HMODULE hModule = GetModuleHandle ("kernel32.dll");
- FARPROC func = GetProcAddress (hModule, "ClosePseudoConsole");
- VOID (WINAPI *ClosePseudoConsole) (HPCON) = NULL;
- ClosePseudoConsole = (VOID (WINAPI *) (HPCON)) func;
- ClosePseudoConsole (getPseudoConsole ());
-   }
+   /* Release pseudo console */
+   ClosePseudoConsole (getPseudoConsole ());
  get_ttyp ()->switch_to_pcon_in = false;
  get_ttyp ()->switch_to_pcon_out = false;
}
@@ -2348,10 +2348,6 @@ fhandler_pty_master::ioctl (unsigned int cmd, void *arg)
 only in the process which created it. What else can we do? */
   if (getPseudoConsole () && get_ttyp ()->master_pid == myself->pid)
{
- HMODULE hModule = GetModuleHandle ("kernel32.dll");
- FARPROC func = GetProcAddress (hModule, "ResizePseudoConsole");
- HRESULT (WINAPI *ResizePseudoConsole) (HPCON, COORD) = NULL;
- ResizePseudoConsole = (HRESULT (WINAPI *) (HPCON, COORD)) func;
  COORD size;
  size.X = ((struct winsize *) arg)->ws_col;
  size.Y = ((struct winsize *) arg)->ws_row;
@@ -3103,22 +3099,16 @@ fhandler_pty_master::setup_pseudoconsole ()
  process in a pseudo console and get them from the helper.
  Slave process will attach to the pseudo console in the
  helper process using AttachConsole(). */
-  HMODULE hModule = GetModuleHandle ("kernel32.dll");
-  FARPROC func = GetProcAddress (hModule, "CreatePseudoConsole");
-  HRESULT (WINAPI *CreatePseudoConsole)
-(COORD, HANDLE, HANDLE, DWORD, HPCON *) = NULL;
-  if (!func)
-return false;
-  CreatePseudoConsole =
-(HRESULT (WINAPI *) (COORD, HANDLE, HANDLE, DWORD, HPCON *)) func;
   COORD size = {80, 25};
   CreatePipe (_master, _slave, _none, 0);
+  SetLastError (ERROR_SUCCESS);
   HRESULT res = CreatePseudoConsole (size, from_master, to_master,
 0, _ttyp ()->hPseudoConsole);
-  if (res != S_OK)
+  if (res != S_OK || GetLastError () == ERROR_PROC_NOT_FOUND)
 {
-  system_printf ("CreatePseudoConsole() failed. %08x\n",
-GetLastError ());
+  if (res != S_OK)
+   system_printf ("CreatePseudoConsole() failed. %08x\n",
+  GetLastError ());
   CloseHandle (from_master);
   CloseHandle (to_slave);
   from_master = from_master_cyg;


[newlib-cygwin] Cygwin: pty: Correct typos that do not fit the coding style.

2019-09-15 Thread Ken Brown
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=fac5a01aec19480a1c1b039788cd26714928335f

commit fac5a01aec19480a1c1b039788cd26714928335f
Author: Takashi Yano 
Date:   Sun Sep 15 13:36:23 2019 +0900

Cygwin: pty: Correct typos that do not fit the coding style.

Diff:
---
 winsup/cygwin/fhandler_tty.cc | 26 +-
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc
index 5c27510..5072c62 100644
--- a/winsup/cygwin/fhandler_tty.cc
+++ b/winsup/cygwin/fhandler_tty.cc
@@ -45,7 +45,7 @@ details. */
 #endif /* ENABLE_VIRTUAL_TERMINAL_INPUT */
 
 extern "C" int sscanf (const char *, const char *, ...);
-extern "C" int ttyname_r(int, char*, size_t);
+extern "C" int ttyname_r (int, char*, size_t);
 
 #define close_maybe(h) \
   do { \
@@ -2147,7 +2147,7 @@ fhandler_pty_master::close ()
   else if (obi.HandleCount == (getPseudoConsole () ? 2 : 1))
  /* Helper process has inherited one. */
 {
-  termios_printf("Closing last master of pty%d", get_minor ());
+  termios_printf ("Closing last master of pty%d", get_minor ());
   /* Close Pseudo Console */
   if (getPseudoConsole ())
{
@@ -2446,9 +2446,9 @@ get_locale_from_env (char *locale)
   char lang[ENCODING_LEN + 1] = {0, }, country[ENCODING_LEN + 1] = {0, };
   env = getenv ("LC_ALL");
   if (env == NULL || !*env)
-env = getenv("LC_CTYPE");
+env = getenv ("LC_CTYPE");
   if (env == NULL || !*env)
-env = getenv("LANG");
+env = getenv ("LANG");
   if (env == NULL || !*env)
 {
   if (GetLocaleInfo (LOCALE_CUSTOM_UI_DEFAULT,
@@ -2476,7 +2476,7 @@ get_locale_from_env (char *locale)
 LOCALE_SISO3166CTRYNAME,
 country, sizeof (country));
   if (strlen (lang) && strlen (country))
-   __small_sprintf (lang + strlen(lang), "_%s.UTF-8", country);
+   __small_sprintf (lang + strlen (lang), "_%s.UTF-8", country);
   else
strcpy (lang , "C.UTF-8");
   env = lang;
@@ -2492,7 +2492,7 @@ get_langinfo (char *locale_out, char *charset_out)
   get_locale_from_env (new_locale);
 
   __locale_t loc;
-  memset(, 0, sizeof (loc));
+  memset (, 0, sizeof (loc));
   const char *locale = __loadlocale (, LC_CTYPE, new_locale);
   if (!locale)
 locale = "C";
@@ -2565,8 +2565,8 @@ get_langinfo (char *locale_out, char *charset_out)
 return 0;
 
   /* Set results */
-  strcpy(locale_out, new_locale);
-  strcpy(charset_out, charset);
+  strcpy (locale_out, new_locale);
+  strcpy (charset_out, charset);
   return lcid;
 }
 
@@ -2670,7 +2670,7 @@ fhandler_pty_slave::fixup_after_attach (bool 
native_maybe, int fd_set)
get_ttyp ()->pcon_pid = myself->pid;
  get_ttyp ()->switch_to_pcon_out = true;
}
- init_console_handler(false);
+ init_console_handler (false);
}
   else if (fd == 0 && native_maybe)
/* Read from unattached pseudo console cause freeze,
@@ -2754,7 +2754,7 @@ fhandler_pty_slave::fixup_after_exec ()
{ \
  void *api = hook_api (module, #name, (void *) name##_Hooked); \
  name##_Orig = (__typeof__ (name) *) api; \
- /*if (api) system_printf(#name " hooked.");*/ \
+ /*if (api) system_printf (#name " hooked.");*/ \
}
   DO_HOOK (NULL, WriteFile);
   DO_HOOK (NULL, WriteConsoleA);
@@ -3118,7 +3118,7 @@ fhandler_pty_master::setup_pseudoconsole ()
   if (res != S_OK)
 {
   system_printf ("CreatePseudoConsole() failed. %08x\n",
-GetLastError());
+GetLastError ());
   CloseHandle (from_master);
   CloseHandle (to_slave);
   from_master = from_master_cyg;
@@ -3230,7 +3230,7 @@ fhandler_pty_master::setup ()
 termios_printf ("can't set output_handle(%p) to non-blocking mode",
get_output_handle ());
 
-  char pipename[sizeof("pty-to-master-cyg")];
+  char pipename[sizeof ("pty-to-master-cyg")];
   __small_sprintf (pipename, "pty%d-to-master", unit);
   res = fhandler_pipe::create (_none, _slave, _master,
   fhandler_pty_common::pipesize, pipename, 0);
@@ -3406,7 +3406,7 @@ fhandler_pty_common::process_opost_output (HANDLE h, 
const void *ptr, ssize_t& l
break;
  else
{
- set_errno(EAGAIN);
+ set_errno (EAGAIN);
  len = -1;
  return TRUE;
}


[newlib-cygwin] Cygwin: pty: Change the timing of clearing screen.

2019-09-15 Thread Ken Brown
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=244f03627d37ea5ba642fc9a4b7c7b4a1a7be11d

commit 244f03627d37ea5ba642fc9a4b7c7b4a1a7be11d
Author: Takashi Yano 
Date:   Sun Sep 15 13:05:53 2019 +0900

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.

Diff:
---
 winsup/cygwin/fhandler_tty.cc | 26 +-
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc
index 3bf8d0b..5c27510 100644
--- a/winsup/cygwin/fhandler_tty.cc
+++ b/winsup/cygwin/fhandler_tty.cc
@@ -1041,19 +1041,6 @@ skip_console_setting:
 void
 fhandler_pty_slave::reset_switch_to_pcon (void)
 {
-  if (get_ttyp ()->need_clear_screen)
-{
-  const char *term = getenv ("TERM");
-  if (term && strcmp (term, "dumb") && !strstr (term, "emacs"))
-   {
- /* FIXME: Clearing sequence may not be "^[[H^[[J"
-depending on the terminal type. */
- DWORD n;
- WriteFile (get_output_handle_cyg (), "\033[H\033[J", 6, , NULL);
-   }
-  get_ttyp ()->need_clear_screen = false;
-}
-
   if (isHybrid)
 this->set_switch_to_pcon (fd);
   if (get_ttyp ()->pcon_pid &&
@@ -2742,6 +2729,19 @@ fhandler_pty_slave::fixup_after_exec ()
}
 }
 
+  if (get_ttyp ()->need_clear_screen)
+{
+  const char *term = getenv ("TERM");
+  if (term && strcmp (term, "dumb") && !strstr (term, "emacs"))
+   {
+ /* FIXME: Clearing sequence may not be "^[[H^[[J"
+depending on the terminal type. */
+ DWORD n;
+ WriteFile (get_output_handle_cyg (), "\033[H\033[J", 6, , NULL);
+   }
+  get_ttyp ()->need_clear_screen = false;
+}
+
   /* Set locale */
   setup_locale ();


[newlib-cygwin] Cygwin: pty: Fix bad file descriptor error in some environment.

2019-09-15 Thread Ken Brown
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=6983433f8e097449a7182def4c4393306e9a9a46

commit 6983433f8e097449a7182def4c4393306e9a9a46
Author: Takashi Yano 
Date:   Sun Sep 15 13:05:51 2019 +0900

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.

Diff:
---
 winsup/cygwin/fhandler_tty.cc | 2 --
 1 file changed, 2 deletions(-)

diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc
index 9aa8326..1b1d544 100644
--- a/winsup/cygwin/fhandler_tty.cc
+++ b/winsup/cygwin/fhandler_tty.cc
@@ -857,8 +857,6 @@ fhandler_pty_slave::open (int flags, mode_t)
   pcon_attached_to = get_minor ();
   init_console_handler (true);
 }
-  else if (pcon_attached_to < 0)
-fhandler_console::need_invisible ();
 
   set_open_status ();
   return 1;


Re: [PATCH] Cygwin: pty: Correct typos that do not fit the coding style.

2019-09-15 Thread Ken Brown
On 9/15/2019 12:36 AM, Takashi Yano wrote:
> ---
>   winsup/cygwin/fhandler_tty.cc | 26 +-
>   1 file changed, 13 insertions(+), 13 deletions(-)
> 
> diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc
> index 5c27510be..5072c6243 100644
> --- a/winsup/cygwin/fhandler_tty.cc
> +++ b/winsup/cygwin/fhandler_tty.cc
> @@ -45,7 +45,7 @@ details. */
>   #endif /* ENABLE_VIRTUAL_TERMINAL_INPUT */
>   
>   extern "C" int sscanf (const char *, const char *, ...);
> -extern "C" int ttyname_r(int, char*, size_t);
> +extern "C" int ttyname_r (int, char*, size_t);
>   
>   #define close_maybe(h) \
> do { \
> @@ -2147,7 +2147,7 @@ fhandler_pty_master::close ()
> else if (obi.HandleCount == (getPseudoConsole () ? 2 : 1))
> /* Helper process has inherited one. */
>   {
> -  termios_printf("Closing last master of pty%d", get_minor ());
> +  termios_printf ("Closing last master of pty%d", get_minor ());
> /* Close Pseudo Console */
> if (getPseudoConsole ())
>   {
> @@ -2446,9 +2446,9 @@ get_locale_from_env (char *locale)
> char lang[ENCODING_LEN + 1] = {0, }, country[ENCODING_LEN + 1] = {0, };
> env = getenv ("LC_ALL");
> if (env == NULL || !*env)
> -env = getenv("LC_CTYPE");
> +env = getenv ("LC_CTYPE");
> if (env == NULL || !*env)
> -env = getenv("LANG");
> +env = getenv ("LANG");
> if (env == NULL || !*env)
>   {
> if (GetLocaleInfo (LOCALE_CUSTOM_UI_DEFAULT,
> @@ -2476,7 +2476,7 @@ get_locale_from_env (char *locale)
>LOCALE_SISO3166CTRYNAME,
>country, sizeof (country));
> if (strlen (lang) && strlen (country))
> - __small_sprintf (lang + strlen(lang), "_%s.UTF-8", country);
> + __small_sprintf (lang + strlen (lang), "_%s.UTF-8", country);
> else
>   strcpy (lang , "C.UTF-8");
> env = lang;
> @@ -2492,7 +2492,7 @@ get_langinfo (char *locale_out, char *charset_out)
> get_locale_from_env (new_locale);
>   
> __locale_t loc;
> -  memset(, 0, sizeof (loc));
> +  memset (, 0, sizeof (loc));
> const char *locale = __loadlocale (, LC_CTYPE, new_locale);
> if (!locale)
>   locale = "C";
> @@ -2565,8 +2565,8 @@ get_langinfo (char *locale_out, char *charset_out)
>   return 0;
>   
> /* Set results */
> -  strcpy(locale_out, new_locale);
> -  strcpy(charset_out, charset);
> +  strcpy (locale_out, new_locale);
> +  strcpy (charset_out, charset);
> return lcid;
>   }
>   
> @@ -2670,7 +2670,7 @@ fhandler_pty_slave::fixup_after_attach (bool 
> native_maybe, int fd_set)
>   get_ttyp ()->pcon_pid = myself->pid;
> get_ttyp ()->switch_to_pcon_out = true;
>   }
> -   init_console_handler(false);
> +   init_console_handler (false);
>   }
> else if (fd == 0 && native_maybe)
>   /* Read from unattached pseudo console cause freeze,
> @@ -2754,7 +2754,7 @@ fhandler_pty_slave::fixup_after_exec ()
>   { \
> void *api = hook_api (module, #name, (void *) name##_Hooked); \
> name##_Orig = (__typeof__ (name) *) api; \
> -   /*if (api) system_printf(#name " hooked.");*/ \
> +   /*if (api) system_printf (#name " hooked.");*/ \
>   }
> DO_HOOK (NULL, WriteFile);
> DO_HOOK (NULL, WriteConsoleA);
> @@ -3118,7 +3118,7 @@ fhandler_pty_master::setup_pseudoconsole ()
> if (res != S_OK)
>   {
> system_printf ("CreatePseudoConsole() failed. %08x\n",
> -  GetLastError());
> +  GetLastError ());
> CloseHandle (from_master);
> CloseHandle (to_slave);
> from_master = from_master_cyg;
> @@ -3230,7 +3230,7 @@ fhandler_pty_master::setup ()
>   termios_printf ("can't set output_handle(%p) to non-blocking mode",
>   get_output_handle ());
>   
> -  char pipename[sizeof("pty-to-master-cyg")];
> +  char pipename[sizeof ("pty-to-master-cyg")];
> __small_sprintf (pipename, "pty%d-to-master", unit);
> res = fhandler_pipe::create (_none, _slave, _master,
>  fhandler_pty_common::pipesize, pipename, 0);
> @@ -3406,7 +3406,7 @@ fhandler_pty_common::process_opost_output (HANDLE h, 
> const void *ptr, ssize_t& l
>   break;
> else
>   {
> -   set_errno(EAGAIN);
> +   set_errno (EAGAIN);
> len = -1;
> return TRUE;
>   }

Pushed.  Thanks.

Ken


Re: [PATCH 0/3] Some fixes for PTY with pseudo console support (3)

2019-09-15 Thread Ken Brown
On 9/15/2019 12:05 AM, Takashi Yano wrote:
> [PATCH 1/3] 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.
> 
> [PATCH 2/3] 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.
> 
> [PATCH 3/3] 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.
> 
> Takashi Yano (3):
>Cygwin: pty: Fix bad file descriptor error in some environment.
>Cygwin: pty: Use system NLS function instead of PTY's own one.
>Cygwin: pty: Change the timing of clearing screen.
> 
>   winsup/cygwin/fhandler.h  |   1 +
>   winsup/cygwin/fhandler_tty.cc | 527 --
>   winsup/cygwin/tty.cc  |   2 +-
>   winsup/cygwin/tty.h   |   2 +-
>   4 files changed, 120 insertions(+), 412 deletions(-)

Pushed.  Thanks.

Ken


[newlib-cygwin] winsup/cygwin/times.cc (times): follow Linux and allow for a NULL buf argument

2019-09-15 Thread Ken Brown
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=d5f84126e56ee860b10a8a5826dc568e2c266f1b

commit d5f84126e56ee860b10a8a5826dc568e2c266f1b
Author: Achim Gratz 
Date:   Sun Sep 15 18:28:21 2019 +0200

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

Diff:
---
 winsup/cygwin/times.cc | 17 +++--
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/winsup/cygwin/times.cc b/winsup/cygwin/times.cc
index 8908d44..909cae1 100644
--- a/winsup/cygwin/times.cc
+++ b/winsup/cygwin/times.cc
@@ -72,12 +72,17 @@ times (struct tms *buf)
   /* ticks is in in 100ns, convert to clock ticks. */
   tc = (clock_t) (ticks.QuadPart * CLOCKS_PER_SEC / NS100PERSEC);
 
-  buf->tms_stime = __to_clock_t (, 0);
-  buf->tms_utime = __to_clock_t (, 0);
-  timeval_to_filetime (>rusage_children.ru_stime, );
-  buf->tms_cstime = __to_clock_t (, 1);
-  timeval_to_filetime (>rusage_children.ru_utime, );
-  buf->tms_cutime = __to_clock_t (, 1);
+  /* Linux allows a NULL buf and just returns tc in that case, so
+mimic that */
+  if (buf)
+   {
+ buf->tms_stime = __to_clock_t (, 0);
+ buf->tms_utime = __to_clock_t (, 0);
+ timeval_to_filetime (>rusage_children.ru_stime, 
);
+ buf->tms_cstime = __to_clock_t (, 1);
+ timeval_to_filetime (>rusage_children.ru_utime, 
);
+ buf->tms_cutime = __to_clock_t (, 1);
+   }
 }
   __except (EFAULT)
 {


Re: [PATCH] winsup/cygwin/times.cc (times): follow Linux and allow for a NULL buf argument

2019-09-15 Thread Ken Brown
On 9/15/2019 12:28 PM, Achim Gratz wrote:
> 
> Adresses a problem reported on the Cygwin list.
> 
> ---
>   winsup/cygwin/times.cc | 17 +++--
>   1 file changed, 11 insertions(+), 6 deletions(-)
> 
> diff --git a/winsup/cygwin/times.cc b/winsup/cygwin/times.cc
> index 8908d44f1..909cae1f1 100644
> --- a/winsup/cygwin/times.cc
> +++ b/winsup/cygwin/times.cc
> @@ -72,12 +72,17 @@ times (struct tms *buf)
> /* ticks is in in 100ns, convert to clock ticks. */
> tc = (clock_t) (ticks.QuadPart * CLOCKS_PER_SEC / NS100PERSEC);
>   
> -  buf->tms_stime = __to_clock_t (, 0);
> -  buf->tms_utime = __to_clock_t (, 0);
> -  timeval_to_filetime (>rusage_children.ru_stime, 
> );
> -  buf->tms_cstime = __to_clock_t (, 1);
> -  timeval_to_filetime (>rusage_children.ru_utime, );
> -  buf->tms_cutime = __to_clock_t (, 1);
> +  /* Linux allows a NULL buf and just returns tc in that case, so
> +  mimic that */
> +  if (buf)
> + {
> +   buf->tms_stime = __to_clock_t (, 0);
> +   buf->tms_utime = __to_clock_t (, 0);
> +   timeval_to_filetime (>rusage_children.ru_stime, 
> );
> +   buf->tms_cstime = __to_clock_t (, 1);
> +   timeval_to_filetime (>rusage_children.ru_utime, 
> );
> +   buf->tms_cutime = __to_clock_t (, 1);
> + }
>   }
> __except (EFAULT)
>   {

Pushed, with a slight tweak to the commit message.  Thanks.

Ken


[newlib-cygwin] Cygwin: document last change

2019-09-15 Thread Ken Brown
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=bbc625da81076bf31ea77af346d368fd221c4079

commit bbc625da81076bf31ea77af346d368fd221c4079
Author: Ken Brown 
Date:   Sun Sep 15 13:40:12 2019 -0400

Cygwin: document last change

Diff:
---
 winsup/cygwin/release/3.1.0 | 3 +++
 winsup/doc/new-features.xml | 4 
 2 files changed, 7 insertions(+)

diff --git a/winsup/cygwin/release/3.1.0 b/winsup/cygwin/release/3.1.0
index 12a5f32..72664ab 100644
--- a/winsup/cygwin/release/3.1.0
+++ b/winsup/cygwin/release/3.1.0
@@ -30,6 +30,9 @@ What changed:
 - Eliminate a header file name collision with  on case
   insensitive filesystems by reverting  back to .
 
+- Allow times(2) to have a NULL argument, as on Linux.
+  Addresses: https://cygwin.com/ml/cygwin/2019-09/msg00141.html
+
 
 Bug Fixes
 -
diff --git a/winsup/doc/new-features.xml b/winsup/doc/new-features.xml
index 118e378..cbfdf32 100644
--- a/winsup/doc/new-features.xml
+++ b/winsup/doc/new-features.xml
@@ -46,6 +46,10 @@ New APIs: dbm_clearerr, dbm_close, dbm_delete, dbm_dirfno, 
dbm_error,
 dbm_fetch, dbm_firstkey, dbm_nextkey, dbm_open, dbm_store.
 
 
+
+Allow times(2) to have a NULL argument, as on Linux.
+
+
 
 
 


[PATCH] Cygwin: pty: Use autoload feature for pseudo console system calls.

2019-09-15 Thread Takashi Yano
- The autoload feature is used rather than GetModuleHandle(),
  GetProcAddress() for CreatePseudoConsole(), ResizePseudoConsole()
  and ClosePseudoConsole().
---
 winsup/cygwin/autoload.cc |  3 +++
 winsup/cygwin/fhandler_tty.cc | 36 +--
 2 files changed, 16 insertions(+), 23 deletions(-)

diff --git a/winsup/cygwin/autoload.cc b/winsup/cygwin/autoload.cc
index c4d91611e..1851ab3b6 100644
--- a/winsup/cygwin/autoload.cc
+++ b/winsup/cygwin/autoload.cc
@@ -759,4 +759,7 @@ LoadDLLfunc (PdhAddEnglishCounterW, 16, pdh)
 LoadDLLfunc (PdhCollectQueryData, 4, pdh)
 LoadDLLfunc (PdhGetFormattedCounterValue, 16, pdh)
 LoadDLLfunc (PdhOpenQueryW, 12, pdh)
+LoadDLLfuncEx (CreatePseudoConsole, 20, kernel32, 1)
+LoadDLLfuncEx (ResizePseudoConsole, 8, kernel32, 1)
+LoadDLLfuncEx (ClosePseudoConsole, 4, kernel32, 1)
 }
diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc
index 5072c6243..659e7b595 100644
--- a/winsup/cygwin/fhandler_tty.cc
+++ b/winsup/cygwin/fhandler_tty.cc
@@ -47,6 +47,12 @@ details. */
 extern "C" int sscanf (const char *, const char *, ...);
 extern "C" int ttyname_r (int, char*, size_t);
 
+extern "C" {
+  HRESULT WINAPI CreatePseudoConsole (COORD, HANDLE, HANDLE, DWORD, HPCON *);
+  HRESULT WINAPI ResizePseudoConsole (HPCON, COORD);
+  VOID WINAPI ClosePseudoConsole (HPCON);
+}
+
 #define close_maybe(h) \
   do { \
 if (h && h != INVALID_HANDLE_VALUE) \
@@ -2157,14 +2163,8 @@ fhandler_pty_master::close ()
  /* FIXME: Pseudo console can be accessed via its handle
 only in the process which created it. What else can we do? */
  if (master_pid_tmp == myself->pid)
-   {
- /* Release pseudo console */
- HMODULE hModule = GetModuleHandle ("kernel32.dll");
- FARPROC func = GetProcAddress (hModule, "ClosePseudoConsole");
- VOID (WINAPI *ClosePseudoConsole) (HPCON) = NULL;
- ClosePseudoConsole = (VOID (WINAPI *) (HPCON)) func;
- ClosePseudoConsole (getPseudoConsole ());
-   }
+   /* Release pseudo console */
+   ClosePseudoConsole (getPseudoConsole ());
  get_ttyp ()->switch_to_pcon_in = false;
  get_ttyp ()->switch_to_pcon_out = false;
}
@@ -2348,10 +2348,6 @@ fhandler_pty_master::ioctl (unsigned int cmd, void *arg)
 only in the process which created it. What else can we do? */
   if (getPseudoConsole () && get_ttyp ()->master_pid == myself->pid)
{
- HMODULE hModule = GetModuleHandle ("kernel32.dll");
- FARPROC func = GetProcAddress (hModule, "ResizePseudoConsole");
- HRESULT (WINAPI *ResizePseudoConsole) (HPCON, COORD) = NULL;
- ResizePseudoConsole = (HRESULT (WINAPI *) (HPCON, COORD)) func;
  COORD size;
  size.X = ((struct winsize *) arg)->ws_col;
  size.Y = ((struct winsize *) arg)->ws_row;
@@ -3103,22 +3099,16 @@ fhandler_pty_master::setup_pseudoconsole ()
  process in a pseudo console and get them from the helper.
  Slave process will attach to the pseudo console in the
  helper process using AttachConsole(). */
-  HMODULE hModule = GetModuleHandle ("kernel32.dll");
-  FARPROC func = GetProcAddress (hModule, "CreatePseudoConsole");
-  HRESULT (WINAPI *CreatePseudoConsole)
-(COORD, HANDLE, HANDLE, DWORD, HPCON *) = NULL;
-  if (!func)
-return false;
-  CreatePseudoConsole =
-(HRESULT (WINAPI *) (COORD, HANDLE, HANDLE, DWORD, HPCON *)) func;
   COORD size = {80, 25};
   CreatePipe (_master, _slave, _none, 0);
+  SetLastError (ERROR_SUCCESS);
   HRESULT res = CreatePseudoConsole (size, from_master, to_master,
 0, _ttyp ()->hPseudoConsole);
-  if (res != S_OK)
+  if (res != S_OK || GetLastError () == ERROR_PROC_NOT_FOUND)
 {
-  system_printf ("CreatePseudoConsole() failed. %08x\n",
-GetLastError ());
+  if (res != S_OK)
+   system_printf ("CreatePseudoConsole() failed. %08x\n",
+  GetLastError ());
   CloseHandle (from_master);
   CloseHandle (to_slave);
   from_master = from_master_cyg;
-- 
2.21.0