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
64#include "compiledata.h"
82Bool_t TASInterruptHandler::Notify()
84 fServ->HandleUrgentData();
105Bool_t TASSigPipeHandler::Notify()
107 fServ->HandleSigPipe();
126Bool_t TASInputHandler::Notify()
128 fServ->HandleSocketInput();
151 Error(
"TASLogHandler",
"executing command in pipe");
154 Error(
"TASLogHandler",
155 "undefined command (%p) or socket (%p)", (
int *)cmd,
s);
172 Error(
"TASLogHandler",
"undefined file (%p) or socket (%p)",
f,
s);
197 if ((plf = strchr(
line,
'\n')))
229 const char *pfx,
Bool_t on)
237 Error(
"TASLogHandlerGuard",
"invalid handler");
241 Error(
"TASLogHandlerGuard",
"undefined command");
249 const char *pfx,
Bool_t on)
257 Error(
"TASLogHandlerGuard",
"invalid handler");
261 Error(
"TASLogHandlerGuard",
"undefined file");
283 FILE *flog,
const char *logfile)
320 Error(
"TApplicationServer",
"failed to setup - quitting");
370 Error(
"Setup",
"failed to send startup message");
376 Error(
"Setup",
"failed to send local protocol");
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");
480 Error(
"Run",
"invalid instance: cannot Run()");
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...");
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;
739 const Int_t kMAXBUF = 16384;
740 char buf[kMAXBUF], cpy[kMAXBUF];
745 while (filesize < size) {
746 left =
Int_t(size - filesize);
758 Int_t k = 0, i = 0, j = 0;
775 SysError(
"ReceiveFile",
"error writing to file %s",
file);
783 Error(
"ReceiveFile",
"error during receiving file %s",
file);
806 off_t ltot=0, lnow=0;
811 ltot = lseek(fileno(stdout), (off_t) 0, SEEK_END);
814 SysError(
"SendLogFile",
"lseek failed");
820 if (end <= start || end > ltot)
822 left = (
Int_t)(end - start);
827 left = (
Int_t)(ltot - lnow);
838 const Int_t kMAXBUF = 32768;
840 Int_t wanted = (left > kMAXBUF) ? kMAXBUF : left;
843 while ((len = read(
fLogFileDes, buf, wanted)) < 0 &&
848 SysError(
"SendLogFile",
"error reading log file");
852 if (end == ltot && len == wanted)
856 SysError(
"SendLogFile",
"error sending log file");
862 wanted = (left > kMAXBUF) ? kMAXBUF : left;
864 }
while (len > 0 && left > 0);
888 while ((o = next())) {
903 Info(
"SendCanvases",
"new canvas found: %p", o);
956 if (!fname || !*fname) {
961 while ((fh = (
TNamed *)next())) {
979 TIter nextk(keylist);
982 while ((key = (
TNamed *)nextk())) {
984 const char *classname = (
const char *)
gROOT->ProcessLine(
Form(
"((TKey *)0x%lx)->GetClassName();", (
ULong_t)key));
1044 while ((fh = next())) {
1045 TASInputHandler *ih =
dynamic_cast<TASInputHandler *
>(fh);
1064 (*mess) >> filenam >> md5;
1068 if (md5local && md5 == (*md5local)) {
1073 Info(
"HandleCheckFile",
"up-to-date version of %s available", filenam.
Data());
1078 Info(
"HandleCheckFile",
"file %s needs to be uploaded", filenam.
Data());
1116 if (syslogService.
IsNull()) {
1117 syslogService =
"server";
1121 const char *
type = 0;
1128 if (level >=
kInfo) {
1142 type =
"*** Break ***";
1156 if (!location || !location[0] ||
1159 fprintf(stderr,
"%s on %s: %s\n",
type, node.
Data(), msg);
1162 fprintf(stderr,
"%s in <%s> on %s: %s\n",
type, location, node.
Data(), msg);
1163 buf.
Form(
"%s:%s:<%s>:%s", node.
Data(),
type, location, msg);
1170 fprintf(stderr,
"aborting\n");
1189 if (!strncmp(
line,
".L", 2) || !strncmp(
line,
".U", 2) ||
1190 !strncmp(
line,
".X", 2) || !strncmp(
line,
".x", 2)) {
1206 Info(
"ProcessLine",
"macro %s not found in path %s: asking the client",
1216 while (filefollows) {
1221 Error(
"ProcessLine",
"ask-file: received empty message from client");
1225 Error(
"ProcessLine",
"ask-file: wrong message received (what: %d)", rm->
What());
1230 Error(
"ProcessLine",
"ask-file: wrong sub-type received (type: %d)",
type);
1233 (*rm) >> filefollows;
1237 Error(
"ProcessLine",
"file: received empty message from client");
1241 Error(
"ProcessLine",
"file: wrong message received (what: %d)", rm->
What());
1246 Error(
"ProcessLine",
"file: wrong sub-type received (type: %d)",
type);
1252 char name[2048], i1[20], i2[40];
1253 sscanf(str,
"%2047s %19s %39s",
name, i1, i2);
1254 Int_t bin = atoi(i1);
1300 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.
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,...)
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
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
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 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 const char * HomeDirectory(const char *userName=nullptr)
Return the user's home directory.
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