14QHyodaSsh::QHyodaSsh(QString interactive,
18 bool _singleShot): client_name(QProcessEnvironment::systemEnvironment().value(
"HOSTNAME")),
19 inter_name(interactive),
20 inter_adrs(QString()),
22 tunnelProcess(new QProcess()),
23 ceaHostProcess(new QProcess()),
24 via_interactive_hop(false),
27 singleShot(_singleShot){
28 qDebug() <<
"[QHyodaSsh] NEW";
29 qDebug() <<
"[QHyodaSsh] interactive:"<<interactive;
30 qDebug() <<
"[QHyodaSsh] rankZero:"<<rankZero;
32 via_interactive_hop=( inter_name.startsWith(
"germain", Qt::CaseInsensitive)
33 || inter_name.startsWith(
"cartan", Qt::CaseInsensitive)
34 || inter_name.startsWith(
"lascaux", Qt::CaseInsensitive)) ?
true : false;
37 if (singleShot) via_interactive_hop=
false;
40 ceaHostProcess->setProcessChannelMode(QProcess::MergedChannels);
41 connect(ceaHostProcess, SIGNAL(readyReadStandardOutput()),
this, SLOT(ceaHostReadyReadStandardOutput()));
43 ceaHostProcess->start(QString(
"/usr/local/sr/bin/cea_gethost"), QStringList()<<interactive);
45 ceaHostProcess->start(QString(
"/usr/bin/host"), QStringList()<<inter_name);
47 if (!ceaHostProcess->waitForStarted())
48 qFatal(
"QHyodaSsh::run threadProcess NOT started!");
55QHyodaSsh::~QHyodaSsh(){
56 qDebug() <<
"~QHyodaSsh";
57 tunnelProcess->close();
58 ceaHostProcess->close();
59 if (tunnelProcess->state()!=QProcess::NotRunning)
60 qFatal(
"QHyodaSsh tunnelProcess NOT closed!");
69 if (isRunning())
return;
71 ceaHostProcess->close();
74 if (!via_interactive_hop){
76 tcpAdrs=inetAton(inter_adrs.toLatin1().data());
77 qDebug()<<
"\33[1m[QHyodaSsh::run] tcpAdrs="<<tcpAdrs<<
"\33[m";
79 if (!singleShot)
return;
84 QString command(
"ssh");
85 QStringList args = QStringList() <<
"-xCTR"
86 << QString(
"%1:%2:%1").arg(QString().setNum(tcpPort),inter_adrs)
87 << rank_zero.toLower()
91 tunnelProcess->setProcessChannelMode(QProcess::MergedChannels);
92 connect(tunnelProcess, SIGNAL(readyReadStandardOutput()),
this, SLOT(tunnelReadyReadStandardOutput()));
93 qDebug()<<
"\33[1m[QHyodaSsh::run] singleShot tunnelProcess command="<<command<<
", args="<<args<<
"\33[m";
94 tunnelProcess->start(command, args);
95 if (!tunnelProcess->waitForStarted())
96 qFatal(
"QHyodaSsh::run tunnelProcess NOT started!");
101 QString command(
"ssh");
102 QStringList args = QStringList() <<
"-xCTR"
103 << QString(
"%1:%2:%1").arg(QString().setNum(tcpPort),client_name)
107 << QString(
"%1:%2:%1").arg(QString().setNum(tcpPort),inter_adrs)
108 << rank_zero.toLower()
110 qDebug() <<
"\33[7m" << command << args <<
"\33[m";
112 tunnelProcess->setProcessChannelMode(QProcess::MergedChannels);
113 connect(tunnelProcess, SIGNAL(readyReadStandardOutput()),
this, SLOT(tunnelReadyReadStandardOutput()));
114 tunnelProcess->start(command, args);
115 if (!tunnelProcess->waitForStarted())
116 qFatal(
"QHyodaSsh::run tunnelProcess NOT started!");
124void QHyodaSsh::tunnelReadyReadStandardOutput(
void){
125 const QStringList read_lines=QString(tunnelProcess->readAllStandardOutput()).split(QRegExp(
"\n"));
126 for(
int i=0,mx=read_lines.size();i<mx;++i){
127 const QString line=read_lines.at(i).trimmed();
128 if (line.isEmpty())
continue;
129 qDebug()<<
"\t\t"<<
"\33[1m"<<line<<
"\33[m";
137void QHyodaSsh::ceaHostReadyReadStandardOutput(
void){
138 const QStringList read_lines=QString(ceaHostProcess->readAllStandardOutput()).split(QRegExp(
"\n"));
139 qDebug()<<read_lines;
140 for(
int i=0,mx=read_lines.size();i<mx;++i){
141 const QString line=read_lines.at(i).trimmed();
142 if (line.isEmpty())
continue;
143 qDebug()<<
"\t\t"<<
"\33[1m"<<line<<
"\33[m";
144 QStringList tokens = line.split(QRegExp(
"\\s"));
146 inter_adrs=tokens[3];
148 inter_adrs=tokens[0];
149 qDebug()<<
"[\33[1mQHyodaSsh::ceaHostReadyReadStandardOutput] inter_adrs="<<inter_adrs<<
"\33[m";
151 if (!isRunning()) run();
166quint32 QHyodaSsh::inetAton(
const char *cp){
178 if (*++cp ==
'x' || *cp ==
'X')
183 while ((c = *cp) !=
'\0') {
184 if (isascii(c) && isdigit(c)){
185 val = (val * base) + (c -
'0');
189 if (base == 16 && isascii(c) && isxdigit(c)){
191 (c + 10 - (islower(c) ?
'a' :
'A'));
199 if (pp >= parts + 3 || val > 0xff)
208 if (*cp && (!isascii(*cp) || !isspace(*cp)))
219 val |= parts[0] << 24;
224 val |= (parts[0] << 24) | (parts[1] << 16);
229 val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);