start sea server even remotely over ssh
this works on neutron instruments (account equal host) and on linse-c
This commit is contained in:
12
main.cpp
12
main.cpp
@ -15,6 +15,7 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include "instr_hosts.h"
|
#include "instr_hosts.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
QPoint firstPos;
|
QPoint firstPos;
|
||||||
|
|
||||||
@ -27,17 +28,6 @@ const char *instr;
|
|||||||
//char prefinstr[64]="";
|
//char prefinstr[64]="";
|
||||||
char frominstr[128];
|
char frominstr[128];
|
||||||
|
|
||||||
char *strtoupper(const char *str) {
|
|
||||||
static char buf[128];
|
|
||||||
int i;
|
|
||||||
for (i = 0; i < 127; i++) {
|
|
||||||
if (str[i] == 0) break;
|
|
||||||
buf[i] = toupper(str[i]);
|
|
||||||
}
|
|
||||||
buf[i] = 0;
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *fullinstr(const char *host, const char *instr) {
|
const char *fullinstr(const char *host, const char *instr) {
|
||||||
static char buf[128];
|
static char buf[128];
|
||||||
if (strncasecmp(host, instr, strlen(instr)) == 0) {
|
if (strncasecmp(host, instr, strlen(instr)) == 0) {
|
||||||
|
29
seaset.cpp
29
seaset.cpp
@ -19,6 +19,7 @@
|
|||||||
#include <qevent.h>
|
#include <qevent.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include "instr_hosts.h"
|
#include "instr_hosts.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
@ -646,13 +647,13 @@ SeaSet::SeaSet(QSplitter *parent, long range, const char *name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SeaSet::setHost(const QString &hostport) {
|
void SeaSet::setHost(const QString &hostport) {
|
||||||
/*
|
static char cmd[128], psw[32];
|
||||||
static char seaStart[64];
|
static char *user;
|
||||||
char host[128], instr[32];
|
char host[128], instr[32];
|
||||||
char *hp = (char *)hostport.latin1();
|
char *hp = (char *)hostport.latin1();
|
||||||
char *p;
|
char *p;
|
||||||
int port;
|
int port;
|
||||||
*/
|
|
||||||
|
|
||||||
this->hostport = hostport;
|
this->hostport = hostport;
|
||||||
sc->setHost(hostport.latin1(), "sea");
|
sc->setHost(hostport.latin1(), "sea");
|
||||||
@ -660,18 +661,30 @@ void SeaSet::setHost(const QString &hostport) {
|
|||||||
gc->setHost(hostport.latin1(), "graph");
|
gc->setHost(hostport.latin1(), "graph");
|
||||||
ec->setHost(hostport.latin1(), "graph");
|
ec->setHost(hostport.latin1(), "graph");
|
||||||
|
|
||||||
/*
|
|
||||||
p = strchr(hp, ':');
|
p = strchr(hp, ':');
|
||||||
if (p == NULL) {
|
if (p == NULL) {
|
||||||
InstrHost("sea", hp, instr, sizeof instr, host, sizeof host, &port);
|
InstrHost("sea", hp, instr, sizeof instr, host, sizeof host, &port);
|
||||||
if (strcmp(host, instr) == 0) {
|
if (strcmp(host, instr) == 0) {
|
||||||
snprintf(seaStart, sizeof seaStart, "ssh %s@%s sea start", instr, host);
|
snprintf(psw, sizeof psw, "SSHPASS=%sLNS", strtoupper(instr));
|
||||||
|
user = instr;
|
||||||
|
} else if (strcmp(host, "linse-c") == 0) {
|
||||||
|
snprintf(psw, sizeof psw, "SSHPASS=1%dlns1", 7);
|
||||||
|
user = "l_samenv";
|
||||||
} else {
|
} else {
|
||||||
snprintf(seaStart, sizeof seaStart, "ssh l_samenv@%s sea start %s", host, instr);
|
return;
|
||||||
|
}
|
||||||
|
putenv(psw);
|
||||||
|
snprintf(cmd, sizeof cmd, "sshpass -e ssh -Y %s@%s sea start %s",
|
||||||
|
user, host, instr);
|
||||||
|
sc->startServer = cmd;
|
||||||
|
for (int i=0; i<30; i++) {
|
||||||
|
sc->handleBuffer(1);
|
||||||
|
if (sc->connect_state == SicsConnection::connect_waitlogin) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
usleep(250000);
|
||||||
}
|
}
|
||||||
sc->startServer = seaStart;
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SeaSet::setLive(bool on) {
|
void SeaSet::setLive(bool on) {
|
||||||
|
13
sicsconn.cpp
13
sicsconn.cpp
@ -173,6 +173,7 @@ SicsConnection::SicsConnection(QObject *parent) : QObject(parent) {
|
|||||||
bufline = "";
|
bufline = "";
|
||||||
bufstate = buf_got_line;
|
bufstate = buf_got_line;
|
||||||
connect_state = connect_start;
|
connect_state = connect_start;
|
||||||
|
tries_wait_start = 0;
|
||||||
command2send = "";
|
command2send = "";
|
||||||
tmo = 0;
|
tmo = 0;
|
||||||
if (!sigpipe_ignored) {
|
if (!sigpipe_ignored) {
|
||||||
@ -246,8 +247,9 @@ int SicsConnection::handleBuffer(int tmo) {
|
|||||||
iret = SicsConnectSuccess(fd);
|
iret = SicsConnectSuccess(fd);
|
||||||
if (iret <= 0) {
|
if (iret <= 0) {
|
||||||
if (startServer) {
|
if (startServer) {
|
||||||
iret = system(startServer);
|
int isys = system(startServer);
|
||||||
if (iret) {
|
tries_wait_start = 3;
|
||||||
|
if (isys) {
|
||||||
printf("can not connect to sea and failed to start the sea server\n");
|
printf("can not connect to sea and failed to start the sea server\n");
|
||||||
printf("\n");
|
printf("\n");
|
||||||
pos = strcspn(hostport, ":");
|
pos = strcspn(hostport, ":");
|
||||||
@ -255,10 +257,13 @@ int SicsConnection::handleBuffer(int tmo) {
|
|||||||
printf("\n");
|
printf("\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
iret = 1;
|
|
||||||
}
|
}
|
||||||
startServer = NULL;
|
startServer = NULL;
|
||||||
|
if (iret == 0) return iret; /* connection pending */
|
||||||
|
if (tries_wait_start > 0) {
|
||||||
|
tries_wait_start--;
|
||||||
|
connect_state = connect_start;
|
||||||
|
}
|
||||||
return iret;
|
return iret;
|
||||||
}
|
}
|
||||||
connect_state = connect_login;
|
connect_state = connect_login;
|
||||||
|
@ -41,6 +41,7 @@ public:
|
|||||||
char *debug;
|
char *debug;
|
||||||
ConnState state;
|
ConnState state;
|
||||||
char *startServer = NULL;
|
char *startServer = NULL;
|
||||||
|
enum {connect_done, connect_start, connect_wait, connect_login, connect_waitlogin, connect_error} connect_state;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void handle(const char *line, bool *done = NULL);
|
void handle(const char *line, bool *done = NULL);
|
||||||
@ -60,7 +61,7 @@ private:
|
|||||||
char *server;
|
char *server;
|
||||||
int tmo;
|
int tmo;
|
||||||
enum {buf_got_line, buf_got_finished, buf_sent_line, buf_got_start, buf_sent_transact} bufstate;
|
enum {buf_got_line, buf_got_finished, buf_sent_line, buf_got_start, buf_sent_transact} bufstate;
|
||||||
enum {connect_done, connect_start, connect_wait, connect_login, connect_waitlogin, connect_error} connect_state;
|
int tries_wait_start;
|
||||||
QString command2send;
|
QString command2send;
|
||||||
QString bufline;
|
QString bufline;
|
||||||
QString rdbuffer;
|
QString rdbuffer;
|
||||||
|
11
utils.cpp
11
utils.cpp
@ -460,3 +460,14 @@ void MyTextEdit::appendText(QString text) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *strtoupper(const char *str) {
|
||||||
|
static char buf[128];
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < 127; i++) {
|
||||||
|
if (str[i] == 0) break;
|
||||||
|
buf[i] = toupper(str[i]);
|
||||||
|
}
|
||||||
|
buf[i] = 0;
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user