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