From e704d6aee2b9e8864589d1960ac15726bb0cd35c Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Mon, 23 Jun 2008 21:54:48 +0000 Subject: [PATCH] IRIX fixes, sort of partly work. --- GNUmakefile | 8 ++-- compat/asprintf.c | 35 +++++++++++++++++- compat/forkpty-irix.c | 83 ++++++++++++++++++++++++++++++++++++++++++ compat/forkpty-sunos.c | 7 +++- status.c | 13 ++++++- 5 files changed, 138 insertions(+), 8 deletions(-) create mode 100644 compat/forkpty-irix.c diff --git a/GNUmakefile b/GNUmakefile index 17cf030d..cc6133d2 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -1,4 +1,4 @@ -# $Id: GNUmakefile,v 1.31 2008-06-23 16:58:49 nicm Exp $ +# $Id: GNUmakefile,v 1.32 2008-06-23 21:54:48 nicm Exp $ .PHONY: clean @@ -56,10 +56,10 @@ INSTALLMAN= install -g bin -o root -m 444 ifeq ($(shell uname),IRIX64) INCDIRS+= -Icompat -I/usr/local/include/ncurses SRCS+= compat/strlcpy.c compat/strtonum.c compat/daemon.c \ - compat/asprintf.c compat/fgetln.c + compat/asprintf.c compat/fgetln.c compat/forkpty-irix.c CFLAGS+= -DNO_STRLCPY -DNO_STRTONUM -DNO_TREE_H -DNO_SETPROCTITLE \ -DNO_DAEMON -DNO_FORKPTY -DNO_PROGNAME -DNO_ASPRINTF -DNO_FGETLN \ - -D_SGI_SOURCE -std=c99 + -DBROKEN_VSNPRINTF -D_SGI_SOURCE -std=c99 LDFLAGS+= -L/usr/local/lib LIBS+= -lgen endif @@ -99,7 +99,7 @@ CPPFLAGS+= $(INCDIRS) all: $(PROG) $(PROG): $(OBJS) - $(CC) $(LDFLAGS) $(LIBS) -o $@ $+ + $(CC) $(LDFLAGS) -o $@ $+ $(LIBS) depend: $(SRCS) $(CC) $(CFLAGS) $(INCDIRS) -MM $(SRCS) > .depend diff --git a/compat/asprintf.c b/compat/asprintf.c index f3ec7ef7..05e8dd24 100644 --- a/compat/asprintf.c +++ b/compat/asprintf.c @@ -1,4 +1,4 @@ -/* $Id: asprintf.c,v 1.2 2008-06-18 22:21:51 nicm Exp $ */ +/* $Id: asprintf.c,v 1.3 2008-06-23 21:54:48 nicm Exp $ */ /* * Copyright (c) 2006 Nicholas Marriott @@ -16,7 +16,9 @@ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include #include +#include #include #include "tmux.h" @@ -34,6 +36,7 @@ asprintf(char **ret, const char *format, ...) return (n); } +#ifndef BROKEN_VSNPRINTF int vasprintf(char **ret, const char *format, va_list ap) { @@ -54,3 +57,33 @@ error: *ret = NULL; return (-1); } +#else +int +vasprintf(char **ret, const char *fmt, va_list ap) +{ + va_list aq; + size_t len; + char *buf; + int n; + + len = 64; + buf = xmalloc(len); + + for (;;) { + va_copy(aq, ap); + n = vsnprintf(buf, len, fmt, aq); + va_end(aq); + + if (n != -1) { + *ret = buf; + return (n); + } + + if (len > SIZE_MAX / 2) { + xfree(buf); + return (-1); + } + len *= 2; + } +} +#endif diff --git a/compat/forkpty-irix.c b/compat/forkpty-irix.c new file mode 100644 index 00000000..1e0f689e --- /dev/null +++ b/compat/forkpty-irix.c @@ -0,0 +1,83 @@ +/* $Id: forkpty-irix.c,v 1.1 2008-06-23 21:54:48 nicm Exp $ */ + +/* + * Copyright (c) 2008 Nicholas Marriott + * + * 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 +#include +#include + +#include +#include +#include +#include + +#include "tmux.h" + +pid_t +forkpty(int *master, + unused char *name, unused struct termios *tio, struct winsize *ws) +{ + int slave, fd; + char *path; + pid_t pid; + void *old; + + path = _getpty(master, O_RDWR, 0622, 0); + if (path == 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); + + setsid(); + + old = signal(SIGHUP, SIG_IGN); + vhangup(); + signal(SIGHUP, old); + + if ((fd = open(path, O_RDWR)) == -1) + fatal("open failed"); + close(slave); + slave = fd; + + 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/compat/forkpty-sunos.c b/compat/forkpty-sunos.c index bc4fe8a3..a4b1dbdf 100644 --- a/compat/forkpty-sunos.c +++ b/compat/forkpty-sunos.c @@ -1,7 +1,7 @@ -/* $Id: forkpty-sunos.c,v 1.5 2008-06-18 22:21:51 nicm Exp $ */ +/* $Id: forkpty-sunos.c,v 1.6 2008-06-23 21:54:48 nicm Exp $ */ /* - * Copyright (c) 2007 Nicholas Marriott + * Copyright (c) 2008 Nicholas Marriott * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -17,6 +17,7 @@ */ #include +#include #include #include @@ -52,8 +53,10 @@ forkpty(int *master, close(*master); setsid(); +#ifdef TIOCSCTTY if (ioctl(slave, TIOCSCTTY, NULL) == -1) fatal("ioctl failed"); +#endif if (ioctl(slave, I_PUSH, "ptem") == -1) fatal("ioctl failed"); diff --git a/status.c b/status.c index 1c82c9eb..2a880eaf 100644 --- a/status.c +++ b/status.c @@ -1,4 +1,4 @@ -/* $Id: status.c,v 1.39 2008-06-23 16:58:49 nicm Exp $ */ +/* $Id: status.c,v 1.40 2008-06-23 21:54:48 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -255,7 +255,18 @@ off: size_t status_width(struct winlink *wl) { +#ifndef BROKEN_VSNPRINTF return (xsnprintf(NULL, 0, "%d:%s ", wl->idx, wl->window->name)); +#else + char *s; + size_t n; + + xasprintf(&s, "%d:%s ", wl->idx, wl->window->name); + n = strlen(s); + xfree(s); + + return (n); +#endif } char *