dvtm

dynamic virtual terminal manager - with my changes
git clone https://pi.duncano.de/git/dvtm.git
Log | Files | Refs | README | LICENSE

commit 2b3a544dc0197426b5841c8bf2131477e6f86667
parent 2ca3eda7906809958c5b4b8c83913932a4266040
Author: Bergman Andrey <vkni@yandex.ru>
Date:   Tue,  8 Jul 2014 22:56:53 +0200

Solaris support

Diffstat:
Makefile | 6+++---
config.mk | 5++++-
dvtm.c | 2+-
forkpty-sunos.c | 88+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
vt.c | 4+++-
5 files changed, 99 insertions(+), 6 deletions(-)

diff --git a/Makefile b/Makefile @@ -35,9 +35,9 @@ dist: clean @echo creating dist tarball @mkdir -p dvtm-${VERSION} @cp -R LICENSE Makefile README testsuite.sh config.def.h config.mk \ - ${SRC} vt.h forkpty-aix.c tile.c bstack.c tstack.c vstack.c \ - grid.c fullscreen.c fibonacci.c dvtm-status dvtm.info dvtm.1 \ - dvtm-${VERSION} + ${SRC} vt.h forkpty-aix.c forkpty-sunos.c tile.c bstack.c \ + tstack.c vstack.c grid.c fullscreen.c fibonacci.c \ + dvtm-status dvtm.info dvtm.1 dvtm-${VERSION} @tar -cf dvtm-${VERSION}.tar dvtm-${VERSION} @gzip dvtm-${VERSION}.tar @rm -rf dvtm-${VERSION} diff --git a/config.mk b/config.mk @@ -12,8 +12,11 @@ LIBS = -lc -lutil -lncursesw #LIBS = -lc -lutil -lcurses # AIX #LIBS = -lc -lncursesw +# Solaris +#INCS = -I/usr/include/ncurses +#LIBS = -lc -lncursesw # Cygwin -#INCS += -I/usr/include/ncurses +#INCS = -I/usr/include/ncurses CFLAGS += -std=c99 -Os ${INCS} -DVERSION=\"${VERSION}\" -DNDEBUG LDFLAGS += ${LIBS} diff --git a/dvtm.c b/dvtm.c @@ -27,7 +27,7 @@ #include <unistd.h> #include <stdbool.h> #include <errno.h> -#ifdef __CYGWIN__ +#if defined __CYGWIN__ || defined __sun # include <termios.h> #endif #include "vt.h" diff --git a/forkpty-sunos.c b/forkpty-sunos.c @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER + * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/types.h> +#include <sys/ioctl.h> +#include <fcntl.h> +#include <stdlib.h> +#include <strings.h> +#include <stropts.h> +#include <unistd.h> + +#ifndef TTY_NAME_MAX +#define TTY_NAME_MAX TTYNAME_MAX +#endif + +pid_t forkpty(int *master, char *name, struct termios *tio, struct winsize *ws) +{ + int slave; + char *path; + pid_t pid; + + if ((*master = open("/dev/ptmx", O_RDWR|O_NOCTTY)) == -1) + return -1; + if (grantpt(*master) != 0) + goto out; + if (unlockpt(*master) != 0) + goto out; + + if ((path = ptsname(*master)) == NULL) + goto out; + if (name != NULL) + strlcpy(name, path, TTY_NAME_MAX); + if ((slave = open(path, O_RDWR|O_NOCTTY)) == -1) + goto out; + + switch (pid = fork()) { + case -1: + goto out; + case 0: + close(*master); + + setsid(); +#ifdef TIOCSCTTY + if (ioctl(slave, TIOCSCTTY, NULL) == -1) + return -1; +#endif + + if (ioctl(slave, I_PUSH, "ptem") == -1) + return -1; + if (ioctl(slave, I_PUSH, "ldterm") == -1) + return -1; + + if (tio != NULL && tcsetattr(slave, TCSAFLUSH, tio) == -1) + return -1; + if (ioctl(slave, TIOCSWINSZ, ws) == -1) + return -1; + + dup2(slave, 0); + dup2(slave, 1); + dup2(slave, 2); + if (slave > 2) + close(slave); + return 0; + } + + close(slave); + return pid; + +out: + if (*master != -1) + close(*master); + if (slave != -1) + close(slave); + return -1; +} diff --git a/vt.c b/vt.c @@ -38,7 +38,7 @@ #elif defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__) # include <util.h> #endif -#if defined(__CYGWIN__) || defined(_AIX) +#if defined(__CYGWIN__) || defined(_AIX) || defined(__sun) # include <alloca.h> #endif @@ -46,6 +46,8 @@ #ifdef _AIX # include "forkpty-aix.c" +#elif defined __sun +# include "forkpty-sunos.c" #endif #ifndef NCURSES_ATTR_SHIFT