From 76857624203ead1a923cdc7077e22c7cd3a459ae Mon Sep 17 00:00:00 2001 From: John Wood Date: Tue, 2 Jul 2024 10:24:23 +0900 Subject: [PATCH] Implement a -u flag in mosh-server to print detached mosh sessions then exit --- src/frontend/mosh-server.cc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/frontend/mosh-server.cc b/src/frontend/mosh-server.cc index 5d22553d6..011339e74 100644 --- a/src/frontend/mosh-server.cc +++ b/src/frontend/mosh-server.cc @@ -125,7 +125,7 @@ static void print_version( FILE* file ) static void print_usage( FILE* stream, const char* argv0 ) { fprintf( stream, - "Usage: %s new [-s] [-v] [-i LOCALADDR] [-p PORT[:PORT2]] [-c COLORS] [-l NAME=VALUE] [-- COMMAND...]\n", + "Usage: %s new [-s] [-u] [-v] [-i LOCALADDR] [-p PORT[:PORT2]] [-c COLORS] [-l NAME=VALUE] [-- COMMAND...]\n", argv0 ); } @@ -133,6 +133,7 @@ static bool print_motd( const char* filename ); static void chdir_homedir( void ); static bool motd_hushed( void ); static void warn_unattached( const std::string& ignore_entry ); +static char utmp_entry[64] = { 0 }; /* Simple spinloop */ static void spin( void ) @@ -203,6 +204,11 @@ int main( int argc, char* argv[] ) print_version( stdout ); exit( 0 ); } + if ( 0 == strcmp( argv[i], "-u" ) ) { + snprintf( utmp_entry, 64, "mosh [%ld]", static_cast( getpid() ) ); + warn_unattached( utmp_entry ); + exit( 0 ); + } if ( 0 == strcmp( argv[i], "--" ) ) { /* -- is mandatory */ if ( i != argc - 1 ) { command_argv = argv + i + 1; @@ -513,7 +519,6 @@ static int run_server( const char* desired_ip, } } - char utmp_entry[64] = { 0 }; snprintf( utmp_entry, 64, "mosh [%ld]", static_cast( getpid() ) ); /* Fork child process */