21#include "RConfigure.h"
36#if (defined(__FreeBSD__) && (__FreeBSD__ < 4)) || \
37 (defined(__APPLE__) && (!defined(MAC_OS_X_VERSION_10_3) || \
38 (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3)))
40#define lockf(fd, op, sz) flock((fd), (op))
42#define F_LOCK (LOCK_EX | LOCK_NB)
45#define F_ULOCK LOCK_UN
65#include "compiledata.h"
83Bool_t TASInterruptHandler::Notify()
85 fServ->HandleUrgentData();
106Bool_t TASSigPipeHandler::Notify()
108 fServ->HandleSigPipe();
127Bool_t TASInputHandler::Notify()
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')))
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");
284 FILE *flog,
const char *logfile)
321 Error(
"TApplicationServer",
"failed to setup - quitting");
371 Error(
"Setup",
"failed to send startup message");
377 Error(
"Setup",
"failed to send local protocol");
399 SysError(
"Setup",
"can not change to directory %s",
407 SysError(
"Setup",
"can not change to directory %s",
417 SysWarning(
"Setup",
"failed to enable SIGURG generation on incoming OOB");
454 Fatal(
"GetOptions",
"must be started with 4 arguments");
483 Error(
"Run",
"invalid instance: cannot Run()");
500 Error(
"HandleSocketInput",
"retrieving message from input socket");
507 Info(
"HandleSocketInput",
"got message of type %d", what);
515 Info(
"HandleSocketInput:kMESS_CINT",
"processing: %s...", str);
548 {
char name[2048], i1[20], i2[40];
549 sscanf(str,
"%2047s %19s %39s",
name, i1, i2);
550 Int_t bin = atoi(i1);
570 Warning(
"HandleSocketInput",
"message type unknown (%d)", what);
586 const Int_t kBufSize = 1024;
587 char waste[kBufSize];
592 Info(
"HandleUrgentData",
"handling oob...");
613 if (nch > kBufSize) nch = kBufSize;
616 Error(
"HandleUrgentData",
"error receiving waste");
621 Error(
"HandleUrgentData",
"error receiving OOB (n = %d)",
n);
626 Info(
"HandleUrgentData",
"got OOB byte: %d\n", oob_byte);
631 Info(
"HandleUrgentData",
"*** Hard Interrupt");
644 Error(
"HandleUrgentData",
"error sending OOB");
655 if (nch > kBufSize) nch = kBufSize;
658 Error(
"HandleUrgentData",
"error receiving waste (2)");
668 Info(
"HandleUrgentData",
"Soft Interrupt");
671 Error(
"HandleUrgentData",
"soft interrupt flushed stream");
682 Info(
"HandleUrgentData",
"Shutdown Interrupt");
689 Error(
"HandleUrgentData",
"unexpected OOB byte");
703 Info(
"HandleSigPipe",
"client died");
733 if (size <= 0)
return 0;
742 const Int_t kMAXBUF = 16384;
743 char buf[kMAXBUF], cpy[kMAXBUF];
748 while (filesize < size) {
749 left =
Int_t(size - filesize);
761 Int_t k = 0, i = 0, j = 0;
778 SysError(
"ReceiveFile",
"error writing to file %s",
file);
786 Error(
"ReceiveFile",
"error during receiving file %s",
file);
809 off_t ltot=0, lnow=0;
814 ltot = lseek(fileno(stdout), (off_t) 0, SEEK_END);
817 SysError(
"SendLogFile",
"lseek failed");
823 if (end <= start || end > ltot)
825 left = (
Int_t)(end - start);
830 left = (
Int_t)(ltot - lnow);
841 const Int_t kMAXBUF = 32768;
843 Int_t wanted = (left > kMAXBUF) ? kMAXBUF : left;
846 while ((len = read(
fLogFileDes, buf, wanted)) < 0 &&
851 SysError(
"SendLogFile",
"error reading log file");
855 if (end == ltot && len == wanted)
859 SysError(
"SendLogFile",
"error sending log file");
865 wanted = (left > kMAXBUF) ? kMAXBUF : left;
867 }
while (len > 0 && left > 0);
891 while ((o = next())) {
906 Info(
"SendCanvases",
"new canvas found: %p", o);
955 if (!fname || !*fname) {
960 while ((fh = (
TNamed *)next())) {
978 TIter nextk(keylist);
981 while ((key = (
TNamed *)nextk())) {
983 const char *classname = (
const char *)
gROOT->ProcessLine(
Form(
"((TKey *)0x%lx)->GetClassName();", (
ULong_t)key));
1039 while ((fh = next())) {
1040 TASInputHandler *ih =
dynamic_cast<TASInputHandler *
>(fh);
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());
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);
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);
1165 fprintf(stderr,
"aborting\n");
1184 if (!strncmp(
line,
".L", 2) || !strncmp(
line,
".U", 2) ||
1185 !strncmp(
line,
".X", 2) || !strncmp(
line,
".x", 2)) {
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);
1295 const char *logon =
gEnv->
GetValue(
"Rint.Logon", (
char*)0);
const Int_t kRRemote_Protocol
R__EXTERN TBenchmark * gBenchmark
void Error(const char *location, const char *msgfmt,...)
R__EXTERN Int_t gErrorAbortLevel
R__EXTERN Int_t gErrorIgnoreLevel
ErrorHandlerFunc_t SetErrorHandler(ErrorHandlerFunc_t newhandler)
Set an errorhandler function. Returns the old handler.
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,...)
R__EXTERN TSystem * gSystem
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.
TASLogHandler(const char *cmd, TSocket *s, const char *pfx="")
Execute 'cmd' in a pipe and handle output messages from the related file.
Bool_t Notify()
Handle available message in the open file.
static void SetDefaultPrefix(const char *pfx)
Static method to set the default prefix.
void ExecLogon()
Execute logon macro's.
Int_t SendCanvases()
Send any created canvas to client.
void Terminate(Int_t status)
Terminate the proof server.
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 GetOptions(Int_t *argc, char **argv)
Get and handle command line options.
void Reset(const char *dir)
Reset environment to be ready for execution of next command.
void Run(Bool_t retrn=kFALSE)
Main server eventloop.
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.
Long_t ProcessLine(const char *line, Bool_t=kFALSE, Int_t *err=0)
Parse a command line received from the client, making sure that the files needed for the execution,...
void HandleCheckFile(TMessage *mess)
Handle file checking request.
virtual ~TApplicationServer()
Cleanup.
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.
This class creates the ROOT Application Environment that interfaces to the windowing system eventloop...
virtual void Run(Bool_t retrn=kFALSE)
Main application eventloop. Calls system dependent eventloop via gSystem.
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 Long_t ProcessFile(const char *file, Int_t *error=0, 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.
virtual Int_t GetEntries() const
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
Describe directory structure in memory.
virtual Bool_t cd(const char *path=nullptr)
Change current directory to "this" directory.
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
virtual Bool_t Notify()
Notify when event occurred on descriptor associated with this handler.
virtual Bool_t ReadNotify()
Notify when something can be read from the descriptor associated with this handler.
virtual void Add(TObject *obj)
virtual TObjLink * FirstLink() const
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.
virtual const char * GetTitle() const
Returns title of object.
virtual const char * GetName() const
Returns name of object.
Wrapper around a TObject so it can be stored in a TList.
TObject * GetObject() const
Mother of all ROOT objects.
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
@ kNotDeleted
object has not been deleted
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.
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 SetRemoteAddress(Long_t addr)
virtual void Browse(TBrowser *b)
Browse remote object.
void SetFolder(Bool_t isFolder)
virtual Bool_t Notify()
Notify when signal occurs.
Option_t * GetOption() const
virtual Int_t SetOption(ESockOptions opt, Int_t val)
Set socket options.
virtual Int_t Recv(TMessage *&mess)
Receive a TMessage object.
virtual Int_t RecvRaw(void *buffer, Int_t length, ESendRecvOptions opt=kDefault)
Receive a raw buffer of specified length bytes.
virtual Int_t SendRaw(const void *buffer, Int_t length, ESendRecvOptions opt=kDefault)
Send a raw buffer of specified length.
virtual Int_t GetDescriptor() const
virtual Int_t Send(const TMessage &mess)
Send a TMessage object.
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.
virtual void AddFileHandler(TFileHandler *fh)
Add a file handler to the list of system file handlers.
virtual void Syslog(ELogLevel level, const char *mess)
Send mess to syslog daemon.
static void ResetErrno()
Static function resetting system error number.
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
virtual void Openlog(const char *name, Int_t options, ELogFacility facility)
Open connection to system log daemon.
static Int_t GetErrno()
Static function returning system error number.
virtual int GetPid()
Get process id.
virtual TString SplitAclicMode(const char *filename, TString &mode, TString &args, TString &io) const
This method split a filename of the form:
virtual char * ConcatFileName(const char *dir, const char *name)
Concatenate a directory and a file name. User must delete returned string.
virtual int mkdir(const char *name, Bool_t recursive=kFALSE)
Make a file system directory.
virtual const char * HomeDirectory(const char *userName=0)
Return the user's home directory.
virtual TFileHandler * RemoveFileHandler(TFileHandler *fh)
Remove a file handler from the list of file handlers.
virtual TSeqCollection * GetListOfFileHandlers() const
virtual FILE * OpenPipe(const char *command, const char *mode)
Open a pipe.
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
virtual Bool_t ChangeDirectory(const char *path)
Change directory.
virtual int ClosePipe(FILE *pipe)
Close the pipe.
virtual const char * BaseName(const char *pathname)
Base name of a file name. Base name of /user/root is root.
virtual void AddSignalHandler(TSignalHandler *sh)
Add a signal handler to list of system signal handlers.
virtual void Exit(int code, Bool_t mode=kTRUE)
Exit the application.
virtual const char * HostName()
Return the system's host name.
virtual void Sleep(UInt_t milliSec)
Sleep milliSec milli seconds.
virtual const char * WorkingDirectory()
Return working directory.
virtual char * Which(const char *search, const char *file, EAccessMode mode=kFileExists)
Find location of file in a search path.
virtual void Abort(int code=0)
Abort the application.
virtual int Unlink(const char *name)
Unlink, i.e.
virtual void StackTrace()
Print a stack trace.
const char * GetFile() const
void SetUrl(const char *url, Bool_t defaultIsFile=kFALSE)
Parse url character string and split in its different subcomponents.
static constexpr double s