14#include <mx/sys/timeUtils.hpp>
16#include "../../libMagAOX/libMagAOX.hpp"
17#include "../../magaox_git_version.h"
33#define SSHDIGGER_E_NOTUNNELS (-10)
34#define SSHDIGGER_E_NOTUNNELFOUND (-11)
35#define SSHDIGGER_E_NOHOSTNAME (-12)
36#define SSHDIGGER_E_NOLOCALPORT (-13)
37#define SSHDIGGER_E_NOREMOTEPORT (-14)
265 _config.configUnused(rh, mx::app::iniFile::makeKey(
sections[
i],
"remoteHost" ) );
305 std::string
comp =
"";
319 std::vector<std::string>
argsV;
322 std::vector<std::string>
envps;
327 std::string
coml =
"Starting autossh with command: ";
358 const char **
args =
new const char*[
argsV.size() + 1];
363 const char **
envp =
new const char*[
envps.size() + 1];
369 std::cerr <<
"returned\n";
384 std::string
coml =
"autossh tunnel started with PID " + mx::ioutils::convertToString(
m_tunnelPID);
393 s->sshLogThreadExec();
403 catch(
const std::exception &
e )
455 if(
logs.back() ==
'\n')
461 if(
eol == std::string::npos)
break;
478 if(
logs.find(
"bind: Address already in use") != std::string::npos)
484 if(
logs.find(
"channel_setup_fwd_listener_tcpip: cannot listen to port:") != std::string::npos)
490 if(
logs.find(
"connect failed:") != std::string::npos)
509 s->autosshLogThreadExec();
520 catch(
const std::exception &
e )
589 if(
logs.back() ==
'\n')
595 if(
eol == std::string::npos)
break;
The base-class for MagAO-X applications.
std::string m_configName
The name of the configuration file (minus .conf).
stateCodes::stateCodeT state()
Get the current state code.
int m_shutdown
Flag to signal it's time to shutdown. When not 0, the main loop exits.
static int log(const typename logT::messageT &msg, logPrioT level=logPrio::LOG_DEFAULT)
Make a log entry.
pid_t m_pid
This process's PID.
std::string m_configBase
The name of a base config class for this app (minus .conf).
The MagAO-X SSH tunnel manager.
~sshDigger() noexcept
D'tor, declared and defined for noexcept.
std::thread m_sshLogThread
A separate thread for capturing ssh logs.
int m_autosshLogThreadPrio
Priority of the autossh log capture thread, should normally be 0.
int sshLogThreadStart()
Start the log capture.
virtual int appLogic()
Implementation of the FSM for sshDigger.
int m_sshSTDERR_input
The input end of stderr, used to wake up the log thread on shutdown.
int execTunnel()
Creates the tunnel in a child process using exec.
std::string m_remoteHost
The name of the remote host.
static void _sshLogThreadStart(sshDigger *s)
Thread starter, called by sshLogThreadStart on thread construction. Calls sshLogThreadExec.
int m_localPort
The local port to forward from.
int m_tunnelPID
The PID of the autossh process.
void autosshLogThreadExec()
Execute the log capture.
int processSSHLog(const std::string &logs)
Process a log entry from indiserver, putting it into MagAO-X standard form.
static void _autosshLogThreadStart(sshDigger *s)
Thread starter, called by sshLogThreadStart on thread construction. Calls sshLogThreadExec.
int loadConfigImpl(mx::app::appConfigurator &_config)
Implementation of loadConfig logic, separated for testing.
int m_autosshLogFD
File descriptor of the autossh logfile.
int m_sshLogThreadPrio
Priority of the ssh log capture thread, should normally be 0.
std::string m_lastSSHLogs
int m_remotePort
The remote port to forward to.
int m_sshSTDERR
The output of stderr of the ssh process.
int m_monitorPort
The monitor port.
void sshLogThreadExec()
Execute the log capture.
int autosshLogThreadStart()
Start the log capture.
virtual int appShutdown()
Shutdown the app.
virtual int appStartup()
Startup function.
sshDigger()
Default c'tor.
virtual void setupConfig()
int processAutoSSHLog(const std::string &logs)
Process a log entry from indiserver, putting it into MagAO-X standard form.
int m_sshError
Flag to signal when ssh logs an error, and should be restarted via SIGUSR1 to autossh.
void genEnvp(std::vector< std::string > &envp)
Generate the envp vector for the exec of autossh.
std::string tunnelSpec()
Create the tunnel specification string, [localPort]:localhost:[remotePort].
void genArgsV(std::vector< std::string > &argsV)
Generate the argv vector for the exec of autossh.
std::string m_autosshLogFile
Name of the autossh logfile.
virtual void loadConfig()
std::thread m_autosshLogThread
A separate thread for capturing autossh logs.
bool m_compress
Control compression on this tunnel. True is on, false is off.
int8_t logPrioT
The type of the log priority code.
@ CONNECTED
The application has connected to the device or service.
@ NOTCONNECTED
The application is not connected to the device or service.
static constexpr logPrioT LOG_INFO
Informational. The info log level is the lowest level recorded during normal operations.
static constexpr logPrioT LOG_CRITICAL
The process can not continue and will shut down (fatal)
static constexpr logPrioT LOG_WARNING
A condition has occurred which may become an error, but the process continues.
static constexpr logPrioT LOG_ERROR
An error has occured which the software will attempt to correct.
#define SSHDIGGER_E_NOLOCALPORT
#define SSHDIGGER_E_NOTUNNELFOUND
#define SSHDIGGER_E_NOREMOTEPORT
#define SSHDIGGER_E_NOHOSTNAME
#define SSHDIGGER_E_NOTUNNELS
void log(const typename logT::messageT &msg, logPrioT level=logPrio::LOG_DEFAULT)
Make a log entry, including a message.
int logLevel(logPrioT newLev)
Set a new value of logLevel.
A simple text log, a string-type log.