Make utmp entries using utempter
This commit is contained in:
@@ -12,6 +12,7 @@ AC_PROG_CXX
|
|||||||
AC_PROG_RANLIB
|
AC_PROG_RANLIB
|
||||||
|
|
||||||
# Checks for libraries.
|
# Checks for libraries.
|
||||||
|
AC_SEARCH_LIBS([utempter_remove_added_record], [utempter], , AC_MSG_ERROR([Unable to find libutempter.]))
|
||||||
|
|
||||||
# Checks for header files.
|
# Checks for header files.
|
||||||
AC_CHECK_HEADERS([arpa/inet.h fcntl.h langinfo.h limits.h locale.h netinet/in.h stddef.h stdint.h stdlib.h string.h sys/ioctl.h sys/socket.h sys/time.h termios.h unistd.h wchar.h wctype.h])
|
AC_CHECK_HEADERS([arpa/inet.h fcntl.h langinfo.h limits.h locale.h netinet/in.h stddef.h stdint.h stdlib.h string.h sys/ioctl.h sys/socket.h sys/time.h termios.h unistd.h wchar.h wctype.h])
|
||||||
|
|||||||
Vendored
+2
-2
@@ -2,7 +2,7 @@ Source: mosh
|
|||||||
Section: net
|
Section: net
|
||||||
Priority: optional
|
Priority: optional
|
||||||
Maintainer: Keith Winstein <keithw@mit.edu>
|
Maintainer: Keith Winstein <keithw@mit.edu>
|
||||||
Build-Depends: debhelper (>= 8.0.0), autotools-dev, protobuf-compiler, libprotobuf-dev, dh-autoreconf, pkg-config
|
Build-Depends: debhelper (>= 8.0.0), autotools-dev, protobuf-compiler, libprotobuf-dev, dh-autoreconf, pkg-config, libutempter-dev
|
||||||
Standards-Version: 3.9.2
|
Standards-Version: 3.9.2
|
||||||
Homepage: http://mosh.mit.edu
|
Homepage: http://mosh.mit.edu
|
||||||
Vcs-Git: git://github.com/keithw/mosh.git
|
Vcs-Git: git://github.com/keithw/mosh.git
|
||||||
@@ -10,7 +10,7 @@ Vcs-Browser: http://github.com/keithw/mosh
|
|||||||
|
|
||||||
Package: mosh
|
Package: mosh
|
||||||
Architecture: any
|
Architecture: any
|
||||||
Depends: ${shlibs:Depends}, ${misc:Depends}, libprotobuf-lite7, libio-pty-perl, openssh-client
|
Depends: ${shlibs:Depends}, ${misc:Depends}, libprotobuf-lite7, libio-pty-perl, openssh-client, libutempter0
|
||||||
Description: Mobile shell that supports roaming and intelligent local echo
|
Description: Mobile shell that supports roaming and intelligent local echo
|
||||||
Mosh is a remote terminal application that supports:
|
Mosh is a remote terminal application that supports:
|
||||||
- intermittent network connectivity,
|
- intermittent network connectivity,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
AM_CPPFLAGS = -I$(srcdir)/../statesync -I$(srcdir)/../terminal -I$(srcdir)/../network -I$(srcdir)/../crypto -I$(builddir)/../protobufs -I$(srcdir)/../util
|
AM_CPPFLAGS = -I$(srcdir)/../statesync -I$(srcdir)/../terminal -I$(srcdir)/../network -I$(srcdir)/../crypto -I$(builddir)/../protobufs -I$(srcdir)/../util
|
||||||
AM_CXXFLAGS = --std=c++0x -pedantic -Werror -Wall -Wextra -Weffc++ -fno-default-inline -pipe
|
AM_CXXFLAGS = --std=c++0x -pedantic -Werror -Wall -Wextra -Weffc++ -fno-default-inline -pipe
|
||||||
LIBS = $(protobuf_lite_LIBS)
|
LIBS = $(protobuf_lite_LIBS)
|
||||||
LDADD = ../crypto/libmoshcrypto.a ../network/libmoshnetwork.a ../statesync/libmoshstatesync.a ../terminal/libmoshterminal.a ../util/libmoshutil.a ../protobufs/libmoshprotos.a -lutil -lrt -lm
|
LDADD = ../crypto/libmoshcrypto.a ../network/libmoshnetwork.a ../statesync/libmoshstatesync.a ../terminal/libmoshterminal.a ../util/libmoshutil.a ../protobufs/libmoshprotos.a -lutil -lrt -lm -lutempter
|
||||||
|
|
||||||
bin_PROGRAMS = mosh-client mosh-server
|
bin_PROGRAMS = mosh-client mosh-server
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,10 @@
|
|||||||
#include <typeinfo>
|
#include <typeinfo>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <sys/signalfd.h>
|
#include <sys/signalfd.h>
|
||||||
|
#include <utempter.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
#include "completeterminal.h"
|
#include "completeterminal.h"
|
||||||
#include "swrite.h"
|
#include "swrite.h"
|
||||||
@@ -126,7 +130,7 @@ int main( int argc, char *argv[] )
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Fork child process */
|
/* Fork child process */
|
||||||
pid_t child = forkpty( &master, NULL, &child_termios, NULL );
|
pid_t child = forkpty( &master, NULL, &child_termios, &window_size );
|
||||||
|
|
||||||
if ( child == -1 ) {
|
if ( child == -1 ) {
|
||||||
perror( "forkpty" );
|
perror( "forkpty" );
|
||||||
@@ -178,6 +182,11 @@ int main( int argc, char *argv[] )
|
|||||||
exit( 0 );
|
exit( 0 );
|
||||||
} else {
|
} else {
|
||||||
/* parent */
|
/* parent */
|
||||||
|
/* make utmp entry */
|
||||||
|
char tmp[ 64 ];
|
||||||
|
snprintf( tmp, 64, "mosh [%d]", getpid() );
|
||||||
|
utempter_add_record( master, tmp );
|
||||||
|
|
||||||
try {
|
try {
|
||||||
serve( master, terminal, network );
|
serve( master, terminal, network );
|
||||||
} catch ( Network::NetworkException e ) {
|
} catch ( Network::NetworkException e ) {
|
||||||
@@ -192,6 +201,8 @@ int main( int argc, char *argv[] )
|
|||||||
perror( "close" );
|
perror( "close" );
|
||||||
exit( 1 );
|
exit( 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
utempter_remove_added_record();
|
||||||
}
|
}
|
||||||
|
|
||||||
printf( "\n[mosh-server is exiting.]\n" );
|
printf( "\n[mosh-server is exiting.]\n" );
|
||||||
@@ -228,6 +239,10 @@ void serve( int host_fd, Terminal::Complete &terminal, ServerConnection &network
|
|||||||
|
|
||||||
uint64_t last_remote_num = network.get_remote_state_num();
|
uint64_t last_remote_num = network.get_remote_state_num();
|
||||||
|
|
||||||
|
bool connected_utmp = false;
|
||||||
|
struct in_addr saved_addr;
|
||||||
|
saved_addr.s_addr = 0;
|
||||||
|
|
||||||
while ( 1 ) {
|
while ( 1 ) {
|
||||||
try {
|
try {
|
||||||
int active_fds = poll( pollfds, 3, network.wait_time() );
|
int active_fds = poll( pollfds, 3, network.wait_time() );
|
||||||
@@ -271,6 +286,20 @@ void serve( int host_fd, Terminal::Complete &terminal, ServerConnection &network
|
|||||||
if ( swrite( host_fd, terminal_to_host.c_str(), terminal_to_host.length() ) < 0 ) {
|
if ( swrite( host_fd, terminal_to_host.c_str(), terminal_to_host.length() ) < 0 ) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* update utmp entry if we have become "connected" */
|
||||||
|
if ( (!connected_utmp)
|
||||||
|
|| ( saved_addr.s_addr != network.get_remote_ip().s_addr ) ) {
|
||||||
|
utempter_remove_added_record();
|
||||||
|
|
||||||
|
saved_addr = network.get_remote_ip();
|
||||||
|
|
||||||
|
char tmp[ 64 ];
|
||||||
|
snprintf( tmp, 64, "%s via mosh [%d]", inet_ntoa( saved_addr ), getpid() );
|
||||||
|
utempter_add_record( host_fd, tmp );
|
||||||
|
|
||||||
|
connected_utmp = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -350,6 +379,19 @@ void serve( int host_fd, Terminal::Complete &terminal, ServerConnection &network
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* update utmp if has been more than 10 seconds since heard from client */
|
||||||
|
if ( connected_utmp ) {
|
||||||
|
if ( network.get_latest_remote_state().timestamp < Network::timestamp() - 10000 ) {
|
||||||
|
utempter_remove_added_record();
|
||||||
|
|
||||||
|
char tmp[ 64 ];
|
||||||
|
snprintf( tmp, 64, "mosh [%d]", getpid() );
|
||||||
|
utempter_add_record( host_fd, tmp );
|
||||||
|
|
||||||
|
connected_utmp = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
network.tick();
|
network.tick();
|
||||||
} catch ( Network::NetworkException e ) {
|
} catch ( Network::NetworkException e ) {
|
||||||
fprintf( stderr, "%s: %s\n", e.function.c_str(), strerror( e.the_errno ) );
|
fprintf( stderr, "%s: %s\n", e.function.c_str(), strerror( e.the_errno ) );
|
||||||
|
|||||||
@@ -117,6 +117,8 @@ namespace Network {
|
|||||||
|
|
||||||
uint64_t timeout( void ) const;
|
uint64_t timeout( void ) const;
|
||||||
double get_SRTT( void ) const { return SRTT; }
|
double get_SRTT( void ) const { return SRTT; }
|
||||||
|
|
||||||
|
const struct in_addr & get_remote_ip( void ) const { return remote_addr.sin_addr; }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -101,6 +101,8 @@ namespace Network {
|
|||||||
uint64_t get_sent_state_late_acked( void ) const { return sent_state_late_acked; }
|
uint64_t get_sent_state_late_acked( void ) const { return sent_state_late_acked; }
|
||||||
|
|
||||||
unsigned int send_interval( void ) const { return sender.send_interval(); }
|
unsigned int send_interval( void ) const { return sender.send_interval(); }
|
||||||
|
|
||||||
|
const struct in_addr & get_remote_ip( void ) const { return connection.get_remote_ip(); }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user