abduco

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | LICENSE

commit 119d7c8bca2351508bd0c769de496386a0b75469
parent 6df4421e6cf24d87949cda3270659539deab9a03
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Mon,  7 Jul 2014 22:46:14 +0200

Add Solaris support

Diffstat:
Makefile | 3++-
abduco.c | 4+++-
forkpty-sunos.c | 84+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 89 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile @@ -35,7 +35,8 @@ dist: clean @echo creating dist tarball @mkdir -p abduco-${VERSION} @cp -R LICENSE Makefile README testsuite.sh config.def.h config.mk \ - ${SRC} debug.c client.c server.c forkpty-aix.c abduco.1 abduco-${VERSION} + ${SRC} debug.c client.c server.c forkpty-aix.c forkpty-sunos.c \ + abduco.1 abduco-${VERSION} @tar -cf abduco-${VERSION}.tar abduco-${VERSION} @gzip abduco-${VERSION}.tar @rm -rf abduco-${VERSION} diff --git a/abduco.c b/abduco.c @@ -52,8 +52,10 @@ #include "config.h" -#ifdef _AIX +#if defined(_AIX) # include "forkpty-aix.c" +#elif defined(__sun) || defined(__sun__) +# include "forkpty-sunos.c" #endif #define countof(arr) (sizeof(arr) / sizeof((arr)[0])) diff --git a/forkpty-sunos.c b/forkpty-sunos.c @@ -0,0 +1,84 @@ +/* + * 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> + +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; +}