* [PATCH v2] Make zpty module work in the cygwin and msys2
@ 2021-01-15 4:29 Peiyuan Song
2021-01-16 18:34 ` Bart Schaefer
0 siblings, 1 reply; 3+ messages in thread
From: Peiyuan Song @ 2021-01-15 4:29 UTC (permalink / raw)
To: zsh-workers
cygwin have /dev/ptmx, need defined `_GNU_SOURCE 1` to use it, but
configure check /dev/ptmx is usable only defined it for linux.
Another probleam is cygwin upstream have an issue
https://cygwin.com/pipermail/cygwin-developers/2021-January/012030.html,
because of that issue, movefd will broken the fd opened by
posix_openpt, so that we mast disable movefd in zpty until cygwin
fix that issue.
v2 change: make fdtable[master]
---
Src/Modules/zpty.c | 28 ++++++++++++++++++++++++++++
configure.ac | 2 +-
2 files changed, 29 insertions(+), 1 deletion(-)
diff --git a/Src/Modules/zpty.c b/Src/Modules/zpty.c
index 45fd15ee0..624da13f1 100644
--- a/Src/Modules/zpty.c
+++ b/Src/Modules/zpty.c
@@ -299,6 +299,29 @@ get_pty(int master, int *retfd)
#endif /* /dev/ptmx or alternatives */
+#ifdef __CYGWIN__
+/*
+ * Ensure the fdtable is large enough for fd, and that the
+ * maximum fd is set appropriately.
+ */
+static void
+check_fd_table(int fd)
+{
+ if (fd <= max_zsh_fd)
+ return;
+
+ if (fd >= fdtable_size) {
+ int old_size = fdtable_size;
+ while (fd >= fdtable_size)
+ fdtable = zrealloc(fdtable,
+ (fdtable_size *= 2)*sizeof(*fdtable));
+ memset(fdtable + old_size, 0,
+ (fdtable_size - old_size) * sizeof(*fdtable));
+ }
+ max_zsh_fd = fd;
+}
+#endif
+
static int
newptycmd(char *nam, char *pname, char **args, int echo, int nblock)
{
@@ -428,6 +451,7 @@ newptycmd(char *nam, char *pname, char **args, int
echo, int nblock)
mypid = 0; /* trick to ensure we _exit() */
zexit(lastval, ZEXIT_NORMAL);
}
+#ifndef __CYGWIN__
master = movefd(master);
if (master == -1) {
zerrnam(nam, "cannot duplicate fd %d: %e", master, errno);
@@ -435,6 +459,10 @@ newptycmd(char *nam, char *pname, char **args,
int echo, int nblock)
ineval = oineval;
return 1;
}
+#else
+ check_fd_table(master);
+ fdtable[master] = FDT_INTERNAL;
+#endif
p = (Ptycmd) zalloc(sizeof(*p));
diff --git a/configure.ac b/configure.ac
index 549cae3d6..16dafac05 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2460,7 +2460,7 @@ if test x$ac_cv_have_dev_ptmx = xyes -o
x$ac_cv_func_posix_openpt = xyes && \
test x$ac_cv_func_ptsname = xyes; then
AC_CACHE_CHECK([if /dev/ptmx is usable],
ac_cv_use_dev_ptmx,
- [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#ifdef __linux
+ [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#if defined(__linux) ||
defined(__CYGWIN__)
#define _GNU_SOURCE 1
#endif
#include <stdlib.h>
--
2.30.0.windows.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] Make zpty module work in the cygwin and msys2
2021-01-15 4:29 [PATCH v2] Make zpty module work in the cygwin and msys2 Peiyuan Song
@ 2021-01-16 18:34 ` Bart Schaefer
2021-01-19 1:52 ` Peiyuan Song
0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2021-01-16 18:34 UTC (permalink / raw)
To: zsh-workers; +Cc: Peiyuan Song
On Thu, Jan 14, 2021 at 8:30 PM Peiyuan Song <squallatf@gmail.com> wrote:
>
> v2 change: make fdtable[master]
I don't see anything technically wrong with this, but it does
duplicate the code for check_fd_table.
Anyone else have thoughts? Can someone else who compiles on cygwin
give this a once-over?
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] Make zpty module work in the cygwin and msys2
2021-01-16 18:34 ` Bart Schaefer
@ 2021-01-19 1:52 ` Peiyuan Song
0 siblings, 0 replies; 3+ messages in thread
From: Peiyuan Song @ 2021-01-19 1:52 UTC (permalink / raw)
To: Bart Schaefer; +Cc: zsh-workers
Bart Schaefer <schaefer@brasslantern.com> 于2021年1月17日周日 上午2:34写道:
>
> On Thu, Jan 14, 2021 at 8:30 PM Peiyuan Song <squallatf@gmail.com> wrote:
> >
> > v2 change: make fdtable[master]
>
> I don't see anything technically wrong with this, but it does
> duplicate the code for check_fd_table.
>
> Anyone else have thoughts? Can someone else who compiles on cygwin
> give this a once-over?
I have upload v3 patch, remove duplicate the code for check_fd_table,
use addmodulefd api. assume cygwin upstream issue will be fixed in
version 3.2.0
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-01-19 1:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-15 4:29 [PATCH v2] Make zpty module work in the cygwin and msys2 Peiyuan Song
2021-01-16 18:34 ` Bart Schaefer
2021-01-19 1:52 ` Peiyuan Song
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).