dvtm

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

commit 76bcc767a14becb9199f0565b5eb27d4c9a68129
parent 7133419a30dd1720d6da8602a2e7edcad83409d8
Author: Ross Mohn <rpmohn@waxandwane.org>
Date:   Sun,  8 Jul 2012 17:19:15 +0200

AIX support

Signed-off-by: Marc Andre Tanner <mat@brain-dump.org>

Diffstat:
Makefile | 4++--
config.mk | 3++-
dvtm.c | 3+++
forkpty-aix.c | 101+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
vt.c | 4++++
5 files changed, 112 insertions(+), 3 deletions(-)

diff --git a/Makefile b/Makefile @@ -32,8 +32,8 @@ dist: clean @echo creating dist tarball @mkdir -p dvtm-${VERSION} @cp -R LICENSE Makefile README config.h config.mk \ - ${SRC} tile.c bstack.c tstack.c grid.c fullscreen.c \ - fibonacci.c vt.h dvtm-status dvtm.1 dvtm-${VERSION} + ${SRC} vt.h forkpty-aix.c tile.c bstack.c tstack.c grid.c fullscreen.c \ + fibonacci.c dvtm-status 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 @@ -8,7 +8,8 @@ MANPREFIX = ${PREFIX}/share/man INCS = -I. -I/usr/include -I/usr/local/include LIBS = -lc -lutil -lncursesw -#LIBS = -lc -lutil -lncurses +# For AIX, remove -lutil +#LIBS = -lc -lncursesw CFLAGS += -std=c99 -Os ${INCS} -DVERSION=\"${VERSION}\" -DNDEBUG LDFLAGS += -L/usr/lib -L/usr/local/lib ${LIBS} diff --git a/dvtm.c b/dvtm.c @@ -80,6 +80,9 @@ typedef struct { } ColorRule; #define ALT(k) ((k) + (161 - 'a')) +#if defined CTRL && defined _AIX + #undef CTRL +#endif #ifndef CTRL #define CTRL(k) ((k) & 0x1F) #endif diff --git a/forkpty-aix.c b/forkpty-aix.c @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net> + * Copyright (c) 2012 Ross Palmer Mohn <rpmohn@waxandwane.org> + * + * 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 <stropts.h> +#include <unistd.h> +#include <paths.h> + +/* Fatal errors. */ +#ifdef NDEBUG + #define debug(format, args...) +#else + #define debug eprint +#endif +#define fatal(msg) debug("%s: %s", __func__, msg); + +pid_t +forkpty(int *master, char *name, struct termios *tio, struct winsize *ws) +{ + int slave, fd; + char *path; + pid_t pid; + + if ((*master = open("/dev/ptc", O_RDWR|O_NOCTTY)) == -1) + return (-1); + + if ((path = ttyname(*master)) == NULL) + goto out; + if ((slave = open(path, O_RDWR|O_NOCTTY)) == -1) + goto out; + + switch (pid = fork()) { + case -1: + goto out; + case 0: + close(*master); + + fd = open(_PATH_TTY, O_RDWR|O_NOCTTY); + if (fd >= 0) { + ioctl(fd, TIOCNOTTY, NULL); + close(fd); + } + + if (setsid() < 0) + fatal("setsid"); + + fd = open(_PATH_TTY, O_RDWR|O_NOCTTY); + if (fd >= 0) + fatal("open succeeded (failed to disconnect)"); + + fd = open(path, O_RDWR); + if (fd < 0) + fatal("open failed"); + close(fd); + + fd = open("/dev/tty", O_WRONLY); + if (fd < 0) + fatal("open failed"); + close(fd); + + if (tio != NULL && tcsetattr(slave, TCSAFLUSH, tio) == -1) + fatal("tcsetattr failed"); + if (ioctl(slave, TIOCSWINSZ, ws) == -1) + fatal("ioctl failed"); + + 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 @@ -42,6 +42,10 @@ #include "vt.h" +#ifdef _AIX +# include "forkpty-aix.c" +#endif + #ifndef NCURSES_ATTR_SHIFT # define NCURSES_ATTR_SHIFT 8 #endif