Logo ROOT   6.12/07
Reference Guide
TXProofMgr.cxx
Go to the documentation of this file.
1 // @(#)root/proofx:$Id$
2 // Author: Gerardo Ganis 12/12/2005
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2005, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 /**
12  \defgroup proofx XProofD client Library
13  \ingroup proof
14 
15  The XProofD client library, libProofx, contain the classes providing
16  the client to interact with the XRootD-based xproofd daemon.
17 
18 */
19 
20 /** \class TXProofMgr
21 \ingroup proofx
22 
23 Implementation of the functionality provided by TProofMgr in the case of a xproofd-based session.
24 
25 */
26 
27 #include <errno.h>
28 #include <memory>
29 #ifdef WIN32
30 #include <io.h>
31 #endif
32 
33 #include "Getline.h"
34 #include "TList.h"
35 #include "TObjArray.h"
36 #include "TObjString.h"
37 #include "TProof.h"
38 #include "TProofLog.h"
39 #include "TXProofMgr.h"
40 #include "TXSocket.h"
41 #include "TXSocketHandler.h"
42 #include "TROOT.h"
43 #include "TStopwatch.h"
44 #include "TSysEvtHandler.h"
45 #include "XProofProtocol.h"
46 
47 #include "XrdProofConn.h"
48 
50 
51 //
52 //----- ProofMgr Interrupt signal handler
53 //
54 class TProofMgrInterruptHandler : public TSignalHandler {
55 private:
56  TProofMgr *fMgr;
57 
58  TProofMgrInterruptHandler(const TProofMgrInterruptHandler&); // Not implemented
59  TProofMgrInterruptHandler& operator=(const TProofMgrInterruptHandler&); // Not implemented
60 public:
61  TProofMgrInterruptHandler(TProofMgr *mgr)
62  : TSignalHandler(kSigInterrupt, kFALSE), fMgr(mgr) { }
63  Bool_t Notify();
64 };
65 
66 ////////////////////////////////////////////////////////////////////////////////
67 /// TProofMgr interrupt handler.
68 
69 Bool_t TProofMgrInterruptHandler::Notify()
70 {
71  // Only on clients
72  if (isatty(0) != 0 && isatty(1) != 0) {
73  TString u = fMgr->GetUrl();
74  Printf("Opening new connection to %s", u.Data());
75  TXSocket *s = new TXSocket(u, 'C', kPROOF_Protocol,
76  kXPROOF_Protocol, 0, -1, (TXHandler *)fMgr);
77  if (s && s->IsValid()) {
78  // Set the interrupt flag on the server
79  s->CtrlC();
80  }
81  }
82  return kTRUE;
83 }
84 
85 // Autoloading hooks.
86 // These are needed to avoid using the plugin manager which may create
87 // problems in multi-threaded environments.
88 TProofMgr *GetTXProofMgr(const char *url, Int_t l, const char *al)
89 { return ((TProofMgr *) new TXProofMgr(url, l, al)); }
90 
91 class TXProofMgrInit {
92 public:
93  TXProofMgrInit() {
95 }};
96 static TXProofMgrInit gxproofmgr_init;
97 
98 ////////////////////////////////////////////////////////////////////////////////
99 /// Create a PROOF manager for the standard (old) environment.
100 
101 TXProofMgr::TXProofMgr(const char *url, Int_t dbg, const char *alias)
102  : TProofMgr(url, dbg, alias)
103 {
104  // Set the correct servert type
106 
107  // Initialize
108  if (Init(dbg) != 0) {
109  // Failure: make sure the socket is deleted so that its lack of
110  // validity is correctly transmitted
112  }
113 }
114 
115 ////////////////////////////////////////////////////////////////////////////////
116 /// Do real initialization: open the connection and set the relevant
117 /// variables.
118 /// Login and authentication are dealt with at this level, if required.
119 /// Return 0 in case of success, 1 if the remote server is a 'proofd',
120 /// -1 in case of error.
121 
123 {
124  // Here we make sure that the port is explicitly specified in the URL,
125  // even when it matches the default value
126  TString u = fUrl.GetUrl(kTRUE);
127 
128  fSocket = 0;
129  if (!(fSocket = new TXSocket(u, 'C', kPROOF_Protocol,
130  kXPROOF_Protocol, 0, -1, this)) ||
131  !(fSocket->IsValid())) {
132  if (!fSocket || !(fSocket->IsServProofd()))
133  if (gDebug > 0)
134  Error("Init", "while opening the connection to %s - exit (error: %d)",
135  u.Data(), (fSocket ? fSocket->GetOpenError() : -1));
136  if (fSocket && fSocket->IsServProofd())
138  return -1;
139  }
140 
141  // Protocol run by remote PROOF server
143 
144  // We add the manager itself for correct destruction
146  gROOT->GetListOfSockets()->Remove(fSocket);
147  }
148 
149  // Set interrupt PROOF handler from now on
150  fIntHandler = new TProofMgrInterruptHandler(this);
151 
152  // We are done
153  return 0;
154 }
155 
156 ////////////////////////////////////////////////////////////////////////////////
157 /// Destructor: close the connection
158 
160 {
161  SetInvalid();
162 }
163 
164 ////////////////////////////////////////////////////////////////////////////////
165 /// Invalidate this manager by closing the connection
166 
168 {
169  if (fSocket)
170  fSocket->Close("P");
172 
173  // Avoid destroying twice
175  gROOT->GetListOfSockets()->Remove(this);
176  }
177 }
178 
179 ////////////////////////////////////////////////////////////////////////////////
180 /// Dummy version provided for completeness. Just returns a pointer to
181 /// existing session 'id' (as shown by TProof::QuerySessions) or 0 if 'id' is
182 /// not valid. The boolena 'gui' should be kTRUE when invoked from the GUI.
183 
185 {
186  if (!IsValid()) {
187  Warning("AttachSession","invalid TXProofMgr - do nothing");
188  return 0;
189  }
190  if (!d) {
191  Warning("AttachSession","invalid description object - do nothing");
192  return 0;
193  }
194 
195  if (d->GetProof())
196  // Nothing to do if already in contact with proofserv
197  return d->GetProof();
198 
199  // Re-compose url
200  TString u(Form("%s/?%d", fUrl.GetUrl(kTRUE), d->GetRemoteId()));
201 
202  // We need this to set correctly the kUsingSessionGui bit before the first
203  // feedback messages arrive
204  if (gui)
205  u += "GUI";
206 
207  // Attach
208  TProof *p = new TProof(u, 0, 0, gDebug, 0, this);
209  if (p && p->IsValid()) {
210 
211  // Set reference manager
212  p->SetManager(this);
213 
214  // Save record about this session
215  Int_t st = (p->IsIdle()) ? TProofDesc::kIdle
217  d->SetStatus(st);
218  d->SetProof(p);
219 
220  // Set session tag
221  p->SetName(d->GetName());
222 
223  } else {
224  // Session creation failed
225  Error("AttachSession", "attaching to PROOF session");
226  }
227  return p;
228 }
229 
230 ////////////////////////////////////////////////////////////////////////////////
231 /// Detach session with 'id' from its proofserv. The 'id' is the number
232 /// shown by QuerySessions. The correspondent TProof object is deleted.
233 /// If id == 0 all the known sessions are detached.
234 /// Option opt="S" or "s" forces session shutdown.
235 
237 {
238  if (!IsValid()) {
239  Warning("DetachSession","invalid TXProofMgr - do nothing");
240  return;
241  }
242 
243  if (id > 0) {
244  // Single session request
245  TProofDesc *d = GetProofDesc(id);
246  if (d) {
247  if (fSocket)
249  TProof *p = d->GetProof();
250  fSessions->Remove(d);
251  SafeDelete(p);
252  delete d;
253  }
254  } else if (id == 0) {
255 
256  // Requesto to destroy all sessions
257  if (fSocket) {
258  TString o = Form("%sA",opt);
259  fSocket->DisconnectSession(-1, o);
260  }
261  if (fSessions) {
262  // Delete PROOF sessions
263  TIter nxd(fSessions);
264  TProofDesc *d = 0;
265  while ((d = (TProofDesc *)nxd())) {
266  TProof *p = d->GetProof();
267  SafeDelete(p);
268  }
269  fSessions->Delete();
270  }
271  }
272 
273  return;
274 }
275 
276 ////////////////////////////////////////////////////////////////////////////////
277 /// Detach session 'p' from its proofserv. The instance 'p' is invalidated
278 /// and should be deleted by the caller
279 
281 {
282  if (!IsValid()) {
283  Warning("DetachSession","invalid TXProofMgr - do nothing");
284  return;
285  }
286 
287  if (p) {
288  // Single session request
289  TProofDesc *d = GetProofDesc(p);
290  if (d) {
291  if (fSocket)
293  fSessions->Remove(d);
294  p->Close(opt);
295  delete d;
296  }
297  }
298 
299  return;
300 }
301 
302 ////////////////////////////////////////////////////////////////////////////////
303 /// Checks if 'url' refers to the same 'user@host:port' entity as the URL
304 /// in memory. TProofMgr::MatchUrl cannot be used here because of the
305 /// 'double' default port, implying an additional check on the port effectively
306 /// open.
307 
308 Bool_t TXProofMgr::MatchUrl(const char *url)
309 {
310  if (!IsValid()) {
311  Warning("MatchUrl","invalid TXProofMgr - do nothing");
312  return 0;
313  }
314 
315  TUrl u(url);
316 
317  // Correct URL protocol
318  if (!strcmp(u.GetProtocol(), TUrl("a").GetProtocol()))
319  u.SetProtocol("proof");
320 
321  if (u.GetPort() == TUrl("a").GetPort()) {
322  // Set default port
323  Int_t port = gSystem->GetServiceByName("proofd");
324  if (port < 0)
325  port = 1093;
326  u.SetPort(port);
327  }
328 
329  // Now we can check
330  if (!strcmp(u.GetHostFQDN(), fUrl.GetHost()))
331  if (u.GetPort() == fUrl.GetPort() ||
332  u.GetPort() == fSocket->GetPort())
333  if (strlen(u.GetUser()) <= 0 || !strcmp(u.GetUser(),fUrl.GetUser()))
334  return kTRUE;
335 
336  // Match failed
337  return kFALSE;
338 }
339 
340 ////////////////////////////////////////////////////////////////////////////////
341 /// Show available workers
342 
344 {
345  if (!IsValid()) {
346  Warning("ShowWorkers","invalid TXProofMgr - do nothing");
347  return;
348  }
349 
350  // Send the request
352  if (os) {
353  TObjArray *oa = TString(os->GetName()).Tokenize(TString("&"));
354  if (oa) {
355  TIter nxos(oa);
356  TObjString *to = 0;
357  while ((to = (TObjString *) nxos()))
358  // Now parse them ...
359  Printf("+ %s", to->GetName());
360  }
361  }
362 }
363 
364 ////////////////////////////////////////////////////////////////////////////////
365 /// Gets the URL to be prepended to paths when accessing the MSS associated
366 /// with the connected cluster, if any. The information is retrieved from
367 /// the cluster the first time or if retrieve is true.
368 
370 {
371  if (fMssUrl.IsNull() || retrieve) {
372  // Nothing to do if not in contact with proofserv
373  if (!IsValid()) {
374  Error("GetMssUrl", "invalid TXProofMgr - do nothing");
375  return 0;
376  }
377  // Server may not support it
378  if (fSocket->GetXrdProofdVersion() < 1007) {
379  Error("GetMssUrl", "functionality not supported by server");
380  return 0;
381  }
383  if (os) {
384  Printf("os: '%s'", os->GetName());
385  fMssUrl = os->GetName();
386  SafeDelete(os);
387  } else {
388  Error("GetMssUrl", "problems retrieving the required information");
389  return 0;
390  }
391  } else if (!IsValid()) {
392  Warning("GetMssUrl", "TXProofMgr is now invalid: information may not be valid");
393  return 0;
394  }
395 
396  // Done
397  return fMssUrl.Data();
398 }
399 
400 ////////////////////////////////////////////////////////////////////////////////
401 /// Get list of sessions accessible to this manager
402 
404 {
405  if (opt && !strncasecmp(opt,"L",1))
406  // Just return the existing list
407  return fSessions;
408 
409  // Nothing to do if not in contact with proofserv
410  if (!IsValid()) {
411  Warning("QuerySessions","invalid TXProofMgr - do nothing");
412  return 0;
413  }
414 
415  // Create list if not existing
416  if (!fSessions) {
417  fSessions = new TList();
418  fSessions->SetOwner();
419  }
420 
421  // Send the request
422  TList *ocl = new TList;
424  if (os) {
425  TObjArray *oa = TString(os->GetName()).Tokenize(TString("|"));
426  if (oa) {
427  TProofDesc *d = 0;
428  TIter nxos(oa);
429  TObjString *to = (TObjString *) nxos();
430  if (to && to->GetString().IsDigit() && !strncasecmp(opt,"S",1))
431  Printf("// +++ %s session(s) currently active +++", to->GetName());
432  while ((to = (TObjString *) nxos())) {
433  // Now parse them ...
434  Int_t id = -1, st = -1;
435  TString al, tg, tk;
436  Ssiz_t from = 0;
437  while (to->GetString()[from] == ' ') { from++; }
438  if (!to->GetString().Tokenize(tk, from, " ") || !tk.IsDigit()) continue;
439  id = tk.Atoi();
440  if (!to->GetString().Tokenize(tg, from, " ")) continue;
441  if (!to->GetString().Tokenize(al, from, " ")) continue;
442  if (!to->GetString().Tokenize(tk, from, " ") || !tk.IsDigit()) continue;
443  st = tk.Atoi();
444  // Add to the list, if not already there
445  if (!(d = (TProofDesc *) fSessions->FindObject(tg))) {
446  Int_t locid = fSessions->GetSize() + 1;
447  d = new TProofDesc(tg, al, GetUrl(), locid, id, st, 0);
448  fSessions->Add(d);
449  } else {
450  // Set missing / update info
451  d->SetStatus(st);
452  d->SetRemoteId(id);
453  d->SetTitle(al);
454  }
455  // Add to the list for final garbage collection
456  ocl->Add(new TObjString(tg));
457  }
458  SafeDelete(oa);
459  }
460  SafeDelete(os);
461  }
462 
463  // Printout and Garbage collection
464  if (fSessions->GetSize() > 0) {
465  TIter nxd(fSessions);
466  TProofDesc *d = 0;
467  while ((d = (TProofDesc *)nxd())) {
468  if (ocl->FindObject(d->GetName())) {
469  if (opt && !strncasecmp(opt,"S",1))
470  d->Print("");
471  } else {
472  fSessions->Remove(d);
473  SafeDelete(d);
474  }
475  }
476  }
477 
478  // We are done
479  return fSessions;
480 }
481 
482 ////////////////////////////////////////////////////////////////////////////////
483 /// Handle asynchronous input on the socket
484 
486 {
487  if (fSocket && fSocket->IsValid()) {
488  TMessage *mess;
489  if (fSocket->Recv(mess) >= 0) {
490  Int_t what = mess->What();
491  if (gDebug > 0)
492  Info("HandleInput", "%p: got message type: %d", this, what);
493  switch (what) {
494  case kPROOF_TOUCH:
495  fSocket->RemoteTouch();
496  break;
497  default:
498  Warning("HandleInput", "%p: got unknown message type: %d", this, what);
499  break;
500  }
501  }
502  } else {
503  Warning("HandleInput", "%p: got message but socket is invalid!", this);
504  }
505 
506  // We are done
507  return kTRUE;
508 }
509 
510 ////////////////////////////////////////////////////////////////////////////////
511 /// Handle error on the input socket
512 
514 {
515  XHandleErr_t *herr = in ? (XHandleErr_t *)in : 0;
516 
517  // Try reconnection
518  if (fSocket && herr && (herr->fOpt == 1)) {
519  fSocket->Reconnect();
520  if (fSocket && fSocket->IsValid()) {
521  if (gDebug > 0)
522  Printf("ProofMgr: connection to coordinator at %s re-established",
523  fUrl.GetUrl());
524  return kFALSE;
525  }
526  }
527  Printf("TXProofMgr::HandleError: %p: got called ...", this);
528 
529  // Interrupt any PROOF session in Collect
530  if (fSessions && fSessions->GetSize() > 0) {
531  TIter nxd(fSessions);
532  TProofDesc *d = 0;
533  while ((d = (TProofDesc *)nxd())) {
534  TProof *p = (TProof *) d->GetProof();
535  if (p)
537  }
538  }
539  if (gDebug > 0)
540  Printf("TXProofMgr::HandleError: %p: DONE ... ", this);
541 
542  // We are done
543  return kTRUE;
544 }
545 
546 ////////////////////////////////////////////////////////////////////////////////
547 /// Send a cleanup request for the sessions associated with the current user.
548 /// If 'hard' is true sessions are signalled for termination and moved to
549 /// terminate at all stages (top master, sub-master, workers). Otherwise
550 /// (default) only top-master sessions are asked to terminate, triggering
551 /// a gentle session termination. In all cases all sessions should be gone
552 /// after a few (2 or 3) session checking cycles.
553 /// A user with superuser privileges can also asks cleaning for an different
554 /// user, specified by 'usr', or for all users (usr = *)
555 /// Return 0 on success, -1 in case of error.
556 
557 Int_t TXProofMgr::Reset(Bool_t hard, const char *usr)
558 {
559  // Nothing to do if not in contact with proofserv
560  if (!IsValid()) {
561  Warning("Reset","invalid TXProofMgr - do nothing");
562  return -1;
563  }
564 
565  Int_t h = (hard) ? 1 : 0;
567 
568  return 0;
569 }
570 
571 ////////////////////////////////////////////////////////////////////////////////
572 /// Get logs or log tails from last session associated with this manager
573 /// instance.
574 /// The arguments allow to specify a session different from the last one:
575 /// isess specifies a position relative to the last one, i.e. 1
576 /// for the next to last session; the absolute value is taken
577 /// so -1 and 1 are equivalent.
578 /// stag specifies the unique tag of the wanted session
579 /// The special value stag = "NR" allows to just initialize the TProofLog
580 /// object w/o retrieving the files; this may be useful when the number
581 /// of workers is large and only a subset of logs is required.
582 /// If 'stag' is specified 'isess' is ignored (unless stag = "NR").
583 /// If 'pattern' is specified only the lines containing it are retrieved
584 /// (remote grep functionality); to filter out a pattern 'pat' use
585 /// pattern = "-v pat".
586 /// If 'rescan' is TRUE, masters will rescan the worker sandboxes for the exact
587 /// paths, instead of using the save information; may be useful when the
588 /// ssave information looks wrong or incomplete.
589 /// Returns a TProofLog object (to be deleted by the caller) on success,
590 /// 0 if something wrong happened.
591 
592 TProofLog *TXProofMgr::GetSessionLogs(Int_t isess, const char *stag,
593  const char *pattern, Bool_t rescan)
594 {
595  // Nothing to do if not in contact with proofserv
596  if (!IsValid()) {
597  Warning("GetSessionLogs","invalid TXProofMgr - do nothing");
598  return 0;
599  }
600 
601  TProofLog *pl = 0;
602 
603  // The absolute value of isess counts
604  isess = (isess > 0) ? -isess : isess;
605 
606  // Special option in stag
607  bool retrieve = 1;
608  TString sesstag(stag);
609  if (sesstag == "NR") {
610  retrieve = 0;
611  sesstag = "";
612  }
613 
614  // Get the list of paths
615  Int_t xrs = (rescan) ? 1 : 0;
616  TObjString *os = fSocket->SendCoordinator(kQueryLogPaths, sesstag.Data(), isess, -1, xrs);
617 
618  // Analyse it now
619  Int_t ii = 0;
620  if (os) {
621  TString rs(os->GetName());
622  Ssiz_t from = 0;
623  // The session tag
624  TString tag;
625  if (!rs.Tokenize(tag, from, "|")) {
626  Warning("GetSessionLogs", "Session tag undefined: corruption?\n"
627  " (received string: %s)", os->GetName());
628  return (TProofLog *)0;
629  }
630  // The pool url
631  TString purl;
632  if (!rs.Tokenize(purl, from, "|")) {
633  Warning("GetSessionLogs", "Pool URL undefined: corruption?\n"
634  " (received string: %s)", os->GetName());
635  return (TProofLog *)0;
636  }
637  // Create the instance now
638  if (!pl)
639  pl = new TProofLog(tag, GetUrl(), this);
640 
641  // Per-node info
642  TString to;
643  while (rs.Tokenize(to, from, "|")) {
644  if (!to.IsNull()) {
645  TString ord(to);
646  ord.Strip(TString::kLeading, ' ');
647  TString url(ord);
648  if ((ii = ord.Index(" ")) != kNPOS)
649  ord.Remove(ii);
650  if ((ii = url.Index(" ")) != kNPOS)
651  url.Remove(0, ii + 1);
652  // Add to the list (special tag for valgrind outputs)
653  if (url.Contains(".valgrind")) ord += "-valgrind";
654  pl->Add(ord, url);
655  // Notify
656  if (gDebug > 1)
657  Info("GetSessionLogs", "ord: %s, url: %s", ord.Data(), url.Data());
658  }
659  }
660  // Cleanup
661  SafeDelete(os);
662  // Retrieve the default part if required
663  if (pl && retrieve) {
664  const char *pat = pattern ? pattern : "-v \"| SvcMsg\"";
665  if (pat && strlen(pat) > 0)
666  pl->Retrieve("*", TProofLog::kGrep, 0, pat);
667  else
668  pl->Retrieve();
669  }
670  }
671 
672  // Done
673  return pl;
674 }
675 
676 ////////////////////////////////////////////////////////////////////////////////
677 /// Read, via the coordinator, 'len' bytes from offset 'ofs' of 'file'.
678 /// Returns a TObjString with the content or 0, in case of failure
679 
680 TObjString *TXProofMgr::ReadBuffer(const char *fin, Long64_t ofs, Int_t len)
681 {
682  // Nothing to do if not in contact with proofserv
683  if (!IsValid()) {
684  Warning("ReadBuffer","invalid TXProofMgr - do nothing");
685  return (TObjString *)0;
686  }
687 
688  // Send the request
689  return fSocket->SendCoordinator(kReadBuffer, fin, len, ofs, 0);
690 }
691 
692 ////////////////////////////////////////////////////////////////////////////////
693 /// Read, via the coordinator, 'fin' filtered. If 'pattern' starts with '|',
694 /// it represents a command filtering the output. Elsewhere, it is a grep
695 /// pattern. Returns a TObjString with the content or 0 in case of failure
696 
697 TObjString *TXProofMgr::ReadBuffer(const char *fin, const char *pattern)
698 {
699  // Nothing to do if not in contact with proofserv
700  if (!IsValid()) {
701  Warning("ReadBuffer", "invalid TXProofMgr - do nothing");
702  return (TObjString *)0;
703  }
704 
705  const char *ptr;
706  Int_t type; // 1 = grep, 2 = grep -v, 3 = pipe through cmd
707  if (*pattern == '|') {
708  ptr = &pattern[1]; // strip first char if it is a command
709  type = 3;
710  }
711  else {
712  ptr = pattern;
713  type = 1;
714  }
715 
716  // Prepare the buffer
717  Int_t plen = strlen(ptr);
718  Int_t lfi = strlen(fin);
719  char *buf = new char[lfi + plen + 1];
720  memcpy(buf, fin, lfi);
721  memcpy(buf+lfi, ptr, plen);
722  buf[lfi+plen] = 0;
723 
724  // Send the request
725  return fSocket->SendCoordinator(kReadBuffer, buf, plen, 0, type);
726 }
727 
728 ////////////////////////////////////////////////////////////////////////////////
729 /// Display what ROOT versions are available on the cluster
730 
732 {
733  // Nothing to do if not in contact with proofserv
734  if (!IsValid()) {
735  Warning("ShowROOTVersions","invalid TXProofMgr - do nothing");
736  return;
737  }
738 
739  // Send the request
741  if (os) {
742  // Display it
743  Printf("----------------------------------------------------------\n");
744  Printf("Available versions (tag ROOT-vers remote-path PROOF-version):\n");
745  Printf("%s", os->GetName());
746  Printf("----------------------------------------------------------");
747  SafeDelete(os);
748  }
749 
750  // We are done
751  return;
752 }
753 
754 ////////////////////////////////////////////////////////////////////////////////
755 /// Set the default ROOT version to be used
756 
758 {
759  // Nothing to do if not in contact with proofserv
760  if (!IsValid()) {
761  Warning("SetROOTVersion","invalid TXProofMgr - do nothing");
762  return -1;
763  }
764 
765  // Send the request
767 
768  // We are done
769  return (fSocket->GetOpenError() != kXR_noErrorYet) ? -1 : 0;
770 }
771 
772 ////////////////////////////////////////////////////////////////////////////////
773 /// Send a message to connected users. Only superusers can do this.
774 /// The first argument specifies the message or the file from where to take
775 /// the message.
776 /// The second argument specifies the user to which to send the message: if
777 /// empty or null the message is send to all the connected users.
778 /// return 0 in case of success, -1 in case of error
779 
780 Int_t TXProofMgr::SendMsgToUsers(const char *msg, const char *usr)
781 {
782  Int_t rc = 0;
783 
784  // Check input
785  if (!msg || strlen(msg) <= 0) {
786  Error("SendMsgToUsers","no message to send - do nothing");
787  return -1;
788  }
789 
790  // Buffer (max 32K)
791  const Int_t kMAXBUF = 32768;
792  char buf[kMAXBUF] = {0};
793  char *p = &buf[0];
794  size_t space = kMAXBUF - 1;
795  Int_t lusr = 0;
796 
797  // A specific user?
798  if (usr && strlen(usr) > 0 && (strlen(usr) != 1 || usr[0] != '*')) {
799  lusr = (strlen(usr) + 3);
800  snprintf(buf, kMAXBUF, "u:%s ", usr);
801  p += lusr;
802  space -= lusr;
803  }
804 
805  ssize_t len = 0;
806  // Is it from file ?
807  if (!gSystem->AccessPathName(msg, kFileExists)) {
808  // From file: can we read it ?
810  Error("SendMsgToUsers","request to read message from unreadable file '%s'", msg);
811  return -1;
812  }
813  // Open the file
814  FILE *f = 0;
815  if (!(f = fopen(msg, "r"))) {
816  Error("SendMsgToUsers", "file '%s' cannot be open", msg);
817  return -1;
818  }
819  // Determine the number of bytes to be read from the file.
820  size_t left = 0;
821  off_t rcsk = lseek(fileno(f), (off_t) 0, SEEK_END);
822  if ((rcsk != (off_t)(-1))) {
823  left = (size_t) rcsk;
824  if ((lseek(fileno(f), (off_t) 0, SEEK_SET) == (off_t)(-1))) {
825  Error("SendMsgToUsers", "cannot rewind open file (seek to 0)");
826  fclose(f);
827  return -1;
828  }
829  } else {
830  Error("SendMsgToUsers", "cannot get size of open file (seek to END)");
831  fclose(f);
832  return -1;
833  }
834  // Now readout from file
835  size_t wanted = left;
836  if (wanted > space) {
837  wanted = space;
838  Warning("SendMsgToUsers",
839  "requested to send %lld bytes: max size is %lld bytes: truncating",
840  (Long64_t)left, (Long64_t)space);
841  }
842  do {
843  while ((len = read(fileno(f), p, wanted)) < 0 &&
844  TSystem::GetErrno() == EINTR)
846  if (len < 0) {
847  SysError("SendMsgToUsers", "error reading file");
848  break;
849  }
850 
851  // Update counters
852  left = (len >= (ssize_t)left) ? 0 : left - len;
853  p += len;
854  wanted = (left > kMAXBUF-1) ? kMAXBUF-1 : left;
855 
856  } while (len > 0 && left > 0);
857  // Close file
858  fclose(f);
859  } else {
860  // Add the message to the buffer
861  len = strlen(msg);
862  if (len > (ssize_t)space) {
863  Warning("SendMsgToUsers",
864  "requested to send %lld bytes: max size is %lld bytes: truncating",
865  (Long64_t)len, (Long64_t)space);
866  len = space;
867  }
868  memcpy(p, msg, len);
869  }
870 
871  // Null-terminate
872  buf[len + lusr] = 0;
873 
874  // Send the request
876 
877  return rc;
878 }
879 
880 ////////////////////////////////////////////////////////////////////////////////
881 /// Run 'grep' on the nodes
882 
883 void TXProofMgr::Grep(const char *what, const char *how, const char *where)
884 {
885  // Nothing to do if not in contact with proofserv
886  if (!IsValid()) {
887  Error("Grep","invalid TXProofMgr - do nothing");
888  return;
889  }
890  // Server may not support it
891  if (fSocket->GetXrdProofdVersion() < 1006) {
892  Error("Grep", "functionality not supported by server");
893  return;
894  }
895 
896  // Send the request
897  TObjString *os = Exec(kGrep, what, how, where);
898 
899  // Show the result, if any
900  if (os) Printf("%s", os->GetName());
901 
902  // Cleanup
903  SafeDelete(os);
904 }
905 
906 ////////////////////////////////////////////////////////////////////////////////
907 /// Run 'find' on the nodes
908 
909 void TXProofMgr::Find(const char *what, const char *how, const char *where)
910 {
911  // Nothing to do if not in contact with proofserv
912  if (!IsValid()) {
913  Error("Find","invalid TXProofMgr - do nothing");
914  return;
915  }
916  // Server may not support it
917  if (fSocket->GetXrdProofdVersion() < 1006) {
918  Error("Find", "functionality not supported by server (XrdProofd version: %d)",
920  return;
921  }
922 
923  // Send the request
924  TObjString *os = Exec(kFind, what, how, where);
925 
926  // Show the result, if any
927  if (os) Printf("%s", os->GetName());
928 
929  // Cleanup
930  SafeDelete(os);
931 }
932 
933 ////////////////////////////////////////////////////////////////////////////////
934 /// Run 'ls' on the nodes
935 
936 void TXProofMgr::Ls(const char *what, const char *how, const char *where)
937 {
938  // Nothing to do if not in contact with proofserv
939  if (!IsValid()) {
940  Error("Ls","invalid TXProofMgr - do nothing");
941  return;
942  }
943  // Server may not support it
944  if (fSocket->GetXrdProofdVersion() < 1006) {
945  Error("Ls", "functionality not supported by server");
946  return;
947  }
948 
949  // Send the request
950  TObjString *os = Exec(kLs, what, how, where);
951 
952  // Show the result, if any
953  if (os) Printf("%s", os->GetName());
954 
955  // Cleanup
956  SafeDelete(os);
957 }
958 
959 ////////////////////////////////////////////////////////////////////////////////
960 /// Run 'more' on the nodes
961 
962 void TXProofMgr::More(const char *what, const char *how, const char *where)
963 {
964  // Nothing to do if not in contact with proofserv
965  if (!IsValid()) {
966  Error("More","invalid TXProofMgr - do nothing");
967  return;
968  }
969  // Server may not support it
970  if (fSocket->GetXrdProofdVersion() < 1006) {
971  Error("More", "functionality not supported by server");
972  return;
973  }
974 
975  // Send the request
976  TObjString *os = Exec(kMore, what, how, where);
977 
978  // Show the result, if any
979  if (os) Printf("%s", os->GetName());
980 
981  // Cleanup
982  SafeDelete(os);
983 }
984 
985 ////////////////////////////////////////////////////////////////////////////////
986 /// Run 'rm' on the nodes. The user is prompted before removal, unless 'how'
987 /// contains "--force" or a combination of single letter options including 'f',
988 /// e.g. "-fv".
989 
990 Int_t TXProofMgr::Rm(const char *what, const char *how, const char *where)
991 {
992  // Nothing to do if not in contact with proofserv
993  if (!IsValid()) {
994  Error("Rm","invalid TXProofMgr - do nothing");
995  return -1;
996  }
997  // Server may not support it
998  if (fSocket->GetXrdProofdVersion() < 1006) {
999  Error("Rm", "functionality not supported by server");
1000  return -1;
1001  }
1002 
1003  TString prompt, ans("Y"), opt(how);
1004  Bool_t force = kFALSE;
1005  if (!opt.IsNull()) {
1006  TString t;
1007  Int_t from = 0;
1008  while (!force && opt.Tokenize(t, from, " ")) {
1009  if (t == "--force") {
1010  force = kTRUE;
1011  } else if (t.BeginsWith("-") && !t.BeginsWith("--") && t.Contains("f")) {
1012  force = kTRUE;
1013  }
1014  }
1015  }
1016 
1017  if (!force && isatty(0) != 0 && isatty(1) != 0) {
1018  // Really remove the file?
1019  prompt.Form("Do you really want to remove '%s'? [N/y]", what);
1020  ans = "";
1021  while (ans != "N" && ans != "Y") {
1022  ans = Getline(prompt.Data());
1023  ans.Remove(TString::kTrailing, '\n');
1024  if (ans == "") ans = "N";
1025  ans.ToUpper();
1026  if (ans != "N" && ans != "Y")
1027  Printf("Please answer y, Y, n or N");
1028  }
1029  }
1030 
1031  if (ans == "Y") {
1032  // Send the request
1033  TObjString *os = Exec(kRm, what, how, where);
1034  // Show the result, if any
1035  if (os) {
1036  if (gDebug > 1) Printf("%s", os->GetName());
1037  // Cleanup
1038  SafeDelete(os);
1039  // Success
1040  return 0;
1041  }
1042  // Failure
1043  return -1;
1044  }
1045  // Done
1046  return 0;
1047 }
1048 
1049 ////////////////////////////////////////////////////////////////////////////////
1050 /// Run 'tail' on the nodes
1051 
1052 void TXProofMgr::Tail(const char *what, const char *how, const char *where)
1053 {
1054  // Nothing to do if not in contact with proofserv
1055  if (!IsValid()) {
1056  Error("Tail","invalid TXProofMgr - do nothing");
1057  return;
1058  }
1059  // Server may not support it
1060  if (fSocket->GetXrdProofdVersion() < 1006) {
1061  Error("Tail", "functionality not supported by server");
1062  return;
1063  }
1064 
1065  // Send the request
1066  TObjString *os = Exec(kTail, what, how, where);
1067 
1068  // Show the result, if any
1069  if (os) Printf("%s", os->GetName());
1070 
1071  // Cleanup
1072  SafeDelete(os);
1073 }
1074 
1075 ////////////////////////////////////////////////////////////////////////////////
1076 /// Run 'md5sum' on one of the nodes
1077 
1078 Int_t TXProofMgr::Md5sum(const char *what, TString &sum, const char *where)
1079 {
1080  // Nothing to do if not in contact with proofserv
1081  if (!IsValid()) {
1082  Error("Md5sum","invalid TXProofMgr - do nothing");
1083  return -1;
1084  }
1085  // Server may not support it
1086  if (fSocket->GetXrdProofdVersion() < 1006) {
1087  Error("Md5sum", "functionality not supported by server");
1088  return -1;
1089  }
1090 
1091  if (where && !strcmp(where, "all")) {
1092  Error("Md5sum","cannot run on all nodes at once: please specify one");
1093  return -1;
1094  }
1095 
1096  // Send the request
1097  TObjString *os = Exec(kMd5sum, what, 0, where);
1098 
1099  // Show the result, if any
1100  if (os) {
1101  if (gDebug > 1) Printf("%s", os->GetName());
1102  sum = os->GetName();
1103  // Cleanup
1104  SafeDelete(os);
1105  // Success
1106  return 0;
1107  }
1108  // Failure
1109  return -1;
1110 }
1111 
1112 ////////////////////////////////////////////////////////////////////////////////
1113 /// Run 'stat' on one of the nodes
1114 
1115 Int_t TXProofMgr::Stat(const char *what, FileStat_t &st, const char *where)
1116 {
1117  // Nothing to do if not in contact with proofserv
1118  if (!IsValid()) {
1119  Error("Stat","invalid TXProofMgr - do nothing");
1120  return -1;
1121  }
1122  // Server may not support it
1123  if (fSocket->GetXrdProofdVersion() < 1006) {
1124  Error("Stat", "functionality not supported by server");
1125  return -1;
1126  }
1127 
1128  if (where && !strcmp(where, "all")) {
1129  Error("Stat","cannot run on all nodes at once: please specify one");
1130  return -1;
1131  }
1132 
1133  // Send the request
1134  TObjString *os = Exec(kStat, what, 0, where);
1135 
1136  // Show the result, if any
1137  if (os) {
1138  if (gDebug > 1) Printf("%s", os->GetName());
1139 #if 0
1140  Int_t mode, uid, gid, islink;
1141  Long_t dev, ino, mtime;
1142  Long64_t size;
1143 #ifdef R__WIN32
1144  sscanf(os->GetName(), "%ld %ld %d %d %d %I64d %ld %d", &dev, &ino, &mode,
1145  &uid, &gid, &size, &mtime, &islink);
1146 #else
1147  sscanf(os->GetName(), "%ld %ld %d %d %d %lld %ld %d", &dev, &ino, &mode,
1148  &uid, &gid, &size, &mtime, &islink);
1149 #endif
1150  if (dev == -1)
1151  return -1;
1152  st.fDev = dev;
1153  st.fIno = ino;
1154  st.fMode = mode;
1155  st.fUid = uid;
1156  st.fGid = gid;
1157  st.fSize = size;
1158  st.fMtime = mtime;
1159  st.fIsLink = (islink == 1);
1160 #else
1161  TString tkn;
1162  Ssiz_t from = 0;
1163  if (!os->GetString().Tokenize(tkn, from, "[ ]+") || !tkn.IsDigit()) return -1;
1164  st.fDev = tkn.Atoi();
1165  if (st.fDev == -1) return -1;
1166  if (!os->GetString().Tokenize(tkn, from, "[ ]+") || !tkn.IsDigit()) return -1;
1167  st.fIno = tkn.Atoi();
1168  if (!os->GetString().Tokenize(tkn, from, "[ ]+") || !tkn.IsDigit()) return -1;
1169  st.fMode = tkn.Atoi();
1170  if (!os->GetString().Tokenize(tkn, from, "[ ]+") || !tkn.IsDigit()) return -1;
1171  st.fUid = tkn.Atoi();
1172  if (!os->GetString().Tokenize(tkn, from, "[ ]+") || !tkn.IsDigit()) return -1;
1173  st.fGid = tkn.Atoi();
1174  if (!os->GetString().Tokenize(tkn, from, "[ ]+") || !tkn.IsDigit()) return -1;
1175  st.fSize = tkn.Atoll();
1176  if (!os->GetString().Tokenize(tkn, from, "[ ]+") || !tkn.IsDigit()) return -1;
1177  st.fMtime = tkn.Atoi();
1178  if (!os->GetString().Tokenize(tkn, from, "[ ]+") || !tkn.IsDigit()) return -1;
1179  st.fIsLink = (tkn.Atoi() == 1) ? kTRUE : kFALSE;
1180 #endif
1181 
1182  // Cleanup
1183  SafeDelete(os);
1184  // Success
1185  return 0;
1186  }
1187  // Failure
1188  return -1;
1189 }
1190 
1191 ////////////////////////////////////////////////////////////////////////////////
1192 /// Execute 'action' (see EAdminExecType in 'XProofProtocol.h') at 'where'
1193 /// (default master), with options 'how', on 'what'. The option specified by
1194 /// 'how' are typically unix option for the relate commands. In addition to
1195 /// the unix authorizations, the limitations are:
1196 ///
1197 /// action = kRm limited to the sandbox (but basic dirs cannot be
1198 /// removed) and on files owned by the user in the
1199 /// allowed directories
1200 /// action = kTail option '-f' is not supported and will be ignored
1201 ///
1202 
1204  const char *what, const char *how, const char *where)
1205 {
1206  // Nothing to do if not in contact with proofserv
1207  if (!IsValid()) {
1208  Error("Exec","invalid TXProofMgr - do nothing");
1209  return (TObjString *)0;
1210  }
1211  // Server may not support it
1212  if (fSocket->GetXrdProofdVersion() < 1006) {
1213  Error("Exec", "functionality not supported by server");
1214  return (TObjString *)0;
1215  }
1216  // Check 'what'
1217  if (!what || strlen(what) <= 0) {
1218  Error("Exec","specifying a path is mandatory");
1219  return (TObjString *)0;
1220  }
1221  // Check the options
1222  TString opt(how);
1223  if (action == kTail && !opt.IsNull()) {
1224  // Keep only static options: -c, --bytes=N, -n , --lines=N, -N
1225  TString opts(how), o;
1226  Int_t from = 0;
1227  Bool_t isc = kFALSE, isn = kFALSE;
1228  while (opts.Tokenize(o, from, " ")) {
1229  // Skip values not starting with '-' is not argument to '-c' or '-n'
1230  if (!o.BeginsWith("-") && !isc && isn) continue;
1231  if (isc) {
1232  opt.Form("-c %s", o.Data());
1233  isc = kFALSE;
1234  }
1235  if (isn) {
1236  opt.Form("-n %s", o.Data());
1237  isn = kFALSE;
1238  }
1239  if (o == "-c") {
1240  isc = kTRUE;
1241  } else if (o == "-n") {
1242  isn = kTRUE;
1243  } else if (o == "--bytes=" || o == "--lines=") {
1244  opt = o;
1245  } else if (o.BeginsWith("-")) {
1246  o.Remove(TString::kLeading,'-');
1247  if (o.IsDigit()) opt.Form("-%s", o.Data());
1248  }
1249  }
1250  }
1251 
1252  // Build the command line
1253  TString cmd(where);
1254  if (cmd.IsNull()) cmd.Form("%s:%d", fUrl.GetHost(), fUrl.GetPort());
1255  cmd += "|";
1256  cmd += what;
1257  cmd += "|";
1258  cmd += opt;
1259 
1260  // On clients, handle Ctrl-C during collection
1261  if (fIntHandler) fIntHandler->Add();
1262 
1263  // Send the request
1264  TObjString *os = fSocket->SendCoordinator(kExec, cmd.Data(), action);
1265 
1266  // On clients, handle Ctrl-C during collection
1267  if (fIntHandler) fIntHandler->Remove();
1268 
1269  // Done
1270  return os;
1271 }
1272 
1273 ////////////////////////////////////////////////////////////////////////////////
1274 /// Get file 'remote' into 'local' from the master.
1275 /// If opt contains "force", the file, if it exists remotely, is copied in all cases,
1276 /// otherwise a check is done on the MD5sum.
1277 /// If opt contains "silent" standard notificatons are not printed (errors and
1278 /// warnings and prompts still are).
1279 /// Return 0 on success, -1 on error.
1280 
1281 Int_t TXProofMgr::GetFile(const char *remote, const char *local, const char *opt)
1282 {
1283  Int_t rc = -1;
1284  // Nothing to do if not in contact with proofserv
1285  if (!IsValid()) {
1286  Error("GetFile", "invalid TXProofMgr - do nothing");
1287  return rc;
1288  }
1289  // Server may not support it
1290  if (fSocket->GetXrdProofdVersion() < 1006) {
1291  Error("GetFile", "functionality not supported by server");
1292  return rc;
1293  }
1294 
1295  // Check remote path name
1296  TString filerem(remote);
1297  if (filerem.IsNull()) {
1298  Error("GetFile", "remote file path undefined");
1299  return rc;
1300  }
1301 
1302  // Parse option
1303  TString oo(opt);
1304  oo.ToUpper();
1305  Bool_t force = (oo.Contains("FORCE")) ? kTRUE : kFALSE;
1306  Bool_t silent = (oo.Contains("SILENT")) ? kTRUE : kFALSE;
1307 
1308  // Check local path name
1309  TString fileloc(local);
1310  if (fileloc.IsNull()) {
1311  // Set the same as the remote one, in the working dir
1312  fileloc = gSystem->BaseName(filerem);
1313  }
1314  gSystem->ExpandPathName(fileloc);
1315 
1316  // Default open and mode flags
1317 #ifdef WIN32
1318  UInt_t openflags = O_WRONLY | O_BINARY;
1319 #else
1320  UInt_t openflags = O_WRONLY;
1321 #endif
1322  UInt_t openmode = 0600;
1323 
1324  // Get information about the local file
1325  UserGroup_t *ugloc = 0;
1326  Int_t rcloc = 0;
1327  FileStat_t stloc;
1328  if ((rcloc = gSystem->GetPathInfo(fileloc, stloc)) == 0) {
1329  if (R_ISDIR(stloc.fMode)) {
1330  // Add the filename of the remote file and re-check
1331  if (!fileloc.EndsWith("/")) fileloc += "/";
1332  fileloc += gSystem->BaseName(filerem);
1333  // Get again the status of the path
1334  rcloc = gSystem->GetPathInfo(fileloc, stloc);
1335  }
1336  if (rcloc == 0) {
1337  // It exists already. If it is not a regular file we cannot continue
1338  if (!R_ISREG(stloc.fMode)) {
1339  if (!silent)
1340  Printf("[GetFile] local file '%s' exists and is not regular: cannot continue",
1341  fileloc.Data());
1342  return rc;
1343  }
1344  // Get our info
1345  if (!(ugloc = gSystem->GetUserInfo(gSystem->GetUid()))) {
1346  Error("GetFile", "cannot get user info for additional checks");
1347  return rc;
1348  }
1349  // Can we delete or overwrite it ?
1350  Bool_t owner = (ugloc->fUid == stloc.fUid && ugloc->fGid == stloc.fGid) ? kTRUE : kFALSE;
1351  Bool_t group = (!owner && ugloc->fGid == stloc.fGid) ? kTRUE : kFALSE;
1352  Bool_t other = (!owner && !group) ? kTRUE : kFALSE;
1353  delete ugloc;
1354  if ((owner && !(stloc.fMode & kS_IWUSR)) ||
1355  (group && !(stloc.fMode & kS_IWGRP)) || (other && !(stloc.fMode & kS_IWOTH))) {
1356  if (!silent) {
1357  Printf("[GetFile] file '%s' exists: no permission to delete or overwrite the file", fileloc.Data());
1358  Printf("[GetFile] ownership: owner: %d, group: %d, other: %d", owner, group, other);
1359  Printf("[GetFile] mode: %x", stloc.fMode);
1360  }
1361  return rc;
1362  }
1363  // In case we open the file, we need to truncate it
1364  openflags |= O_CREAT | O_TRUNC;
1365  } else {
1366  // In case we open the file, we need to create it
1367  openflags |= O_CREAT;
1368  }
1369  } else {
1370  // In case we open the file, we need to create it
1371  openflags |= O_CREAT;
1372  }
1373 
1374  // Check the remote file exists and get it check sum
1375  TString remsum;
1376  if (Md5sum(filerem, remsum) != 0) {
1377  if (!silent)
1378  Printf("[GetFile] remote file '%s' does not exists or cannot be read", filerem.Data());
1379  return rc;
1380  }
1381 
1382  // If the file exists already locally, check if it is different
1383  bool same = 0;
1384  if (rcloc == 0 && !force) {
1385  TMD5 *md5loc = TMD5::FileChecksum(fileloc);
1386  if (md5loc) {
1387  if (remsum == md5loc->AsString()) {
1388  if (!silent) {
1389  Printf("[GetFile] local file '%s' and remote file '%s' have the same MD5 check sum",
1390  fileloc.Data(), filerem.Data());
1391  Printf("[GetFile] use option 'force' to override");
1392  }
1393  same = 1;
1394  }
1395  delete md5loc;
1396  }
1397 
1398  // If a different file with the same name exists already, ask what to do
1399  if (!same) {
1400  const char *a = Getline("Local file exists already: would you like to overwrite it? [N/y]");
1401  if (a[0] == 'n' || a[0] == 'N' || a[0] == '\0') return 0;
1402  } else {
1403  return 0;
1404  }
1405  }
1406 
1407  // Open the local file for writing
1408  Int_t fdout = open(fileloc, openflags, openmode);
1409  if (fdout < 0) {
1410  Error("GetFile", "could not open local file '%s' for writing: errno: %d", local, errno);
1411  return rc;
1412  }
1413 
1414  // Build the command line
1415  TString cmd(filerem);
1416 
1417  // Disable TXSocket handling while receiving the file (CpProgress processes
1418  // pending events and this could screw-up synchronization in the TXSocket pipe)
1420 
1421  // Send the request
1422  TStopwatch watch;
1423  watch.Start();
1425 
1426  if (os) {
1427  // The message contains the size
1428  TString ssz(os->GetName());
1429  ssz.ReplaceAll(" ", "");
1430  if (!ssz.IsDigit()) {
1431  Error("GetFile", "received non-digit size string: '%s' ('%s')", os->GetName(), ssz.Data());
1432  close(fdout);
1433  return rc;
1434  }
1435  Long64_t size = ssz.Atoll();
1436  if (size <= 0) {
1437  Error("GetFile", "received null or negative size: %lld", size);
1438  close(fdout);
1439  return rc;
1440  }
1441 
1442  // Receive the file
1443  const Int_t kMAXBUF = 16384; //32768 //16384 //65536;
1444  char buf[kMAXBUF];
1445 
1446  rc = 0;
1447  Int_t rec, r;
1448  Long64_t filesize = 0, left = 0;
1449  while (rc == 0 && filesize < size) {
1450  left = size - filesize;
1451  if (left > kMAXBUF) left = kMAXBUF;
1452  rec = fSocket->RecvRaw(&buf, left);
1453  filesize = (rec > 0) ? (filesize + rec) : filesize;
1454  if (rec > 0) {
1455  char *p = buf;
1456  r = rec;
1457  while (r) {
1458  Int_t w = 0;
1459  while ((w = write(fdout, p, r)) < 0 && TSystem::GetErrno() == EINTR)
1461  if (w < 0) {
1462  SysError("GetFile", "error writing to unit: %d", fdout);
1463  rc = -1;
1464  break;
1465  }
1466  r -= w;
1467  p += w;
1468  }
1469  // Basic progress bar
1470  CpProgress("GetFile", filesize, size, &watch);
1471  } else if (rec < 0) {
1472  rc = -1;
1473  Error("GetFile", "error during receiving file");
1474  break;
1475  }
1476  }
1477  // Finalize the progress bar
1478  CpProgress("GetFile", filesize, size, &watch, kTRUE);
1479 
1480  } else {
1481  Error("GetFile", "size not received");
1482  rc = -1;
1483  }
1484 
1485  // Restore socket handling while receiving the file
1487 
1488  // Close local file
1489  close(fdout);
1490  watch.Stop();
1491  watch.Reset();
1492 
1493  if (rc == 0) {
1494  // Check if everything went fine
1495  std::unique_ptr<TMD5> md5loc(TMD5::FileChecksum(fileloc));
1496  if (!(md5loc.get())) {
1497  Error("GetFile", "cannot get MD5 checksum of the new local file '%s'", fileloc.Data());
1498  rc = -1;
1499  } else if (remsum != md5loc->AsString()) {
1500  Error("GetFile", "checksums for the local copy and the remote file differ: {rem:%s,loc:%s}",
1501  remsum.Data(), md5loc->AsString());
1502  rc = -1;
1503  }
1504  }
1505  // Done
1506  return rc;
1507 }
1508 
1509 ////////////////////////////////////////////////////////////////////////////////
1510 /// Put file 'local'to 'remote' to the master
1511 /// If opt is "force", the file, if it exists remotely, is copied in all cases,
1512 /// otherwise a check is done on the MD5sum.
1513 /// Return 0 on success, -1 on error
1514 
1515 Int_t TXProofMgr::PutFile(const char *local, const char *remote, const char *opt)
1516 {
1517  Int_t rc = -1;
1518  // Nothing to do if not in contact with proofserv
1519  if (!IsValid()) {
1520  Error("PutFile", "invalid TXProofMgr - do nothing");
1521  return rc;
1522  }
1523  // Server may not support it
1524  if (fSocket->GetXrdProofdVersion() < 1006) {
1525  Error("PutFile", "functionality not supported by server");
1526  return rc;
1527  }
1528 
1529  // Check local path name
1530  TString fileloc(local);
1531  if (fileloc.IsNull()) {
1532  Error("PutFile", "local file path undefined");
1533  return rc;
1534  }
1535  gSystem->ExpandPathName(fileloc);
1536 
1537  // Parse option
1538  TString oo(opt);
1539  oo.ToUpper();
1540  Bool_t force = (oo == "FORCE") ? kTRUE : kFALSE;
1541 
1542  // Check remote path name
1543  TString filerem(remote);
1544  if (filerem.IsNull()) {
1545  // Set the same as the local one, in the working dir
1546  filerem.Form("~/%s", gSystem->BaseName(fileloc));
1547  } else if (filerem.EndsWith("/")) {
1548  // Remote path is a directory: add the file name as in the local one
1549  filerem += gSystem->BaseName(fileloc);
1550  }
1551 
1552  // Default open flags
1553 #ifdef WIN32
1554  UInt_t openflags = O_RDONLY | O_BINARY;
1555 #else
1556  UInt_t openflags = O_RDONLY;
1557 #endif
1558 
1559  // Get information about the local file
1560  Int_t rcloc = 0;
1561  FileStat_t stloc;
1562  if ((rcloc = gSystem->GetPathInfo(fileloc, stloc)) != 0 || !R_ISREG(stloc.fMode)) {
1563  // It dies not exists or it is not a regular file: we cannot continue
1564  const char *why = (rcloc == 0) ? "is not regular" : "does not exists";
1565  Printf("[PutFile] local file '%s' %s: cannot continue", fileloc.Data(), why);
1566  return rc;
1567  }
1568  // Get our info
1569  UserGroup_t *ugloc = 0;
1570  if (!(ugloc = gSystem->GetUserInfo(gSystem->GetUid()))) {
1571  Error("PutFile", "cannot get user info for additional checks");
1572  return rc;
1573  }
1574  // Can we read it ?
1575  Bool_t owner = (ugloc->fUid == stloc.fUid && ugloc->fGid == stloc.fGid) ? kTRUE : kFALSE;
1576  Bool_t group = (!owner && ugloc->fGid == stloc.fGid) ? kTRUE : kFALSE;
1577  Bool_t other = (!owner && !group) ? kTRUE : kFALSE;
1578  delete ugloc;
1579  if ((owner && !(stloc.fMode & kS_IRUSR)) ||
1580  (group && !(stloc.fMode & kS_IRGRP)) || (other && !(stloc.fMode & kS_IROTH))) {
1581  Printf("[PutFile] file '%s': no permission to read the file", fileloc.Data());
1582  Printf("[PutFile] ownership: owner: %d, group: %d, other: %d", owner, group, other);
1583  Printf("[PutFile] mode: %x", stloc.fMode);
1584  return rc;
1585  }
1586 
1587  // Local MD5 sum
1588  TString locsum;
1589  TMD5 *md5loc = TMD5::FileChecksum(fileloc);
1590  if (!md5loc) {
1591  Error("PutFile", "cannot calculate the check sum for '%s'", fileloc.Data());
1592  return rc;
1593  } else {
1594  locsum = md5loc->AsString();
1595  delete md5loc;
1596  }
1597 
1598  // Check the remote file exists and get it check sum
1599  Bool_t same = kFALSE;
1600  FileStat_t strem;
1601  TString remsum;
1602  if (Stat(filerem, strem) == 0) {
1603  if (Md5sum(filerem, remsum) != 0) {
1604  Printf("[PutFile] remote file exists but the check sum calculation failed");
1605  return rc;
1606  }
1607  // Check sums
1608  if (remsum == locsum) {
1609  if (!force) {
1610  Printf("[PutFile] local file '%s' and remote file '%s' have the same MD5 check sum",
1611  fileloc.Data(), filerem.Data());
1612  Printf("[PutFile] use option 'force' to override");
1613  }
1614  same = kTRUE;
1615  }
1616  if (!force) {
1617  // If a different file with the same name exists already, ask what to do
1618  if (!same) {
1619  const char *a = Getline("Remote file exists already: would you like to overwrite it? [N/y]");
1620  if (a[0] == 'n' || a[0] == 'N' || a[0] == '\0') return 0;
1621  force = kTRUE;
1622  } else {
1623  return 0;
1624  }
1625  }
1626  }
1627 
1628  // Open the local file
1629  int fd = open(fileloc.Data(), openflags);
1630  if (fd < 0) {
1631  Error("PutFile", "cannot open file '%s': %d", fileloc.Data(), errno);
1632  return -1;
1633  }
1634 
1635  // Build the command line: 'path size [opt]'
1636  TString cmd;
1637  cmd.Form("%s %lld", filerem.Data(), stloc.fSize);
1638  if (force) cmd += " force";
1639 
1640  // Disable TXSocket handling while sending the file (CpProgress processes
1641  // pending events and this could screw-up synchronization in the TXSocket pipe)
1643 
1644  // Send the request
1645  TStopwatch watch;
1646  watch.Start();
1648 
1649  if (os) {
1650 
1651  // Send over the file
1652  const Int_t kMAXBUF = 16384; //32768 //16384 //65536;
1653  char buf[kMAXBUF];
1654 
1655  Long64_t pos = 0;
1656  lseek(fd, pos, SEEK_SET);
1657 
1658  rc = 0;
1659  while (rc == 0 && pos < stloc.fSize) {
1660  Long64_t left = stloc.fSize - pos;
1661  if (left > kMAXBUF) left = kMAXBUF;
1662  Int_t siz;
1663  while ((siz = read(fd, &buf[0], left)) < 0 && TSystem::GetErrno() == EINTR)
1665  if (siz < 0 || siz != left) {
1666  Error("PutFile", "error reading from file: errno: %d", errno);
1667  rc = -1;
1668  break;
1669  }
1670  Int_t src = 0;
1671  if ((src = fSocket->fConn->WriteRaw((void *)&buf[0], left)) != left) {
1672  Error("PutFile", "error sending over: errno: %d (rc: %d)", TSystem::GetErrno(), src);
1673  rc = -1;
1674  break;
1675  }
1676  // Basic progress bar
1677  CpProgress("PutFile", pos, stloc.fSize, &watch);
1678  // Re-position
1679  pos += left;
1680  }
1681  // Finalize the progress bar
1682  CpProgress("PutFile", pos, stloc.fSize, &watch, kTRUE);
1683 
1684  } else {
1685  Error("PutFile", "command could not be executed");
1686  rc = -1;
1687  }
1688 
1689  // Restore TXSocket handling
1691 
1692  // Close local file
1693  close(fd);
1694  watch.Stop();
1695  watch.Reset();
1696 
1697  if (rc == 0) {
1698  // Check if everything went fine
1699  if (Md5sum(filerem, remsum) != 0) {
1700  Printf("[PutFile] cannot get MD5 checksum of the new remote file '%s'", filerem.Data());
1701  rc = -1;
1702  } else if (remsum != locsum) {
1703  Printf("[PutFile] checksums for the local copy and the remote file differ: {rem:%s, loc:%s}",
1704  remsum.Data(), locsum.Data());
1705  rc = -1;
1706  }
1707  }
1708 
1709  // Done
1710  return rc;
1711 }
1712 
1713 ////////////////////////////////////////////////////////////////////////////////
1714 /// Print file copy progress.
1715 
1716 void TXProofMgr::CpProgress(const char *pfx, Long64_t bytes,
1717  Long64_t size, TStopwatch *watch, Bool_t cr)
1718 {
1719  // Protection
1720  if (!pfx || size == 0 || !watch) return;
1721 
1722  fprintf(stderr, "[%s] Total %.02f MB\t|", pfx, (Double_t)size/1048576);
1723 
1724  for (int l = 0; l < 20; l++) {
1725  if (size > 0) {
1726  if (l < 20*bytes/size)
1727  fprintf(stderr, "=");
1728  else if (l == 20*bytes/size)
1729  fprintf(stderr, ">");
1730  else if (l > 20*bytes/size)
1731  fprintf(stderr, ".");
1732  } else
1733  fprintf(stderr, "=");
1734  }
1735  // Allow to update the GUI while uploading files
1737  watch->Stop();
1738  Double_t copytime = watch->RealTime();
1739  fprintf(stderr, "| %.02f %% [%.01f MB/s]\r",
1740  100.0*bytes/size, bytes/copytime/1048576.);
1741  if (cr) fprintf(stderr, "\n");
1742  watch->Continue();
1743 }
1744 
1745 ////////////////////////////////////////////////////////////////////////////////
1746 /// Copy files in/out of the sandbox. Either 'src' or 'dst' must be in the
1747 /// sandbox.
1748 /// Return 0 on success, -1 on error
1749 
1750 Int_t TXProofMgr::Cp(const char *src, const char *dst, const char *fmt)
1751 {
1752  Int_t rc = -1;
1753  // Nothing to do if not in contact with proofserv
1754  if (!IsValid()) {
1755  Error("Cp", "invalid TXProofMgr - do nothing");
1756  return rc;
1757  }
1758  // Server may not support it
1759  if (fSocket->GetXrdProofdVersion() < 1006) {
1760  Error("Cp", "functionality not supported by server");
1761  return rc;
1762  }
1763 
1764  // Check source path name
1765  TString filesrc(src);
1766  if (filesrc.IsNull()) {
1767  Error("Cp", "source file path undefined");
1768  return rc;
1769  }
1770  // Check destination path name
1771  TString filedst(dst);
1772  if (filedst.IsNull()) {
1773  filedst = gSystem->BaseName(TUrl(filesrc.Data()).GetFile());
1774  } else if (filedst.EndsWith("/")) {
1775  // Remote path is a directory: add the file name as in the local one
1776  filedst += gSystem->BaseName(filesrc);
1777  }
1778 
1779  // Make sure that local files are in the format file://host/<file> otherwise
1780  // the URL class in the server will not parse them correctly
1781  TUrl usrc = TUrl(filesrc.Data(), kTRUE).GetUrl();
1782  filesrc = usrc.GetUrl();
1783  if (!strcmp(usrc.GetProtocol(), "file"))
1784  filesrc.Form("file://host/%s", usrc.GetFileAndOptions());
1785  TUrl udst = TUrl(filedst.Data(), kTRUE).GetUrl();
1786  filedst = udst.GetUrl();
1787  if (!strcmp(udst.GetProtocol(), "file"))
1788  filedst.Form("file://host/%s", udst.GetFileAndOptions());
1789 
1790  // Prepare the command
1791  TString cmd;
1792  cmd.Form("%s %s %s", filesrc.Data(), filedst.Data(), (fmt ? fmt : ""));
1793 
1794  // On clients, handle Ctrl-C during collection
1795  if (fIntHandler) fIntHandler->Add();
1796 
1797  // Send the request
1799 
1800  // On clients, handle Ctrl-C during collection
1801  if (fIntHandler) fIntHandler->Remove();
1802 
1803  // Show the result, if any
1804  if (os) {
1805  if (gDebug > 0) Printf("%s", os->GetName());
1806  rc = 0;
1807  }
1808 
1809  // Done
1810  return rc;
1811 }
Int_t fGid
Definition: TSystem.h:141
virtual const char * BaseName(const char *pathname)
Base name of a file name. Base name of /user/root is root.
Definition: TSystem.cxx:932
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
virtual void SysError(const char *method, const char *msgfmt,...) const
Issue system error message.
Definition: TObject.cxx:894
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
Definition: TSystem.cxx:1276
void ShowWorkers()
Show available workers.
Definition: TXProofMgr.cxx:343
Int_t GetOpenError() const
Getter for last error.
Definition: TXSocket.cxx:927
TObjString * ReadBuffer(const char *file, Long64_t ofs, Int_t len)
Read, via the coordinator, &#39;len&#39; bytes from offset &#39;ofs&#39; of &#39;file&#39;.
Definition: TXProofMgr.cxx:680
static long int sum(long int i)
Definition: Factory.cxx:2173
An array of TObjects.
Definition: TObjArray.h:37
virtual Bool_t ProcessEvents()
Process pending events (GUI, timers, sockets).
Definition: TSystem.cxx:424
TList * fSessions
Definition: TProofMgr.h:61
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
Definition: TList.cxx:467
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:854
void SetPort(Int_t port)
Definition: TUrl.h:91
Double_t RealTime()
Stop the stopwatch (if it is running) and return the realtime (in seconds) passed between the start a...
Definition: TStopwatch.cxx:110
void CpProgress(const char *pfx, Long64_t bytes, Long64_t size, TStopwatch *watch, Bool_t cr=kFALSE)
Print file copy progress.
long long Long64_t
Definition: RtypesCore.h:69
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
Definition: TStopwatch.cxx:58
Int_t Stat(const char *what, FileStat_t &st, const char *where=0)
Run &#39;stat&#39; on one of the nodes.
Int_t Md5sum(const char *what, TString &sum, const char *where=0)
Run &#39;md5sum&#39; on one of the nodes.
Int_t GetPort() const
Definition: TSocket.h:134
void DetachSession(Int_t, Option_t *="")
Detach session with &#39;id&#39; from its proofserv.
Definition: TXProofMgr.cxx:236
static TMD5 * FileChecksum(const char *file)
Returns checksum of specified file.
Definition: TMD5.cxx:474
void SetProtocol(const char *proto, Bool_t setDefaultPort=kFALSE)
Set protocol and, optionally, change the port accordingly.
Definition: TUrl.cxx:520
Bool_t HandleError(const void *in=0)
Handle error on the input socket.
Definition: TXProofMgr.cxx:513
Int_t Cp(const char *src, const char *dst=0, const char *opts=0)
Copy files in/out of the sandbox.
Collectable string class.
Definition: TObjString.h:28
virtual void Close(Option_t *opt="")
Close connection.
Definition: TXSocket.cxx:311
Int_t fRemoteProtocol
Definition: TProofMgr.h:59
const char Option_t
Definition: RtypesCore.h:62
void InterruptCurrentMonitor()
If in active in a monitor set ready state.
Definition: TProof.cxx:11307
const Ssiz_t kNPOS
Definition: RtypesCore.h:111
This class represents a WWW compatible URL.
Definition: TUrl.h:35
XrdProofConn * fConn
Definition: TXSocket.h:82
Int_t fUid
Definition: TSystem.h:129
static TXSocketHandler * GetSocketHandler(TFileHandler *h=0, TSocket *s=0)
Get an instance of the input socket handler with &#39;h&#39; as handler, connected to socket &#39;s&#39;...
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:638
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.
Definition: TSystem.cxx:1374
const char * GetProtocol() const
Definition: TUrl.h:67
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition: TNamed.cxx:140
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
TH1 * h
Definition: legend2.C:5
TProof * GetProof() const
Definition: TProofMgr.h:164
The PROOF manager interacts with the PROOF server coordinator to create or destroy a PROOF session...
Definition: TProofMgr.h:43
virtual void Add()
Add signal handler to system signal handler list.
void SetInvalid()
Invalidate this manager by closing the connection.
Definition: TXProofMgr.cxx:167
void ToUpper()
Change string to upper case.
Definition: TString.cxx:1112
void More(const char *what, const char *how=0, const char *where=0)
Run &#39;more&#39; on the nodes.
Definition: TXProofMgr.cxx:962
const char * GetFileAndOptions() const
Return the file and its options (the string specified behind the ?).
Definition: TUrl.cxx:501
#define gROOT
Definition: TROOT.h:402
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition: TString.h:585
const char * AsString() const
Return message digest as string.
Definition: TMD5.cxx:220
#define O_BINARY
Definition: civetweb.c:451
Basic string class.
Definition: TString.h:125
void Grep(const char *what, const char *how=0, const char *where=0)
Run &#39;grep&#39; on the nodes.
Definition: TXProofMgr.cxx:883
Int_t GetFile(const char *remote, const char *local, const char *opt=0)
Get file &#39;remote&#39; into &#39;local&#39; from the master.
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
R__EXTERN TVirtualMutex * gROOTMutex
Definition: TROOT.h:57
Long_t fMtime
Definition: TSystem.h:132
const char * GetMssUrl(Bool_t=kFALSE)
Gets the URL to be prepended to paths when accessing the MSS associated with the connected cluster...
Definition: TXProofMgr.cxx:369
Long64_t fSize
Definition: TSystem.h:131
TList * QuerySessions(Option_t *opt="S")
Get list of sessions accessible to this manager.
Definition: TXProofMgr.cxx:403
static void retrieve(const gsl_integration_workspace *workspace, double *a, double *b, double *r, double *e)
Int_t fUid
Definition: TSystem.h:140
TXProofMgr(const char *url, Int_t loglevel=-1, const char *alias="")
Create a PROOF manager for the standard (old) environment.
Definition: TXProofMgr.cxx:101
void RemoteTouch()
Remote touch functionality: contact the server to proof our vitality.
Definition: TXSocket.cxx:1347
virtual TFileHandler * RemoveFileHandler(TFileHandler *fh)
Remove a file handler from the list of file handlers.
Definition: TSystem.cxx:572
void SetProof(TProof *p)
Definition: TProofMgr.h:179
const char * GetHostFQDN() const
Return fully qualified domain name of url host.
Definition: TUrl.cxx:469
Bool_t R_ISREG(Int_t mode)
Definition: TSystem.h:119
Int_t fOpt
Definition: TXSocket.h:55
const char * GetUrl(Bool_t withDeflt=kFALSE) const
Return full URL.
Definition: TUrl.cxx:387
virtual TObject * FindObject(const char *name) const
Delete a TObjLink object.
Definition: TList.cxx:574
static Int_t GetErrno()
Static function returning system error number.
Definition: TSystem.cxx:268
Int_t fMode
Definition: TSystem.h:128
Int_t SendMsgToUsers(const char *msg, const char *usr=0)
Send a message to connected users.
Definition: TXProofMgr.cxx:780
void SetRemoteId(Int_t id)
Definition: TProofMgr.h:180
TProofLog * GetSessionLogs(Int_t ridx=0, const char *stag=0, const char *pattern="-v \ SvcMsg\, Bool_t rescan=kFALSE)
Get logs or log tails from last session associated with this manager instance.
Definition: TXProofMgr.cxx:592
Bool_t MatchUrl(const char *url)
Checks if &#39;url&#39; refers to the same &#39;user:port&#39; entity as the URL in memory.
Definition: TXProofMgr.cxx:308
const char * GetHost() const
Definition: TUrl.h:70
virtual Bool_t Notify()
Notify when signal occurs.
static TXProofMgrInit gxproofmgr_init
Definition: TXProofMgr.cxx:96
#define SafeDelete(p)
Definition: RConfig.h:509
Int_t Reset(Bool_t hard=kFALSE, const char *usr=0)
Send a cleanup request for the sessions associated with the current user.
Definition: TXProofMgr.cxx:557
TProofMgr * GetTXProofMgr(const char *url, Int_t l, const char *al)
Definition: TXProofMgr.cxx:88
virtual int WriteRaw(const void *buf, int len, XrdClientPhyConnection *p=0)
Low level write call.
void Stop()
Stop the stopwatch.
Definition: TStopwatch.cxx:77
Int_t RecvRaw(void *buf, Int_t len, ESendRecvOptions opt=kDefault)
Receive a raw buffer of specified length bytes.
Definition: TXSocket.cxx:1581
This code implements the MD5 message-digest algorithm.
Definition: TMD5.h:44
void Ls(const char *what="~/", const char *how=0, const char *where=0)
Run &#39;ls&#39; on the nodes.
Definition: TXProofMgr.cxx:936
virtual ~TXProofMgr()
Destructor: close the connection.
Definition: TXProofMgr.cxx:159
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Definition: TString.cxx:2231
virtual UserGroup_t * GetUserInfo(Int_t uid)
Returns all user info in the UserGroup_t structure.
Definition: TSystem.cxx:1574
virtual TProofDesc * GetProofDesc(Int_t id)
Get TProofDesc instance corresponding to &#39;id&#39;.
Definition: TProofMgr.cxx:324
TObject & operator=(const TObject &rhs)
TObject assignment operator.
Definition: TObject.h:271
void Continue()
Resume a stopped stopwatch.
Definition: TStopwatch.cxx:93
Bool_t IsServProofd()
Return kTRUE if the remote server is a &#39;proofd&#39;.
Definition: TXSocket.cxx:959
Long64_t Atoll() const
Return long long value of string.
Definition: TString.cxx:2001
Int_t GetRemoteProtocol() const
Definition: TSocket.h:145
Int_t fGid
Definition: TSystem.h:130
void SetManager(TProofMgr *mgr)
Set manager and schedule its destruction after this for clean operations.
Definition: TProof.cxx:1285
EServType fServType
Definition: TProofMgr.h:60
A doubly linked list.
Definition: TList.h:44
const char * GetUser() const
Definition: TUrl.h:68
Bool_t IsValid() const
Definition: TXProofMgr.h:60
const char * GetName() const
Returns name of object.
Definition: TObjString.h:39
const TString & GetString() const
Definition: TObjString.h:47
void ShowROOTVersions()
Display what ROOT versions are available on the cluster.
Definition: TXProofMgr.cxx:731
TSignalHandler * fIntHandler
Definition: TProofMgr.h:64
ROOT::R::TRInterface & r
Definition: Object.C:4
Bool_t fIsLink
Definition: TSystem.h:133
R__EXTERN TSystem * gSystem
Definition: TSystem.h:540
Handler of asynchronous events for XProofD sockets.
Definition: TXHandler.h:28
auto * a
Definition: textangle.C:12
virtual TObject * Remove(TObject *obj)
Remove object from the list.
Definition: TList.cxx:818
High level handler of connections to XProofD.
Definition: TXSocket.h:59
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Definition: TString.h:561
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition: TString.cxx:2343
unsigned int UInt_t
Definition: RtypesCore.h:42
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:880
char * Form(const char *fmt,...)
TSubString Strip(EStripType s=kTrailing, char c=' ') const
Return a substring of self stripped at beginning and/or end.
Definition: TString.cxx:1080
Int_t PutFile(const char *local, const char *remote, const char *opt=0)
Put file &#39;local&#39;to &#39;remote&#39; to the master If opt is "force", the file, if it exists remotely...
virtual const char * GetUrl()
Definition: TProofMgr.h:94
const Int_t kPROOF_Protocol
Definition: TProof.h:120
TObjString * Exec(Int_t action, const char *what, const char *how, const char *where)
Execute &#39;action&#39; (see EAdminExecType in &#39;XProofProtocol.h&#39;) at &#39;where&#39; (default master), with options &#39;how&#39;, on &#39;what&#39;.
Implementation of the functionality provided by TProofMgr in the case of a xproofd-based session...
Definition: TXProofMgr.h:40
Int_t Rm(const char *what, const char *how=0, const char *where=0)
Run &#39;rm&#39; on the nodes.
Definition: TXProofMgr.cxx:990
Bool_t IsIdle() const
Definition: TProof.h:940
void Print(Option_t *opt="") const
Dump the content to the screen.
Definition: TProofMgr.cxx:1098
#define Printf
Definition: TGeoToOCC.h:18
virtual Int_t Reconnect()
Try reconnection after failure.
Definition: TXSocket.cxx:2133
const Bool_t kFALSE
Definition: RtypesCore.h:88
void DisconnectSession(Int_t id, Option_t *opt="")
Disconnect a session.
Definition: TXSocket.cxx:268
UInt_t What() const
Definition: TMessage.h:74
TString & Remove(Ssiz_t pos)
Definition: TString.h:619
long Long_t
Definition: RtypesCore.h:50
int Ssiz_t
Definition: RtypesCore.h:63
TProof * AttachSession(Int_t id, Bool_t gui=kFALSE)
Dummy version provided for completeness.
Definition: TXProofMgr.h:63
TUrl fUrl
Definition: TProofMgr.h:62
TObjArray * Tokenize(const TString &delim) const
This function is used to isolate sequential tokens in a TString.
Definition: TString.cxx:2251
void Close(Option_t *option="")
Close all open slave servers.
Definition: TProof.cxx:1776
#define ClassImp(name)
Definition: Rtypes.h:359
const Int_t kXPROOF_Protocol
Definition: TXProofMgr.h:35
double Double_t
Definition: RtypesCore.h:55
virtual void Remove()
Remove signal handler from system signal handler list.
int type
Definition: TGX11.cxx:120
This class controls a Parallel ROOT Facility, PROOF, cluster.
Definition: TProof.h:316
Bool_t HandleInput(const void *)
Handle asynchronous input on the socket.
Definition: TXProofMgr.cxx:485
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:570
static constexpr double s
#define R__LOCKGUARD(mutex)
Int_t Recv(TMessage *&mess)
Receive a TMessage object.
Definition: TXSocket.cxx:1774
virtual Int_t GetUid(const char *user=0)
Returns the user&#39;s id. If user = 0, returns current user&#39;s id.
Definition: TSystem.cxx:1535
static void SetTXProofMgrHook(TProofMgr_t pmh)
Set hook to TXProofMgr ctor.
Definition: TProofMgr.cxx:618
Int_t GetPort() const
Definition: TUrl.h:81
Bool_t IsNull() const
Definition: TString.h:383
void Find(const char *what="~/", const char *how="-type f", const char *where=0)
Run &#39;find&#39; on the nodes.
Definition: TXProofMgr.cxx:909
TString fMssUrl
Definition: TProofMgr.h:58
Bool_t R_ISDIR(Int_t mode)
Definition: TSystem.h:116
Int_t SetROOTVersion(const char *tag)
Set the default ROOT version to be used.
Definition: TXProofMgr.cxx:757
TProofLogElem * Add(const char *ord, const char *url)
Add new entry to the list of elements.
Definition: TProofLog.cxx:67
Bool_t IsValid() const
Getter for validity status.
Definition: TXSocket.cxx:951
virtual int GetServiceByName(const char *service)
Get port # of internet service.
Definition: TSystem.cxx:2347
virtual void Add(TObject *obj)
Definition: TList.h:87
auto * l
Definition: textangle.C:4
Int_t Init(Int_t loglevel=-1)
Do real initialization: open the connection and set the relevant variables.
Definition: TXProofMgr.cxx:122
TXSocket * fSocket
Definition: TXProofMgr.h:44
TObjString * SendCoordinator(Int_t kind, const char *msg=0, Int_t int2=0, Long64_t l64=0, Int_t int3=0, const char *opt=0)
Send message to intermediate coordinator.
Definition: TXSocket.cxx:1825
Long_t fIno
Definition: TSystem.h:127
#define snprintf
Definition: civetweb.c:822
R__EXTERN Int_t gDebug
Definition: Rtypes.h:86
Int_t Atoi() const
Return integer value of string.
Definition: TString.cxx:1975
void Reset()
Definition: TStopwatch.h:52
Bool_t IsDigit() const
Returns true if all characters in string are digits (0-9) or white spaces, i.e.
Definition: TString.cxx:1817
virtual void AddFileHandler(TFileHandler *fh)
Add a file handler to the list of system file handlers.
Definition: TSystem.cxx:562
static void ResetErrno()
Static function resetting system error number.
Definition: TSystem.cxx:284
Bool_t IsValid() const
Definition: TProof.h:937
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
Definition: TSystem.cxx:1254
void Tail(const char *what, const char *how=0, const char *where=0)
Run &#39;tail&#39; on the nodes.
Long_t fDev
Definition: TSystem.h:126
virtual Int_t GetSize() const
Definition: TCollection.h:180
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition: TNamed.cxx:164
const Bool_t kTRUE
Definition: RtypesCore.h:87
Int_t GetRemoteId() const
Definition: TProofMgr.h:165
void SetStatus(Int_t st)
Definition: TProofMgr.h:177
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:866
Implementation of the PROOF session log handler.
Definition: TProofLog.h:32
Int_t GetXrdProofdVersion() const
Definition: TXSocket.h:161
const char * Data() const
Definition: TString.h:345
Int_t Retrieve(const char *ord="*", TProofLog::ERetrieveOpt opt=TProofLog::kTrailing, const char *fname=0, const char *pattern=0)
Retrieve the content of the log file associated with worker &#39;ord&#39;.
Definition: TProofLog.cxx:87
Stopwatch class.
Definition: TStopwatch.h:28