Added forkpty() and cfmakeraw() fallback implementations if they don't exist.
Signed-off-by: Timo Sirainen <tss@iki.fi>
This commit is contained in:
committed by
Keith Winstein
parent
cc0542dfe1
commit
0c5307f345
@@ -15,16 +15,16 @@ decrypt_LDADD = ../crypto/libmoshcrypto.a $(OPENSSL_LIBS)
|
||||
|
||||
parse_SOURCES = parse.cc
|
||||
parse_CPPFLAGS = -I$(srcdir)/../terminal -I$(srcdir)/../util
|
||||
parse_LDADD = ../terminal/libmoshterminal.a ../util/libmoshutil.a -lutil
|
||||
parse_LDADD = ../terminal/libmoshterminal.a ../util/libmoshutil.a $(LIBUTIL)
|
||||
|
||||
termemu_SOURCES = termemu.cc
|
||||
termemu_CPPFLAGS = -I$(srcdir)/../terminal -I$(srcdir)/../util -I$(srcdir)/../statesync -I../protobufs
|
||||
termemu_LDADD = ../terminal/libmoshterminal.a ../util/libmoshutil.a ../statesync/libmoshstatesync.a ../protobufs/libmoshprotos.a -lutil $(TINFO_LIBS) $(protobuf_LIBS)
|
||||
termemu_LDADD = ../terminal/libmoshterminal.a ../util/libmoshutil.a ../statesync/libmoshstatesync.a ../protobufs/libmoshprotos.a $(LIBUTIL) $(TINFO_LIBS) $(protobuf_LIBS)
|
||||
|
||||
ntester_SOURCES = ntester.cc
|
||||
ntester_CPPFLAGS = -I$(srcdir)/../util -I$(srcdir)/../statesync -I$(srcdir)/../terminal -I$(srcdir)/../network -I$(srcdir)/../crypto -I../protobufs $(protobuf_CFLAGS)
|
||||
ntester_LDADD = ../statesync/libmoshstatesync.a ../terminal/libmoshterminal.a ../network/libmoshnetwork.a ../crypto/libmoshcrypto.a ../protobufs/libmoshprotos.a ../util/libmoshutil.a -lutil -lm $(protobuf_LIBS) $(OPENSSL_LIBS)
|
||||
ntester_LDADD = ../statesync/libmoshstatesync.a ../terminal/libmoshterminal.a ../network/libmoshnetwork.a ../crypto/libmoshcrypto.a ../protobufs/libmoshprotos.a ../util/libmoshutil.a $(LIBUTIL) -lm $(protobuf_LIBS) $(OPENSSL_LIBS)
|
||||
|
||||
benchmark_SOURCES = benchmark.cc
|
||||
benchmark_CPPFLAGS = -I$(srcdir)/../util -I$(srcdir)/../statesync -I$(srcdir)/../terminal -I../protobufs -I$(srcdir)/../frontend -I$(srcdir)/../crypto -I$(srcdir)/../network $(protobuf_CFLAGS)
|
||||
benchmark_LDADD = ../frontend/terminaloverlay.o ../statesync/libmoshstatesync.a ../terminal/libmoshterminal.a ../protobufs/libmoshprotos.a ../network/libmoshnetwork.a ../crypto/libmoshcrypto.a ../util/libmoshutil.a $(STDDJB_LDFLAGS) -lutil -lm $(TINFO_LIBS) $(protobuf_LIBS) $(OPENSSL_LIBS)
|
||||
benchmark_LDADD = ../frontend/terminaloverlay.o ../statesync/libmoshstatesync.a ../terminal/libmoshterminal.a ../protobufs/libmoshprotos.a ../network/libmoshnetwork.a ../crypto/libmoshcrypto.a ../util/libmoshutil.a $(STDDJB_LDFLAGS) $(LIBUTIL) -lm $(TINFO_LIBS) $(protobuf_LIBS) $(OPENSSL_LIBS)
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
|
||||
#include "user.h"
|
||||
#include "fatal_assert.h"
|
||||
#include "pty_compat.h"
|
||||
#include "networktransport.cc"
|
||||
#include "select.h"
|
||||
|
||||
|
||||
@@ -56,6 +56,7 @@
|
||||
#include "swrite.h"
|
||||
#include "locale_utils.h"
|
||||
#include "fatal_assert.h"
|
||||
#include "pty_compat.h"
|
||||
#include "select.h"
|
||||
|
||||
const size_t buf_size = 1024;
|
||||
|
||||
@@ -62,6 +62,7 @@
|
||||
#include "completeterminal.h"
|
||||
#include "swrite.h"
|
||||
#include "fatal_assert.h"
|
||||
#include "pty_compat.h"
|
||||
#include "locale_utils.h"
|
||||
#include "select.h"
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ AM_CXXFLAGS = $(WARNING_CXXFLAGS) $(PICKY_CXXFLAGS) $(HARDEN_CFLAGS) $(MISC_CXXF
|
||||
AM_LDFLAGS = $(HARDEN_LDFLAGS)
|
||||
LDADD = ../crypto/libmoshcrypto.a ../network/libmoshnetwork.a ../statesync/libmoshstatesync.a ../terminal/libmoshterminal.a ../util/libmoshutil.a ../protobufs/libmoshprotos.a -lm $(TINFO_LIBS) $(protobuf_LIBS) $(OPENSSL_LIBS)
|
||||
|
||||
mosh_server_LDADD = $(LDADD) -lutil
|
||||
mosh_server_LDADD = $(LDADD) $(LIBUTIL)
|
||||
|
||||
bin_PROGRAMS =
|
||||
|
||||
|
||||
@@ -58,14 +58,6 @@
|
||||
#include <paths.h>
|
||||
#endif
|
||||
|
||||
#include "completeterminal.h"
|
||||
#include "swrite.h"
|
||||
#include "user.h"
|
||||
#include "fatal_assert.h"
|
||||
#include "locale_utils.h"
|
||||
#include "select.h"
|
||||
#include "timestamp.h"
|
||||
|
||||
#if HAVE_PTY_H
|
||||
#include <pty.h>
|
||||
#elif HAVE_UTIL_H
|
||||
@@ -76,6 +68,15 @@
|
||||
#include <libutil.h>
|
||||
#endif
|
||||
|
||||
#include "completeterminal.h"
|
||||
#include "swrite.h"
|
||||
#include "user.h"
|
||||
#include "fatal_assert.h"
|
||||
#include "locale_utils.h"
|
||||
#include "pty_compat.h"
|
||||
#include "select.h"
|
||||
#include "timestamp.h"
|
||||
|
||||
#ifndef _PATH_BSHELL
|
||||
#define _PATH_BSHELL "/bin/sh"
|
||||
#endif
|
||||
|
||||
@@ -56,6 +56,7 @@
|
||||
#include "user.h"
|
||||
#include "fatal_assert.h"
|
||||
#include "locale_utils.h"
|
||||
#include "pty_compat.h"
|
||||
#include "select.h"
|
||||
#include "timestamp.h"
|
||||
|
||||
|
||||
@@ -2,4 +2,4 @@ AM_CXXFLAGS = $(WARNING_CXXFLAGS) $(PICKY_CXXFLAGS) $(HARDEN_CFLAGS) $(MISC_CXXF
|
||||
|
||||
noinst_LIBRARIES = libmoshutil.a
|
||||
|
||||
libmoshutil_a_SOURCES = locale_utils.cc locale_utils.h swrite.cc swrite.h dos_assert.h fatal_assert.h select.h select.cc timestamp.h timestamp.cc
|
||||
libmoshutil_a_SOURCES = locale_utils.cc locale_utils.h swrite.cc swrite.h dos_assert.h fatal_assert.h select.h select.cc timestamp.h timestamp.cc pty_compat.cc pty_compat.h
|
||||
|
||||
@@ -0,0 +1,165 @@
|
||||
/*
|
||||
Mosh: the mobile shell
|
||||
Copyright 2012 Keith Winstein
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
In addition, as a special exception, the copyright holders give
|
||||
permission to link the code of portions of this program with the
|
||||
OpenSSL library under certain conditions as described in each
|
||||
individual source file, and distribute linked combinations including
|
||||
the two.
|
||||
|
||||
You must obey the GNU General Public License in all respects for all
|
||||
of the code used other than OpenSSL. If you modify file(s) with this
|
||||
exception, you may extend this exception to your version of the
|
||||
file(s), but you are not obligated to do so. If you do not wish to do
|
||||
so, delete this exception statement from your version. If you delete
|
||||
this exception statement from all source files in the program, then
|
||||
also delete it here.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#if !defined(HAVE_FORKPTY) || !defined(HAVE_CFMAKERAW)
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/stropts.h>
|
||||
#include <termios.h>
|
||||
|
||||
#include "pty_compat.h"
|
||||
|
||||
#ifndef HAVE_FORKPTY
|
||||
pid_t my_forkpty( int *amaster, char *name,
|
||||
const struct termios *termp,
|
||||
const struct winsize *winp )
|
||||
{
|
||||
/* For Solaris */
|
||||
int master, slave;
|
||||
char *slave_name;
|
||||
pid_t pid;
|
||||
|
||||
master = open( "/dev/ptmx", O_RDWR | O_NOCTTY );
|
||||
if ( master < 0 ) {
|
||||
perror( "open(/dev/ptmx)" );
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ( grantpt( master ) < 0 ) {
|
||||
perror( "grantpt" );
|
||||
close( master );
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ( unlockpt(master) < 0 ) {
|
||||
perror( "unlockpt" );
|
||||
close( master );
|
||||
return -1;
|
||||
}
|
||||
|
||||
slave_name = ptsname( master );
|
||||
if ( slave_name == NULL ) {
|
||||
perror( "ptsname" );
|
||||
close( master );
|
||||
return -1;
|
||||
}
|
||||
|
||||
slave = open( slave_name, O_RDWR | O_NOCTTY );
|
||||
if ( slave < 0 ) {
|
||||
perror( "open(slave)" );
|
||||
close( master );
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ( ioctl(slave, I_PUSH, "ptem") < 0 ||
|
||||
ioctl(slave, I_PUSH, "ldterm") < 0 ) {
|
||||
perror( "ioctl(I_PUSH)" );
|
||||
close( slave );
|
||||
close( master );
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ( amaster != NULL )
|
||||
*amaster = master;
|
||||
|
||||
if ( name != NULL)
|
||||
strcpy( name, slave_name );
|
||||
|
||||
if ( termp != NULL ) {
|
||||
if ( tcsetattr( slave, TCSAFLUSH, termp ) < 0 ) {
|
||||
perror( "tcsetattr" );
|
||||
exit( 1 );
|
||||
}
|
||||
}
|
||||
|
||||
// we need to set initial window size, or TIOCGWINSZ fails
|
||||
struct winsize w;
|
||||
w.ws_row = 25;
|
||||
w.ws_col = 80;
|
||||
w.ws_xpixel = 0;
|
||||
w.ws_ypixel = 0;
|
||||
if ( ioctl( slave, TIOCSWINSZ, &w) < 0 ) {
|
||||
perror( "ioctl TIOCSWINSZ" );
|
||||
exit( 1 );
|
||||
}
|
||||
if ( winp != NULL ) {
|
||||
if ( ioctl( slave, TIOCGWINSZ, winp ) < 0 ) {
|
||||
perror( "ioctl TIOCGWINSZ" );
|
||||
exit( 1 );
|
||||
}
|
||||
}
|
||||
|
||||
pid = fork();
|
||||
switch ( pid ) {
|
||||
case -1: /* Error */
|
||||
perror( "fork()" );
|
||||
return -1;
|
||||
case 0: /* Child */
|
||||
if ( setsid() < 0 )
|
||||
perror( "setsid" );
|
||||
if ( ioctl( slave, TIOCSCTTY, NULL ) < 0 ) {
|
||||
perror( "ioctl" );
|
||||
return -1;
|
||||
}
|
||||
close( master );
|
||||
dup2( slave, STDIN_FILENO );
|
||||
dup2( slave, STDOUT_FILENO );
|
||||
dup2( slave, STDERR_FILENO );
|
||||
return 0;
|
||||
default: /* Parent */
|
||||
close( slave );
|
||||
return pid;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_CFMAKERAW
|
||||
void my_cfmakeraw( struct termios *termios_p )
|
||||
{
|
||||
termios_p->c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP
|
||||
| INLCR | IGNCR | ICRNL | IXON);
|
||||
termios_p->c_oflag &= ~OPOST;
|
||||
termios_p->c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
|
||||
termios_p->c_cflag &= ~(CSIZE | PARENB);
|
||||
termios_p->c_cflag |= CS8;
|
||||
|
||||
termios_p->c_cc[VMIN] = 1; // read() is satisfied after 1 char
|
||||
termios_p->c_cc[VTIME] = 0; // No timer
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
Mosh: the mobile shell
|
||||
Copyright 2012 Keith Winstein
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
In addition, as a special exception, the copyright holders give
|
||||
permission to link the code of portions of this program with the
|
||||
OpenSSL library under certain conditions as described in each
|
||||
individual source file, and distribute linked combinations including
|
||||
the two.
|
||||
|
||||
You must obey the GNU General Public License in all respects for all
|
||||
of the code used other than OpenSSL. If you modify file(s) with this
|
||||
exception, you may extend this exception to your version of the
|
||||
file(s), but you are not obligated to do so. If you do not wish to do
|
||||
so, delete this exception statement from your version. If you delete
|
||||
this exception statement from all source files in the program, then
|
||||
also delete it here.
|
||||
*/
|
||||
|
||||
#ifndef PTY_COMPAT_HPP
|
||||
#define PTY_COMPAT_HPP
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#ifndef HAVE_FORKPTY
|
||||
# define forkpty my_forkpty
|
||||
#endif
|
||||
#ifndef HAVE_CFMAKERAW
|
||||
# define cfmakeraw my_cfmakeraw
|
||||
#endif
|
||||
|
||||
pid_t my_forkpty( int *amaster, char *name,
|
||||
const struct termios *termp,
|
||||
const struct winsize *winp );
|
||||
|
||||
void my_cfmakeraw( struct termios *termios_p );
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user