21 #include "RConfigure.h"
33 #include <sys/types.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"
85 fServ->HandleUrgentData();
108 fServ->HandleSigPipe();
129 fServ->HandleSocketInput();
133 TString TASLogHandler::fgPfx =
"";
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);
197 while (fgets(line,
sizeof(line),
fFile)) {
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)
288 GetOptions(argc, argv);
298 fLogFilePath = logfile;
301 if (!fLogFile || (fLogFileDes = fileno(fLogFile)) < 0)
314 if (!(fSocket =
new TSocket(GetHost(), GetPort()))) {
318 Int_t sock = fSocket->GetDescriptor();
321 Error(
"TApplicationServer",
"failed to setup - quitting");
327 ProcessLine(
"#include <iostream>",
kTRUE);
328 ProcessLine(
"#include <string>",
kTRUE);
336 ProcessLine(
Form(
".L %s", logon),
kTRUE);
369 snprintf(str, 512,
"**** Remote session @ %s started ****",
gSystem->
HostName());
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",
413 #if 0 // G.Ganis May 11, 2007
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;
736 Int_t fd =
open(file, O_CREAT | O_TRUNC | O_WRONLY, 0600);
738 SysError(
"ReceiveFile",
"error opening file %s", file);
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;
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) {
961 robj =
new TRemoteObject(fh->GetName(), fh->GetTitle(),
"TFile");
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");
1180 if (!line || !*line)
return 0;
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);
1305 const char *logon =
gEnv->
GetValue(
"Rint.Logon", (
char*)0);
ClassImp(TApplicationServer) TApplicationServer
Main constructor.
virtual const char * BaseName(const char *pathname)
Base name of a file name. Base name of /user/root is root.
virtual Int_t GetEntries() const
virtual const char * GetTitle() const
Returns title of object.
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
double read(const std::string &file_name)
reading
ErrorHandlerFunc_t SetErrorHandler(ErrorHandlerFunc_t newhandler)
Set an errorhandler function. Returns the old handler.
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 TString SplitAclicMode(const char *filename, TString &mode, TString &args, TString &io) const
This method split a filename of the form: ~~~ {.cpp} [path/]macro.C[+|++[k|f|g|O|c|s|d|v|-]][(args)]...
virtual int GetPid()
Get process id.
virtual void Syslog(ELogLevel level, const char *mess)
Send mess to syslog daemon.
virtual Bool_t Notify()
Notify when event occurred on descriptor associated with this handler.
TASLogHandler * fExecHandler
void SetKeyClassName(const char *name)
TRemoteObject * fWorkingDir
R__EXTERN Int_t gErrorIgnoreLevel
virtual const char * WorkingDirectory()
Return working directory.
virtual void StackTrace()
Print a stack trace.
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
ClassImp(TSeqCollection) Int_t TSeqCollection TIter next(this)
Return index of object in collection.
void HandleUrgentData()
Handle Out-Of-Band data sent by the master or client.
void GetOptions(Int_t *argc, char **argv)
Get and handle command line options.
static void ErrorHandler(Int_t level, Bool_t abort, const char *location, const char *msg)
The error handler function.
virtual Int_t Send(const TMessage &mess)
Send a TMessage object.
Option_t * GetOption() const
virtual Int_t SetOption(ESockOptions opt, Int_t val)
Set socket options.
TString & ReplaceAll(const TString &s1, const TString &s2)
virtual Int_t Recv(TMessage *&mess)
Receive a TMessage object.
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
void SetFolder(Bool_t isFolder)
void SetUrl(const char *url, Bool_t defaultIsFile=kFALSE)
Parse url character string and split in its different subcomponents.
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
virtual void AddSignalHandler(TSignalHandler *sh)
Add a signal handler to list of system signal handlers.
virtual const char * HomeDirectory(const char *userName=0)
Return the user's home directory.
virtual Bool_t ChangeDirectory(const char *path)
Change directory.
void Terminate(Int_t status)
Terminate the proof server.
R__EXTERN Int_t gErrorAbortLevel
virtual TSeqCollection * GetListOfFileHandlers() const
const Int_t kRRemote_Protocol
Int_t SendCanvases()
Send any created canvas to client.
virtual char * Which(const char *search, const char *file, EAccessMode mode=kFileExists)
Find location of file in a search path.
virtual FILE * OpenPipe(const char *command, const char *mode)
Open a pipe.
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
virtual TFileHandler * RemoveFileHandler(TFileHandler *fh)
Remove a file handler from the list of file handlers.
virtual int mkdir(const char *name, Bool_t recursive=kFALSE)
Make a file system directory.
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 * Data() const
virtual TObject * ReadObject(const TClass *cl)
Read object from I/O buffer.
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
virtual Int_t SendRaw(const void *buffer, Int_t length, ESendRecvOptions opt=kDefault)
Send a raw buffer of specified length.
static void SetDefaultPrefix(const char *pfx)
Static method to set the default prefix.
virtual Bool_t Notify()
Notify when signal occurs.
void SetRemoteAddress(Long_t addr)
virtual int Unlink(const char *name)
Unlink, i.e. remove, a file.
virtual ~TApplicationServer()
Cleanup.
The TRemoteObject class provides protocol for browsing ROOT objects from a remote ROOT session...
virtual void Sleep(UInt_t milliSec)
Sleep milliSec milli seconds.
This code implements the MD5 message-digest algorithm.
The TNamed class is the base class for all named ROOT classes.
virtual void Run(Bool_t retrn=kFALSE)
Main application eventloop. Calls system dependent eventloop via gSystem.
virtual char * ReadString(char *s, Int_t max)
Read string from I/O buffer.
static Bool_t Initialized()
Return kTRUE if the TROOT object has been initialized.
Int_t BrowseKey(const char *keyname)
Read key object and send it back to client.
void Run(Bool_t retrn=kFALSE)
Main server eventloop.
virtual void Browse(TBrowser *b)
Browse remote object.
Int_t Atoi() const
Return integer value of string.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
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 SendLogFile(Int_t status=0, Int_t start=-1, Int_t end=-1)
Send log file to master.
void Error(const char *location, const char *msgfmt,...)
void Reset()
Reset the message buffer so we can use (i.e. fill) it again.
const char Int_t const char TProof Int_t const char * workdir
Int_t BrowseFile(const char *fname)
Browse root file and send back its content; if fname is null, send the full list of files...
R__EXTERN TSystem * gSystem
R__EXTERN TBenchmark * gBenchmark
virtual Int_t GetValue(const char *name, Int_t dflt)
Returns the integer value for a resource.
TObject * GetObject() const
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Bool_t TestBit(UInt_t f) const
char * Form(const char *fmt,...)
TASLogHandler(const char *cmd, TSocket *s, const char *pfx="")
Execute 'cmd' in a pipe and handle output messages from the related file.
void HandleCheckFile(TMessage *mess)
Handle file checking request.
virtual const char * GetName() const
Returns name of object.
virtual void Abort(int code=0)
Abort the application.
This class is a ROOT utility to help benchmarking applications.
virtual TObjLink * FirstLink() const
virtual int ClosePipe(FILE *pipe)
Close the pipe.
void HandleSigPipe()
Called when the client is not alive anymore (i.e.
Int_t Setup()
Print the Remote Server logo on standard output.
virtual void SysError(const char *method, const char *msgfmt,...) const
Issue system error message.
void HandleSocketInput()
Handle input coming from the client or from the master server.
virtual const char * HostName()
Return the system's host name.
Describe directory structure in memory.
Wrapper around a TObject so it can be stored in a TList.
void Throw(int code)
If an exception context has been set (using the TRY and RETRY macros) jump back to where it was set...
Mother of all ROOT objects.
Int_t BrowseDirectory(const char *dirname)
Browse directory and send back its content to client.
virtual void Openlog(const char *name, Int_t options, ELogFacility facility)
Open connection to system log daemon.
virtual Bool_t cd(const char *path=0)
Change current directory to "this" directory.
void ErrorHandler(int level, const char *location, const char *fmt, va_list va)
General error handler function. It calls the user set error handler.
virtual void Add(TObject *obj)
R__EXTERN const char * gRootDir
virtual void Exit(int code, Bool_t mode=kTRUE)
Exit the application.
void WriteObject(const TObject *obj)
Write object to message buffer.
Bool_t Notify()
Handle available message in the open file.
void Reset(const char *dir)
Reset environment to be ready for execution of next command.
virtual ~TASLogHandlerGuard()
Close a guard for executing a command in a pipe.
virtual Bool_t ReadNotify()
Notify when something can be read from the descriptor associated with this handler.
void ExecLogon()
Execute logon macro's.
virtual void AddFileHandler(TFileHandler *fh)
Add a file handler to the list of system file handlers.
static void ResetErrno()
Static function resetting system error number.
This class creates the ROOT Application Environment that interfaces to the windowing system eventloop...
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
TClass * GetClass() const
Int_t ReceiveFile(const char *file, Bool_t bin, Long64_t size)
Receive a file, either sent by a client or a master server.
virtual Int_t RecvRaw(void *buffer, Int_t length, ESendRecvOptions opt=kDefault)
Receive a raw buffer of specified length bytes.
virtual ~TASLogHandler()
Handle available message in the open file.
virtual char * ConcatFileName(const char *dir, const char *name)
Concatenate a directory and a file name. User must delete returned string.
TASLogHandlerGuard(const char *cmd, TSocket *s, const char *pfx="", Bool_t on=kTRUE)
Init a guard for executing a command in a pipe.
const char * GetFile() const
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
virtual Long_t ProcessFile(const char *file, Int_t *error=0, Bool_t keep=kFALSE)
Process a file containing a C++ macro.
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.