From 82d4a8bb686836a91ad058f3681f131440c3ae2f Mon Sep 17 00:00:00 2001 From: Liang Chang Date: Tue, 20 Apr 2021 08:46:54 +0800 Subject: [PATCH] DtTerm: Add pts driver support. --- cde/lib/DtTerm/TermPrim/Imakefile | 4 + cde/lib/DtTerm/TermPrim/TermPrimGetPty-pts.c | 104 +++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 cde/lib/DtTerm/TermPrim/TermPrimGetPty-pts.c diff --git a/cde/lib/DtTerm/TermPrim/Imakefile b/cde/lib/DtTerm/TermPrim/Imakefile index 0f209613f..46cf8b4ae 100644 --- a/cde/lib/DtTerm/TermPrim/Imakefile +++ b/cde/lib/DtTerm/TermPrim/Imakefile @@ -77,6 +77,9 @@ OBJS = \ #include +#if defined(HasPtsDriver) && HasPtsDriver +LinkFile(TermPrimGetPty.c,TermPrimGetPty-pts.c) +#else /* These should be cleaned up. Test SVR4Architecture? */ #ifdef AlphaArchitecture LinkFile(TermPrimGetPty.c,TermPrimGetPty-bsd.c) @@ -105,6 +108,7 @@ LinkFile(TermPrimGetPty.c,TermPrimGetPty-svr4.c) #ifdef BSDArchitecture LinkFile(TermPrimGetPty.c,TermPrimGetPty-bsd.c) #endif +#endif SubdirLibraryRule($(OBJS)) diff --git a/cde/lib/DtTerm/TermPrim/TermPrimGetPty-pts.c b/cde/lib/DtTerm/TermPrim/TermPrimGetPty-pts.c new file mode 100644 index 000000000..ed5b0af73 --- /dev/null +++ b/cde/lib/DtTerm/TermPrim/TermPrimGetPty-pts.c @@ -0,0 +1,104 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* * + * (c) Copyright 1993, 1994 Hewlett-Packard Company * + * (c) Copyright 1993, 1994 International Business Machines Corp. * + * (c) Copyright 1993, 1994 Sun Microsystems, Inc. * + * (c) Copyright 1993, 1994 Novell, Inc. * + */ + +#ifndef _XOPEN_SOURCE +#define _XOPEN_SOURCE 600 +#endif + +#include "TermPrim.h" +#include "TermPrimDebug.h" +#include "TermHeader.h" +#include +#include +#include + +int +_DtTermPrimGetPty(char **ptySlave, char **ptyMaster) +{ + char *c; + int ptyFd; + + *ptyMaster = NULL; + + if (isDebugFSet('p', 10)) { +#ifdef BBA +#pragma BBA_IGNORE +#endif /*BBA*/ + return(-1); + } + + if ((ptyFd = posix_openpt(O_RDWR)) >= 0) { + + /* use grantpt to prevent other processes from grabbing the tty that + * goes with the pty master we have opened. It is a mandatory step + * in the SVR4 pty-tty initialization. Note that /dev must be + * mounted read/write... + */ + Debug('T', timeStamp("_DtTermPrimGetPty() calling grantpt()")); + if (grantpt(ptyFd) == -1) { + (void) perror("grantpt"); + (void) close(ptyFd); + return(-1); + } + + /* Unlock the pty master/slave pair so the slave can be opened later */ + Debug('T', timeStamp("_DtTermPrimGetPty() calling unlockpt()")); + if (unlockpt(ptyFd) == -1) { + (void) perror("unlockpt"); + (void) close(ptyFd); + return(-1); + } + Debug('T', timeStamp("_DtTermPrimGetPty() unlockpt() finished")); + + /* get the pty slave name... */ + if (c = ptsname(ptyFd)) { + *ptySlave = malloc(strlen(c) + 1); + (void) strcpy(*ptySlave, c); + return(ptyFd); + } else { + /* ptsname on the pty master failed. This should not happen!... */ + (void) perror("ptsname"); + (void) close(ptyFd); + } + } else { + (void) perror("posix_openpt"); + } + return(-1); +} + +/* dummy functions */ + +void _DtTermPrimReleasePty(char *ptySlave) {} +void _DtTermPrimPtyCleanup(void) {} + +int +_DtTermPrimSetupPty(char *ptySlave, int ptyFd) +{ + return(0); +}