21#include "RConfigure.h"
37#if (defined(__FreeBSD__) && (__FreeBSD__ < 4)) || \
38 (defined(__APPLE__) && (!defined(MAC_OS_X_VERSION_10_3) || \
39 (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3)))
41#define lockf(fd, op, sz) flock((fd), (op))
43#define F_LOCK (LOCK_EX | LOCK_NB)
46#define F_ULOCK LOCK_UN
65#include "compiledata.h"
85 fServ->HandleUrgentData();
108 fServ->HandleSigPipe();
129 fServ->HandleSocketInput();
152 Error(
"TASLogHandler",
"executing command in pipe");
155 Error(
"TASLogHandler",
156 "undefined command (%p) or socket (%p)", (
int *)cmd, s);
173 Error(
"TASLogHandler",
"undefined file (%p) or socket (%p)",
f, s);
198 if ((plf = strchr(
line,
'\n')))
203 if (
fPfx.Length() > 0) {
206 }
else if (
fgPfx.Length() > 0) {
230 const char *pfx,
Bool_t on)
238 Error(
"TASLogHandlerGuard",
"invalid handler");
242 Error(
"TASLogHandlerGuard",
"undefined command");
250 const char *pfx,
Bool_t on)
258 Error(
"TASLogHandlerGuard",
"invalid handler");
262 Error(
"TASLogHandlerGuard",
"undefined file");
283 FILE *flog,
const char *logfile)
320 Error(
"TApplicationServer",
"failed to setup - quitting");
331 logon =
gEnv->GetValue(
"Rint.Load", (
char *)0);
368 snprintf(str, 512,
"**** Remote session @ %s started ****",
gSystem->HostName());
369 if (
fSocket->Send(str) != 1+
static_cast<Int_t>(strlen(str))) {
370 Error(
"Setup",
"failed to send startup message");
376 Error(
"Setup",
"failed to send local protocol");
387 if (strlen(
fUrl.GetFile()) > 0) {
396 SysError(
"Setup",
"can not change to directory %s",
404 SysError(
"Setup",
"can not change to directory %s",
414 SysWarning(
"Setup",
"failed to enable SIGURG generation on incoming OOB");
451 Fatal(
"GetOptions",
"must be started with 4 arguments");
459 fUrl.SetUrl(argv[2]);
480 Error(
"Run",
"invalid instance: cannot Run()");
494 if (
fSocket->Recv(mess) <= 0) {
497 Error(
"HandleSocketInput",
"retrieving message from input socket");
504 Info(
"HandleSocketInput",
"got message of type %d",
what);
512 Info(
"HandleSocketInput:kMESS_CINT",
"processing: %s...", str);
545 {
char name[2048], i1[20], i2[40];
546 sscanf(str,
"%2047s %19s %39s",
name, i1, i2);
547 Int_t bin = atoi(i1);
567 Warning(
"HandleSocketInput",
"message type unknown (%d)",
what);
583 const Int_t kBufSize = 1024;
584 char waste[kBufSize];
589 Info(
"HandleUrgentData",
"handling oob...");
592 while ((
n =
fSocket->RecvRaw(&oob_byte, 1,
kOob)) < 0) {
610 if (nch > kBufSize) nch = kBufSize;
613 Error(
"HandleUrgentData",
"error receiving waste");
618 Error(
"HandleUrgentData",
"error receiving OOB (n = %d)",
n);
623 Info(
"HandleUrgentData",
"got OOB byte: %d\n", oob_byte);
628 Info(
"HandleUrgentData",
"*** Hard Interrupt");
641 Error(
"HandleUrgentData",
"error sending OOB");
652 if (nch > kBufSize) nch = kBufSize;
655 Error(
"HandleUrgentData",
"error receiving waste (2)");
665 Info(
"HandleUrgentData",
"Soft Interrupt");
668 Error(
"HandleUrgentData",
"soft interrupt flushed stream");
679 Info(
"HandleUrgentData",
"Shutdown Interrupt");
686 Error(
"HandleUrgentData",
"unexpected OOB byte");
700 Info(
"HandleSigPipe",
"client died");
730 if (
size <= 0)
return 0;
733 Int_t fd = open(file, O_CREAT | O_TRUNC | O_WRONLY, 0600);
735 SysError(
"ReceiveFile",
"error opening file %s", file);
739 const Int_t kMAXBUF = 16384;
745 while (filesize <
size) {
759 for (
Int_t i = 0; i <
r; ++i) {
770 SysError(
"ReceiveFile",
"error writing to file %s", file);
778 Error(
"ReceiveFile",
"error during receiving file %s", file);
801 off_t ltot=0, lnow=0;
806 ltot = lseek(fileno(stdout), (off_t) 0, SEEK_END);
809 SysError(
"SendLogFile",
"lseek failed");
815 if (end <= start || end > ltot)
822 left = (
Int_t)(ltot - lnow);
833 const Int_t kMAXBUF = 32768;
835 Int_t wanted = (left > kMAXBUF) ? kMAXBUF : left;
838 while ((len = read(
fLogFileDes, buf, wanted)) < 0 &&
843 SysError(
"SendLogFile",
"error reading log file");
847 if (end == ltot && len == wanted)
850 if (
fSocket->SendRaw(buf, len) < 0) {
851 SysError(
"SendLogFile",
"error sending log file");
857 wanted = (left > kMAXBUF) ? kMAXBUF : left;
859 }
while (len > 0 && left > 0);
883 while ((o = next())) {
898 Info(
"SendCanvases",
"new canvas found: %p", o);
951 if (!fname || !*fname) {
956 while ((fh = (
TNamed *)next())) {
960 if (list->GetEntries() > 0) {
973 TList *keylist = (
TList *)
gROOT->ProcessLine(
Form(
"((TFile *)0x%zx)->GetListOfKeys();", (
size_t)fh));
974 TIter nextk(keylist);
977 while ((key = (
TNamed *)nextk())) {
979 const char *classname = (
const char *)
gROOT->ProcessLine(
Form(
"((TKey *)0x%zx)->GetClassName();", (
size_t)key));
986 if (list->GetEntries() > 0) {
1039 while ((fh = next())) {
1042 gSystem->RemoveFileHandler(ih);
1059 (*mess) >> filenam >> md5;
1063 if (md5local && md5 == (*md5local)) {
1068 Info(
"HandleCheckFile",
"up-to-date version of %s available", filenam.
Data());
1073 Info(
"HandleCheckFile",
"file %s needs to be uploaded", filenam.
Data());
1088 TString slevel =
gEnv->GetValue(
"Root.ErrorIgnoreLevel",
"Print");
1111 if (syslogService.
IsNull()) {
1112 syslogService =
"server";
1116 const char *type = 0;
1123 if (level >=
kInfo) {
1137 type =
"*** Break ***";
1151 if (!location || !location[0] ||
1154 fprintf(stderr,
"%s on %s: %s\n", type, node.
Data(), msg);
1155 buf.
Form(
"%s:%s:%s", node.
Data(), type, msg);
1157 fprintf(stderr,
"%s in <%s> on %s: %s\n", type, location, node.
Data(), msg);
1158 buf.
Form(
"%s:%s:<%s>:%s", node.
Data(), type, location, msg);
1162 gSystem->Syslog(loglevel, buf);
1165 fprintf(stderr,
"aborting\n");
1184 if (!strncmp(
line,
".L", 2) || !strncmp(
line,
".U", 2) ||
1185 !strncmp(
line,
".X", 2) || !strncmp(
line,
".x", 2)) {
1196 Error(
"ProcessLine",
"no write permission in %s",
gSystem->WorkingDirectory());
1201 Info(
"ProcessLine",
"macro %s not found in path %s: asking the client",
1211 while (filefollows) {
1216 Error(
"ProcessLine",
"ask-file: received empty message from client");
1220 Error(
"ProcessLine",
"ask-file: wrong message received (what: %d)", rm->
What());
1225 Error(
"ProcessLine",
"ask-file: wrong sub-type received (type: %d)", type);
1228 (*rm) >> filefollows;
1232 Error(
"ProcessLine",
"file: received empty message from client");
1236 Error(
"ProcessLine",
"file: wrong message received (what: %d)", rm->
What());
1241 Error(
"ProcessLine",
"file: wrong sub-type received (type: %d)", type);
1247 char name[2048], i1[20], i2[40];
1248 sscanf(str,
"%2047s %19s %39s",
name, i1, i2);
1249 Int_t bin = atoi(i1);
1284 s =
gSystem->PrependPathName(
gSystem->HomeDirectory(), temp_name);
1289 if (strcmp(
gSystem->HomeDirectory(),
gSystem->WorkingDirectory())) {
1295 const char *logon =
gEnv->GetValue(
"Rint.Logon", (
char*)0);
const Int_t kRRemote_Protocol
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
int Int_t
Signed integer 4 bytes (int).
long Longptr_t
Integer large enough to hold a pointer (platform-dependent).
long Long_t
Signed long integer 4 bytes (long). Size depends on architecture.
bool Bool_t
Boolean (0=false, 1=true) (bool).
long long Long64_t
Portable signed long integer 8 bytes.
externTBenchmark * gBenchmark
Error("WriteTObject","The current directory (%s) is not associated with a file. The object (%s) has not been written.", GetName(), objname)
externInt_t gErrorAbortLevel
non-ignored errors with level equal or above this value will call abort(). Default is kSysError+1.
constexpr Int_t kSysError
externInt_t gErrorIgnoreLevel
errors with level below this value will be ignored. Default is kUnset.
ErrorHandlerFunc_t SetErrorHandler(ErrorHandlerFunc_t newhandler)
Set an errorhandler function. Returns the old handler.
R__EXTERN void Throw(int code)
If an exception context has been set (using the TRY and RETRY macros) jump back to where it was set.
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
TApplicationServer * fServ
Bool_t Notify() override
Handle this interrupt.
TASInterruptHandler(TApplicationServer *s)
TASLogHandlerGuard(const char *cmd, TSocket *s, const char *pfx="", Bool_t on=kTRUE)
Init a guard for executing a command in a pipe.
virtual ~TASLogHandlerGuard()
Close a guard for executing a command in a pipe.
TASLogHandler * fExecHandler
virtual ~TASLogHandler()
Handle available message in the open file.
Bool_t Notify() override
Handle available message in the open file.
TASLogHandler(const char *cmd, TSocket *s, const char *pfx="")
Execute 'cmd' in a pipe and handle output messages from the related file.
static void SetDefaultPrefix(const char *pfx)
Static method to set the default prefix.
Bool_t Notify() override
Handle this signal.
TApplicationServer * fServ
TASSigPipeHandler(TApplicationServer *s)
void Run(Bool_t retrn=kFALSE) override
Main server eventloop.
void ExecLogon()
Execute logon macro's.
Int_t SendCanvases()
Send any created canvas to client.
Longptr_t ProcessLine(const char *line, Bool_t=kFALSE, Int_t *err=nullptr) override
Parse a command line received from the client, making sure that the files needed for the execution,...
TApplicationServer(Int_t *argc, char **argv, FILE *flog, const char *logfile)
Main constructor.
void HandleUrgentData()
Handle Out-Of-Band data sent by the master or client.
void HandleSocketInput()
Handle input coming from the client or from the master server.
Int_t ReceiveFile(const char *file, Bool_t bin, Long64_t size)
Receive a file, either sent by a client or a master server.
const char * GetHost() const
void Reset(const char *dir)
Reset environment to be ready for execution of next command.
void GetOptions(Int_t *argc, char **argv) override
Get and handle command line options.
void HandleSigPipe()
Called when the client is not alive anymore (i.e.
TRemoteObject * fWorkingDir
static void ErrorHandler(Int_t level, Bool_t abort, const char *location, const char *msg)
The error handler function.
Int_t BrowseKey(const char *keyname)
Read key object and send it back to client.
Int_t Setup()
Print the Remote Server logo on standard output.
Int_t BrowseDirectory(const char *dirname)
Browse directory and send back its content to client.
void HandleCheckFile(TMessage *mess)
Handle file checking request.
virtual ~TApplicationServer()
Cleanup.
void Terminate(Int_t status) override
Terminate the server.
Int_t BrowseFile(const char *fname)
Browse root file and send back its content; if fname is null, send the full list of files.
void SendLogFile(Int_t status=0, Int_t start=-1, Int_t end=-1)
Send log file to master.
virtual Longptr_t ProcessLine(const char *line, Bool_t sync=kFALSE, Int_t *error=nullptr)
Process a single command line, either a C++ statement or an interpreter command starting with a "....
TApplication(const TApplication &)=delete
virtual void Run(Bool_t retrn=kFALSE)
Main application eventloop. Calls system dependent eventloop via gSystem.
virtual Longptr_t ProcessFile(const char *file, Int_t *error=nullptr, Bool_t keep=kFALSE)
Process a file containing a C++ macro.
This class is a ROOT utility to help benchmarking applications.
TObject * ReadObject(const TClass *cl) override
Read object from I/O buffer.
char * ReadString(char *s, Int_t max) override
Read string from I/O buffer.
void WriteObject(const TObject *obj, Bool_t cacheReuse=kTRUE) override
Write object to I/O buffer.
Describe directory structure in memory.
virtual Bool_t cd()
Change current directory to "this" directory.
This code implements the MD5 message-digest algorithm.
static TMD5 * FileChecksum(const char *file)
Returns checksum of specified file.
void Reset() override
Reset the message buffer so we can use (i.e. fill) it again.
TClass * GetClass() const
The TNamed class is the base class for all named ROOT classes.
const char * GetName() const override
Returns name of object.
const char * GetTitle() const override
Returns title of object.
Wrapper around a TObject so it can be stored in a TList.
TObject * GetObject() const
Bool_t TestBit(UInt_t f) const
virtual void SysError(const char *method, const char *msgfmt,...) const
Issue system error message.
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
TObject()
TObject constructor.
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
static const char * GetMacroPath()
Get macro search path. Static utility function.
static Bool_t Initialized()
Return kTRUE if the TROOT object has been initialized.
static const TString & GetEtcDir()
Get the sysconfig directory in the installation. Static utility function.
The TRemoteObject class provides protocol for browsing ROOT objects from a remote ROOT session.
void SetKeyClassName(const char *name)
void Browse(TBrowser *b) override
Browse remote object.
void SetRemoteAddress(Longptr_t addr)
void SetFolder(Bool_t isFolder)
ESignals GetSignal() const
This class implements client sockets.
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
Int_t Atoi() const
Return integer value of string.
const char * Data() const
TString & ReplaceAll(const TString &s1, const TString &s2)
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
static void ResetErrno()
Static function resetting system error number.
static Int_t GetErrno()
Static function returning system error number.
bool HasBeenDeleted(const TObject *obj)
Check if the TObject's memory has been deleted.