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