39 #include <sys/types.h> 49 Info(
"Notify",
"Processing interrupt signal ...");
61 static const
char *
gScriptCmd = "\\\"%s %d localhost:%d/%s -d=%d\\\"";
63 static const char *
gSshCmd =
"ssh %s -f4 %s -R %d:localhost:%d sh -c \ 64 \"'(sh=\\`basename \'\\\\\\$SHELL\'\\`; \ 65 if test xbash = x\'\\\\\\$sh\' -o xsh = x\'\\\\\\$sh\' -o xzsh = x\'\\\\\\$sh\' -o xdash = x\'\\\\\\$sh\'; then \ 66 \'\\\\\\$SHELL\' -l -c %s; \ 67 elif test xcsh = x\'\\\\\\$sh\' -o xtcsh = x\'\\\\\\$sh\' -o xksh = x\'\\\\\\$sh\'; then \ 68 \'\\\\\\$SHELL\' -c %s; \ 70 echo \\\"Unknown shell \'\\\\\\$SHELL\'\\\"; \ 73 static const char *
gSshCmd =
"ssh %s -f4 %s -R %d:localhost:%d sh -c \ 74 \"'(sh=`basename $SHELL`; \ 75 if test xbash = x$sh -o xsh = x$sh -o xzsh = x$sh -o xdash = x$sh; then \ 77 elif test xcsh = x$sh -o xtcsh = x$sh -o xksh = x$sh; then \ 80 echo \"Unknown shell $SHELL\"; \ 102 TString user = (pw) ? (
const char*) pw->fUser :
"";
120 std::default_random_engine randomEngine(now);
124 port = randomPort(randomEngine);
130 Error(
"TApplicationRemote",
"unable to find a free port for connections");
142 if (script && *script) {
144 if (script[1] ==
'<') {
148 Error(
"TApplicationRemote",
"illegal script name <");
156 const char *verb =
"";
169 Info(
"TApplicationRemote",
"executing: %s", cmd.
Data());
171 Info(
"TApplicationRemote",
"an error occured during SSH connection");
185 Error(
"TApplicationRemote",
"failed to open connection");
199 Error(
"TApplicationRemote",
"failed to receive startup message");
208 Error(
"TApplicationRemote",
"failed to receive remote server protocol");
214 Info(
"TApplicationRemote",
"server runs a different protocol version: %d (vs %d)",
220 Error(
"TApplicationRemote",
"failed to receive server info - protocol error");
240 gROOT->GetListOfSockets()->Add(
this);
257 gROOT->GetListOfSockets()->Remove(
this);
270 Error(
"Broadcast",
"could not send message");
312 Error(
"Broadcast",
"could not send raw buffer");
350 if (s && s != (
TSocket *)(-1)) {
356 Info(
"Collect",
"deactivating %p", s);
370 if (s == (
TSocket *)(-1) && nto > 0)
418 Info(
"CollectInput",
"what %d", what);
445 gROOT->RefreshBrowsers();
458 Info(
"CollectInput",
"type %d", type);
470 "server requested an object that we do not have");
496 Info(
"CollectInput",
"kRTT_LogDone: status %d", st);
504 (*mess) >> msg >> lfeed;
506 fprintf(stderr,
"%s\n", msg.
Data());
508 fprintf(stderr,
"%s\r", msg.
Data());
522 Error(
"CollectInput",
"file %s not found in path(s) %s",
544 Info(
"CollectInput",
"no associated header file" 545 " found: tried: %s %s",
554 Info(
"CollectInput",
"problems sending file %s", impfile.
Data());
560 Info(
"CollectInput",
"problems sending file %s", headfile.
Data());
574 Warning(
"CollectInput",
"unknown type received from server: %d", type);
582 Error(
"CollectInput",
"unknown command received from server: %d", what);
603 const Int_t kMAXBUF = 16384;
607 Int_t fdout = fileno(stdout);
609 Warning(
"RecvLogFile",
"file descriptor for outputs undefined (%d):" 610 " will not log msgs", fdout);
613 lseek(fdout, (off_t) 0, SEEK_END);
618 while (filesize < size) {
619 left =
Int_t(size - filesize);
623 filesize = (rec > 0) ? (filesize + rec) : filesize;
631 w =
write(fdout, p, r);
634 SysError(
"RecvLogFile",
"error writing to unit: %d", fdout);
640 }
else if (rec < 0) {
641 Error(
"RecvLogFile",
"error during receiving log file");
653 if (!
IsValid() || !obj)
return -1;
689 if ((*md5) != fs->
fMD5) {
696 Error(
"CheckFile",
"could not calculate local MD5 check sum - dont send");
710 Error(
"CheckFile",
"could not calculate local MD5 check sum - dont send");
724 (*reply) >> type >> uptodate;
727 Warning(
"CheckFile",
"received wrong type:" 728 " %d (expected %d): protocol error?",
734 Error(
"CheckFile",
"received wrong message: %d (expected %d)",
738 Error(
"CheckFile",
"received empty message");
771 SysError(
"SendFile",
"cannot open file %s", file);
777 Long_t id, flags, modtime;
779 Error(
"SendFile",
"cannot stat file %s", file);
784 Error(
"SendFile",
"empty file %s", file);
793 const Int_t kMAXBUF = 32768;
802 size = sendto ? size : 0;
804 if (
gDebug > 1 && size > 0)
805 Info(
"SendFile",
"sending file %s", file);
807 snprintf(buf, kMAXBUF,
"%s %d %lld", fnam, bin, size);
816 lseek(fd, 0, SEEK_SET);
824 SysError(
"SendFile",
"error reading from file %s", file);
831 SysError(
"SendFile",
"error writing to server @ %s:%d (now offline)",
875 ::Info(
"TApplicationRemote::SetPortParam",
"port scan: %d attempts in [%d,%d]",
887 if (!line || !*line)
return 0;
889 if (!strncasecmp(line,
".q", 2)) {
895 if (!strncmp(line,
"?", 1)) {
923 if (opt && opt[0] ==
'F') {
943 Info(
"Interrupt",
"*** Ctrl-C not yet enabled *** (type= %d)", type);
947 char oobc = (char) type;
948 const int kBufSize = 1024;
949 char waste[kBufSize];
953 Error(
"Interrupt",
"error sending oobc to server");
959 int n, nch, nbytes = 0, nloop = 0;
980 if (nch > kBufSize) nch = kBufSize;
983 Error(
"Interrupt",
"error receiving waste from server");
987 }
else if (n == -3) {
993 Error(
"Interrupt",
"server does not respond");
997 Error(
"Interrupt",
"error receiving OOB from server");
1021 if (nch > kBufSize) nch = kBufSize;
1024 Error(
"Interrupt",
"error receiving waste (2) from server");
1030 Info(
"Interrupt",
"server synchronized: %d bytes discarded", nbytes);
1059 gROOT->RefreshBrowsers();
void Add(TObject *obj, const char *name=0, Int_t check=-1)
Add object with name to browser.
TClass * GetClass() const
virtual const char * BaseName(const char *pathname)
Base name of a file name. Base name of /user/root is root.
virtual const char * GetName() const
Returns name of object.
virtual void SysError(const char *method, const char *msgfmt,...) const
Issue system error message.
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
virtual void Add(TObject *obj)
double read(const std::string &file_name)
reading
virtual Long_t ProcessLine(const char *line, Bool_t sync=kFALSE, Int_t *error=0)
Process a single command line, either a C++ statement or an interpreter command starting with a "...
virtual void WriteString(const char *s)
Write string to I/O buffer.
virtual Bool_t IsValid() const
void Terminate(Int_t status=0)
Terminate this session.
const char * GetClassName() const
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
TApplicationRemote(const char *url, Int_t debug=0, const char *script=0)
Main constructor: start a remote session at 'url' accepting callbacks on local port 'port'; if port i...
Int_t GetActive(Long_t timeout=-1) const
Return number of sockets in the active list.
Bool_t Notify()
TApplicationRemote interrupt handler.
static TMD5 * FileChecksum(const char *file)
Returns checksum of specified file.
double write(int n, const std::string &file_name, const std::string &vector_type, int compress=0)
writing
TApplicationRemote * fApplicationRemote
virtual Int_t Send(const TMessage &mess)
Send a TMessage object.
TString & ReplaceAll(const TString &s1, const TString &s2)
int GetPathInfo(const char *path, Long_t *id, Long_t *size, Long_t *flags, Long_t *modtime)
Get info about a file: id, size, flags, modification time.
Bool_t TestBit(UInt_t f) const
virtual Int_t Recv(TMessage *&mess)
Receive a TMessage object.
virtual void Add()
Add signal handler to system signal handler list.
virtual ~TApplicationRemote()
Destructor.
virtual void Add(TSocket *sock, Int_t interest=kRead)
Add socket to the monitor's active list.
Int_t CollectInput()
Collect and analyze available input from the socket.
const Int_t kRRemote_Protocol
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
virtual Int_t SendObject(const TObject *obj, Int_t kind=kMESS_OBJECT)
Send an object.
const char * GetOptions() const
virtual char * Which(const char *search, const char *file, EAccessMode mode=kFileExists)
Find location of file in a search path.
Option_t * GetOption() const
Bool_t CheckFile(const char *file, Long_t modtime)
Check if a file needs to be send to the server.
Int_t Broadcast(const TMessage &mess)
Broadcast a message to the remote session.
R__EXTERN TApplication * gApplication
Int_t BroadcastObject(const TObject *obj, Int_t kind=kMESS_OBJECT)
Broadcast an object to the remote session.
virtual void DeActivateAll()
De-activate all activated sockets.
static Int_t fgPortAttempts
TObject * FindObject(const char *name) const
Find object using its name.
Long_t ProcessLine(const char *line, Bool_t=kFALSE, Int_t *error=0)
Parse a single command line and forward the request to the remote server where it will be processed...
TString & Insert(Ssiz_t pos, const char *s)
const char * GetHostFQDN() const
Return fully qualified domain name of url host.
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
static const char * GetMacroPath()
Get macro search path. Static utility function.
static Int_t GetErrno()
Static function returning system error number.
const char * GetFile() const
virtual TObject * ReadObject(const TClass *cl)
Read object from I/O buffer.
virtual Int_t SendRaw(const void *buffer, Int_t length, ESendRecvOptions opt=kDefault)
Send a raw buffer of specified length.
const char * GetHost() const
TSignalHandler * fIntHandler
virtual const char * ClassName() const
Returns name of class to which the object belongs.
The TRemoteObject class provides protocol for browsing ROOT objects from a remote ROOT session...
virtual void Sleep(UInt_t milliSec)
Sleep milliSec milli seconds.
THashList implements a hybrid collection class consisting of a hash table and a list to store TObject...
This code implements the MD5 message-digest algorithm.
virtual void DeActivate(TSocket *sock)
De-activate a socket.
virtual char * ReadString(char *s, Int_t max)
Read string from I/O buffer.
void Interrupt(Int_t type=kRRI_Hard)
Send interrupt OOB byte to server.
Int_t Collect(Long_t timeout=-1)
Collect responses from the remote server.
virtual UserGroup_t * GetUserInfo(Int_t uid)
Returns all user info in the UserGroup_t structure.
void RecvLogFile(Int_t size)
Receive the log file from the server.
virtual TSocket * Accept(UChar_t Opt=0)
Accept a connection on a server socket.
TSocket * Select()
Return pointer to socket for which an event is waiting.
const char * GetUser() const
void Reset()
Reset the message buffer so we can use (i.e. fill) it again.
Using a TBrowser one can browse all ROOT objects.
TSeqCollection * fRootFiles
virtual TTime Now()
Get current time in milliseconds since 0:00 Jan 1 1995.
static const char * gSshCmd
virtual TObject * First() const
Return the first object in the list. Returns 0 when list is empty.
static void NeedGraphicsLibs()
Static method.
R__EXTERN TSystem * gSystem
if object ctor succeeded but object should not be used
Int_t SendObject(const TObject *obj)
Send object to server.
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
char * Form(const char *fmt,...)
virtual Int_t Exec(const char *shellcmd)
Execute a command.
void SetName(const char *name)
virtual void Help(const char *line)
Print help on interpreter.
void InitializeGraphics()
Initialize the graphics environment.
void SetHost(const char *host)
TString & Remove(Ssiz_t pos)
virtual Int_t GetEffectiveUid()
Returns the effective user id.
virtual void Browse(TBrowser *b)
Browse remote application (working directory and ROOT files).
Ssiz_t Last(char c) const
Find last occurrence of a character c.
void Print(Option_t *option="") const
Print some info about this instance.
virtual void Remove()
Remove signal handler from system signal handler list.
static void SetPortParam(Int_t lower=-1, Int_t upper=-1, Int_t attempts=-1)
Set port parameters for tunnelling. A value of -1 means unchanged.
Mother of all ROOT objects.
TObject * fReceivedObject
virtual void Add(TObject *obj)
static const char * gScriptCmd
void WriteObject(const TObject *obj)
Write object to message buffer.
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
virtual TObject * FindObject(const char *name) const
Find an object in this collection using its name.
Int_t BroadcastRaw(const void *buffer, Int_t length)
Broadcast a raw buffer of specified length to the remote session.
static void ResetErrno()
Static function resetting system error number.
static const char * gScript
This class creates the ROOT Application Environment that interfaces to the windowing system eventloop...
virtual void ActivateAll()
Activate all de-activated sockets.
virtual Int_t RecvRaw(void *buffer, Int_t length, ESendRecvOptions opt=kDefault)
Receive a raw buffer of specified length bytes.
TRemoteObject * fWorkingDir
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Int_t SendFile(const char *file, Int_t opt=kAscii, const char *rfile=0)
Send a file to the server.
virtual const char * GetTitle() const
Returns title of object.
const char * Data() const