git: 5ba8ffefe59e - main - mail/xmail: Fix pty handling

From: Cy Schubert <cy_at_FreeBSD.org>
Date: Tue, 18 Jul 2023 14:57:07 UTC
The branch main has been updated by cy:

URL: https://cgit.FreeBSD.org/ports/commit/?id=5ba8ffefe59e7d478164fcacaae5e5aa720c402c

commit 5ba8ffefe59e7d478164fcacaae5e5aa720c402c
Author:     Cy Schubert <cy@FreeBSD.org>
AuthorDate: 2023-07-18 14:10:12 +0000
Commit:     Cy Schubert <cy@FreeBSD.org>
CommitDate: 2023-07-18 14:56:40 +0000

    mail/xmail: Fix pty handling
    
    Modernize to work with openpty(). Else we get this:
    
            Error: xmail cannot open master/slave pipe connection
    
    MFH:    2023Q3
---
 mail/xmail/Makefile               |  2 +-
 mail/xmail/files/patch-Imakefile  |  6 ++---
 mail/xmail/files/patch-callMail.c | 50 ++++++++++++++++++++++++++++++++++-----
 3 files changed, 48 insertions(+), 10 deletions(-)

diff --git a/mail/xmail/Makefile b/mail/xmail/Makefile
index 2b2d48a81e30..092e307b2878 100644
--- a/mail/xmail/Makefile
+++ b/mail/xmail/Makefile
@@ -14,7 +14,7 @@ LICENSE_FILE=	${WRKSRC}/COPYRIGHT
 USES=		imake xorg
 USE_XORG=	ice sm x11 xaw xbitmaps xext xmu xpm xt
 
-CFLAGS+=	-Wno-incompatible-function-pointer-types
+CFLAGS+=	-Wno-incompatible-function-pointer-types -lutil
 
 post-patch:
 # Fix the build with -fno-common (for Clang 11 and GCC 10)
diff --git a/mail/xmail/files/patch-Imakefile b/mail/xmail/files/patch-Imakefile
index fd65a954a33a..fb417e91b9bd 100644
--- a/mail/xmail/files/patch-Imakefile
+++ b/mail/xmail/files/patch-Imakefile
@@ -1,5 +1,5 @@
---- Imakefile.orig	Mon Jan 30 22:41:47 1995
-+++ Imakefile	Wed Oct 15 09:52:37 2003
+--- Imakefile.orig	1995-01-30 13:41:47.000000000 -0800
++++ Imakefile	2023-07-18 07:06:05.053673000 -0700
 @@ -1,63 +1,62 @@
 -/* */#
 -/* */# @(#)Imakefile - for xmail version 1 patchlevel 5
@@ -103,7 +103,7 @@
  
          DEPLIBS = $(DEPXAWLIB) $(DEPXMULIB) $(DEPXTOOLLIB) $(DEPXLIB)
 -LOCAL_LIBRARIES = $(LIBXPM) $(XAWLIB) $(XMULIB) $(XTOOLLIB) $(XLIB) $(COMPFACE) $(LPT)
-+LOCAL_LIBRARIES = $(LIBXPM) $(XAWLIB) $(XMULIB) $(XTOOLLIB) $(XLIB) $(COMPFACE) $(LPT) -lcompat
++LOCAL_LIBRARIES = $(LIBXPM) $(XAWLIB) $(XMULIB) $(XTOOLLIB) $(XLIB) $(COMPFACE) $(LPT) -lcompat -lutil
  
             SRCS = Mailwatch.c HelpText.c actions.c callMail.c callbacks.c \
  		  confirm.c directory.c environs.c handler.c mail.c parser.c \
diff --git a/mail/xmail/files/patch-callMail.c b/mail/xmail/files/patch-callMail.c
index 53fcd326af4e..685cdde53584 100644
--- a/mail/xmail/files/patch-callMail.c
+++ b/mail/xmail/files/patch-callMail.c
@@ -1,6 +1,17 @@
---- callMail.c.orig	Thu Jan 26 21:52:01 1995
-+++ callMail.c	Wed Feb  4 23:30:07 1998
-@@ -38,11 +38,10 @@
+--- callMail.c.orig	1995-01-26 21:52:01.000000000 -0800
++++ callMail.c	2023-07-18 07:01:24.570712000 -0700
+@@ -34,15 +34,21 @@
+ #include	<sys/stat.h>
+ #include	<signal.h>
+ 
++#ifdef __FreeBSD__
++#include <sys/types.h>
++#include <sys/ioctl.h>
++#include <termios.h>
++#include <libutil.h>
++#endif
++
+ #if	defined(AIXV3) || defined(_IBMR2)
  #include	<sys/select.h>
  #endif
  
@@ -14,7 +25,7 @@
  #include	<fcntl.h>
  #if	defined(att)
  #include	<sys/stropts.h>
-@@ -81,7 +80,7 @@
+@@ -81,7 +87,7 @@
  #ifdef		hpux
  #define	PTYCHAR2	"fedcba9876543210"
  #else	/* !hpux */
@@ -23,7 +34,23 @@
  #endif	/* !hpux */
  #endif	/* !PTYCHAR2 */
  
-@@ -207,8 +206,8 @@
+@@ -91,6 +97,7 @@
+ char		pseudo_tty[20];
+ 
+ 
++#ifndef __FreeBSD__
+ /*
+ ** @(#) openMaster - searches for and opens a pty master.  If it finds one,
+ **		     it returns the value of the file descriptor.  If not,
+@@ -197,6 +204,7 @@
+ #endif
+  return(-1);				/* look for more master/slave pairs */
+ } /* openSlave */
++#endif /* __FreeBSD__ */
+ 
+ 
+ /*
+@@ -207,30 +215,34 @@
  callMail(argv)
  char *argv[];
  {
@@ -34,7 +61,18 @@
  #else	
   struct sgttyb	Sgtty;
  #endif
-@@ -223,14 +222,14 @@
+  int		slave;			/* file descriptor to slave pty */
+ 
+ 
++#ifdef __FreeBSD__
++ openpty(&mail_fd, &slave, NULL, NULL, NULL);
++#else
+  for (;;) {				/* find a pair, or master fails */
+      mail_fd = openMaster();
+      if ((slave = openSlave(mail_fd)) != -1)
+         break;
+     }
++#endif
  /*
  ** Set minimal requirements for slave connection (no echo, no NL->CR, keep TABS)
  */