24#include "XrdNet/XrdNet.hh"
41 XPDLOC(CMGR,
"Client::Client")
55 if (stat(adminpath, &st) != 0) {
56 TRACE(XERR,
"problems stating admin path "<<adminpath<<
"; errno = "<<errno);
82 bool rc = (usr && !strcmp(usr,
User())) ? 1 : 0;
83 if (rc && grp && strlen(grp) > 0)
84 rc = (grp &&
Group() && !strcmp(grp,
Group())) ? 1 : 0;
95 XPDLOC(CMGR,
"Client::GetClientID")
104 int rtime =
fClients[ic]->ResetTime();
131 memcpy((
void *)&sid, (
const void *)&(
p->Request()->header.streamid[0]), 2);
135 TRACE(DBG,
"size = "<<sz<<
", ic = "<<ic);
147 XPDLOC(CMGR,
"Client::ReserveClientID")
152 int sz = 0, newsz = 0;
159 if (cid >= (
int)
fClients.capacity()) {
161 newsz = (cid < newsz) ? newsz : cid + 1;
172 TRACE(DBG,
"cid = "<<cid<<
", size = "<<sz<<
", capacity = "<<newsz);
184 XPDLOC(CMGR,
"Client::GetFreeServObj")
186 int ic = 0, newsz = 0, sz = 0;
219 XPDFORM(msg,
"new capacity = %d, size = %d, ic = %d, xps = %p",
222 XPDFORM(msg,
"size = %d, ic = %d, xps = %p", sz, ic, xps);
236 XPDLOC(CMGR,
"Client::GetServObj")
238 TRACE(DBG,
"id: "<<
id);
241 TRACE(XERR,
"invalid input: id: "<<
id);
245 XrdOucString dmsg, emsg;
247 int siz = 0, cap = 0;
253 TRACE(DBG,
"size = "<<siz<<
"; capacity = "<<cap);
259 emsg =
"instance in use or undefined! protocol error";
265 newsz = (
id < newsz) ? newsz :
id+1;
286 TRACE(DBG,
"size = "<<siz<<
" (capacity = "<<cap<<
"); id = "<<
id);
298 XPDLOC(CMGR,
"Client::GetServer")
300 TRACE(DBG,
"enter: p: " <<
p);
304 std::vector<XrdProofdProofServ *>::iterator ip;
309 if (xps && xps->
SrvPID() ==
p->Pid())
334 XPDLOC(CMGR,
"Client::EraseServer")
336 TRACE(DBG,
"enter: psid: " << psid);
339 std::vector<XrdProofdProofServ *>::iterator ip;
345 if (xps && xps->
Match(psid)) {
358 XPDLOC(CMGR,
"Client::GetTopServers")
363 std::vector<XrdProofdProofServ *>::iterator ip;
368 TRACE(DBG,
"found potentially valid topmaster session: pid "<<xps->
SrvPID());
382 XPDLOC(CMGR,
"Client::ResetClientSlot")
384 TRACE(DBG,
"enter: ic: " << ic);
388 if (ic >= 0 && ic < (
int)
fClients.size()) {
402 XPDLOC(CMGR,
"Client::GetProtocol")
404 TRACE(DBG,
"enter: ic: " << ic);
410 if (ic >= 0 && ic < (
int)
fClients.size()) {
423 XPDLOC(CMGR,
"Client::SetClientID")
425 TRACE(DBG,
"cid: "<< cid <<
", p: " <<
p);
430 if (cid >= 0 && cid < (
int)
fClients.size()) {
436 memcpy((
void *)&sid, (
const void *)&(
p->Request()->header.streamid[0]), 2);
450 XPDLOC(CMGR,
"Client::Broadcast")
453 if (msg && (
len = strlen(msg)) > 0) {
462 if (cid->
P()->
Link()) {
463 TRACE(ALL,
" sending to: "<<cid->
P()->
Link()->ID);
519 XPDLOC(CMGR,
"Client::VerifySession")
521 if (!xps || !(xps->
IsValid())) {
522 TRACE(XERR,
" session undefined or invalid");
528 if (path.length() <= 0) {
529 TRACE(XERR,
"admin path is empty! - protocol error");
536 if (stat(path.c_str(), &st0) != 0) {
537 TRACE(XERR,
"cannot stat admin path: "<<path);
541 if (now >= st0.st_mtime && (now - st0.st_mtime) <= 1)
return 1;
542 TRACE(ALL,
"admin path: "<<path<<
", mtime: "<< st0.st_mtime <<
", now: "<< now);
550 TRACE(XERR,
"could not send verify request to proofsrv");
559 if (stat(path.c_str(), &st1) == 0) {
560 if (st1.st_mtime > st0.st_mtime) {
565 TRACE(HDBG,
"waiting "<<ns<<
" secs for session "<<pid<<
566 " to touch the admin path");
568 XPDFORM(notmsg,
"verifying existing sessions, %d seconds ...", ns);
569 r->Send(kXR_attn,
kXPD_srvmsg, 0, (
char *) notmsg.c_str(), notmsg.length());
588 XPDLOC(CMGR,
"Client::SkipSessionsCheck")
591 std::vector<XrdProofdProofServ *>::iterator ip;
596 if (active) active->push_back(xps);
599 if (emsg.length() <= 0)
600 emsg =
"ignoring (apparently) non-responding session(s): ";
605 TRACE(ALL,
"session "<<xps->
SrvPID()<<
" does not react: dead?");
610 TRACE(HDBG,
"found: " << active->size() <<
" sessions");
622 XrdOucString out, buf;
625 std::list<XrdProofdProofServ *> active;
630 out += (
int) active.size();
631 std::list<XrdProofdProofServ *>::iterator ia;
632 for (ia = active.begin(); ia != active.end(); ++ia) {
633 if ((xps = *ia) && xps->
IsValid()) {
650 XPDLOC(CMGR,
"Client::TerminateSessions")
668 XrdOucString tag =
"-";
677 buf.erase(0, buf.rfind(
'/') + 1);
678 TRACE(DBG,
"posting kSessionRemoval with: '"<<buf<<
"'");
680 TRACE(XERR,
"problem posting the pipe; errno: "<<-rc);
698 std::vector<XrdProofdProofServ *>::iterator ip;
701 if (*ip) (*ip)->Reset();
#define TRACE(Flag, Args)
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 id
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
R__EXTERN C unsigned int sleep(unsigned int seconds)
#define kXPD_ClientMaster
#define XrdSysMutexHelper
XrdProofdResponse * R() const
void SetP(XrdProofdProtocol *p)
XrdProofdProtocol * P() const
void SetSid(unsigned short sid)
static int GetUserInfo(const char *usr, XrdProofUI &ui)
Get information about user 'usr' in a thread safe way.
static int AssertDir(const char *path, XrdProofUI ui, bool changeown)
Make sure that 'path' exists and is owned by the entity described by 'ui'.
static int VerifyProcessByID(int pid, const char *pname="proofserv")
Check if a process named 'pname' and process 'pid' is still in the process table.
std::vector< XrdClientID * > fClients
virtual ~XrdProofdClient()
Destructor.
void TerminateSessions(int srvtype, XrdProofdProofServ *ref, const char *msg, XrdProofdPipe *pipe, bool changeown)
Terminate client sessions; IDs of signalled processes are added to sigpid.
int ReserveClientID(int cid)
Reserve a client ID.
int GetTopServers()
Return the number of valid proofserv topmaster sessions in the list.
XrdProofdProofServ * GetFreeServObj()
Get next free server ID.
int GetClientID(XrdProofdProtocol *p)
Get next free client ID.
XrdOucString ExportSessions(XrdOucString &emsg, XrdProofdResponse *r=0)
Return a string describing the existing sessions.
const char * Group() const
const char * User() const
int ResetClientSlot(int ic)
Reset slot at 'ic'.
void Broadcast(const char *msg)
Broadcast message 'msg' to the connected clients.
bool VerifySession(XrdProofdProofServ *xps, XrdProofdResponse *r=0)
Quick verification of session 'xps' to avoid attaching clients to non responding sessions.
void ResetSessions()
Reset this instance.
XrdProofdProofServ * GetServer(int psid)
Get from the vector server instance with ID psid.
std::vector< XrdProofdProofServ * > fProofServs
int Touch(bool reset=0)
Send a touch the connected clients: this will remotely touch the associated TSocket instance and sche...
void EraseServer(int psid)
Erase server with id psid from the list.
XrdProofdProofServ * GetServObj(int id)
Get server at 'id'. If needed, increase the vector size.
int SetClientID(int cid, XrdProofdProtocol *p)
Set slot cid to instance 'p'.
XrdProofdSandbox fSandbox
XrdProofdProtocol * GetProtocol(int ic)
Return protocol attached to client slot at 'ic'.
bool Match(const char *usr, const char *grp=0)
return TRUE if this instance matches 'id' (and 'grp', if defined)
void SkipSessionsCheck(std::list< XrdProofdProofServ * > *active, XrdOucString &emsg, XrdProofdResponse *r=0)
Skip the next sessions status check.
XrdProofdClient(XrdProofUI ui, bool master, bool changeown, XrdSysError *edest, const char *tmp, int rtime)
Constructor.
int Post(int type, const char *msg)
Post message on the pipe.
void SetValid(bool valid=1)
const char * AdminPath() const
void ExportBuf(XrdOucString &buf)
Fill buf with relevant info about this session.
int VerifyProofServ(bool fw)
Check if the associated proofserv process is alive.
int TerminateProofServ(bool changeown)
Terminate the associated process.
bool Match(short int id) const
void Reset()
Reset this instance.
short int ProofProtocol() const
int Send(void)
Auxilliary Send method.
int GuessTag(XrdOucString &tag, int ridx=1)
Guess session tag completing 'tag' (typically "-<pid>") by scanning the active session file or the se...
int RemoveSession(const char *tag)
Move record for tag from the active sessions file to the old sessions file (<SandBox>/....
int changeown(const std::string &path, uid_t u, gid_t g)
Change the ownership of 'path' to the entity described by {u,g}.