From b03d53d421dd47b74627204d011f491b837a7dbd Mon Sep 17 00:00:00 2001 From: Quentin Smith Date: Sat, 25 Feb 2012 16:24:48 -0500 Subject: [PATCH] Make libutempter optional --- configure.ac | 5 ++++- src/frontend/Makefile.am | 2 +- src/frontend/mosh-server.cc | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index f9195c8..92dc01b 100644 --- a/configure.ac +++ b/configure.ac @@ -41,7 +41,10 @@ AC_SUBST([WARNING_CXXFLAGS]) AC_SUBST([PICKY_CXXFLAGS]) # Checks for libraries. -AC_SEARCH_LIBS([utempter_remove_added_record], [utempter], , [AC_MSG_ERROR([Unable to find libutempter.])]) +AC_SEARCH_LIBS([utempter_remove_added_record], [utempter], + [AC_DEFINE([HAVE_UTEMPTER], [1], + [Define if libutempter is available.])], + [AC_MSG_WARN([Unable to find libutempter; utmp entries will not be made.])]) AC_SEARCH_LIBS([compress], [z], , [AC_MSG_ERROR([Unable to find zlib.])]) AX_BOOST_BASE(, , [AC_MSG_ERROR([Unable to find boost libraries.])]) diff --git a/src/frontend/Makefile.am b/src/frontend/Makefile.am index 313dc94..af7a013 100644 --- a/src/frontend/Makefile.am +++ b/src/frontend/Makefile.am @@ -1,6 +1,6 @@ AM_CPPFLAGS = -I$(srcdir)/../statesync -I$(srcdir)/../terminal -I$(srcdir)/../network -I$(srcdir)/../crypto -I$(builddir)/../protobufs -I$(srcdir)/../util AM_CXXFLAGS = $(WARNING_CXXFLAGS) $(PICKY_CXXFLAGS) -fno-default-inline -pipe -LDADD = ../crypto/libmoshcrypto.a ../network/libmoshnetwork.a ../statesync/libmoshstatesync.a ../terminal/libmoshterminal.a ../util/libmoshutil.a ../protobufs/libmoshprotos.a -lutil -lrt -lm -lutempter $(protobuf_LIBS) +LDADD = ../crypto/libmoshcrypto.a ../network/libmoshnetwork.a ../statesync/libmoshstatesync.a ../terminal/libmoshterminal.a ../util/libmoshutil.a ../protobufs/libmoshprotos.a -lutil -lrt -lm $(protobuf_LIBS) bin_PROGRAMS = mosh-client mosh-server diff --git a/src/frontend/mosh-server.cc b/src/frontend/mosh-server.cc index f355e8a..51d61b3 100644 --- a/src/frontend/mosh-server.cc +++ b/src/frontend/mosh-server.cc @@ -16,6 +16,8 @@ along with this program. If not, see . */ +#include "config.h" + #include #include #include @@ -31,7 +33,9 @@ #include #include #include +#ifdef HAVE_UTEMPTER #include +#endif #include #include #include @@ -182,10 +186,13 @@ int main( int argc, char *argv[] ) exit( 0 ); } else { /* parent */ + + #ifdef HAVE_UTEMPTER /* make utmp entry */ char tmp[ 64 ]; snprintf( tmp, 64, "mosh [%d]", getpid() ); utempter_add_record( master, tmp ); + #endif try { serve( master, terminal, network ); @@ -202,7 +209,9 @@ int main( int argc, char *argv[] ) exit( 1 ); } + #ifdef HAVE_UTEMPTER utempter_remove_added_record(); + #endif } printf( "\n[mosh-server is exiting.]\n" ); @@ -239,7 +248,10 @@ void serve( int host_fd, Terminal::Complete &terminal, ServerConnection &network uint64_t last_remote_num = network.get_remote_state_num(); + #ifdef HAVE_UTEMPTER bool connected_utmp = false; + #endif + struct in_addr saved_addr; saved_addr.s_addr = 0; @@ -305,6 +317,7 @@ void serve( int host_fd, Terminal::Complete &terminal, ServerConnection &network break; } + #ifdef HAVE_UTEMPTER /* update utmp entry if we have become "connected" */ if ( (!connected_utmp) || ( saved_addr.s_addr != network.get_remote_ip().s_addr ) ) { @@ -318,6 +331,7 @@ void serve( int host_fd, Terminal::Complete &terminal, ServerConnection &network connected_utmp = true; } + #endif } } @@ -397,6 +411,7 @@ void serve( int host_fd, Terminal::Complete &terminal, ServerConnection &network break; } + #ifdef HAVE_UTEMPTER /* update utmp if has been more than 10 seconds since heard from client */ if ( connected_utmp ) { if ( time_since_remote_state > 10000 ) { @@ -409,6 +424,7 @@ void serve( int host_fd, Terminal::Complete &terminal, ServerConnection &network connected_utmp = false; } } + #endif if ( terminal.set_echo_ack( now ) ) { /* update client with new echo ack */