24 #include "XrdNet/XrdNet.hh" 39 : fSandbox(ui, master, changeown)
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")
102 for (ic = 0; ic < (int)
fClients.size() ; ic++) {
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;
193 for (ic = 0; ic < (int)
fProofServs.size() ; ic++) {
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;
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) {
459 for (ic = 0; ic < (int)
fClients.size(); ic++) {
462 if (cid->
P()->
Link()) {
463 TRACE(ALL,
" sending to: "<<cid->
P()->
Link()->ID);
497 for (ic = 0; ic < (int)
fClients.size(); ic++) {
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")
655 for (is = 0; is < (int)
fProofServs.size(); is++) {
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();
void ExportBuf(XrdOucString &buf)
Fill buf with relevant info about this session.
int GetClientID(XrdProofdProtocol *p)
Get next free client ID.
virtual ~XrdProofdClient()
Destructor.
int ResetClientSlot(int ic)
Reset slot at 'ic'.
int ReserveClientID(int cid)
Reserve a client ID.
static int GetUserInfo(const char *usr, XrdProofUI &ui)
Get information about user 'usr' in a thread safe way.
const char * Group() const
#define TRACE(Flag, Args)
void SetSid(unsigned short sid)
XrdProofdProofServ * GetServObj(int id)
Get server at 'id'. If needed, increase the vector size.
void Reset()
Reset this instance.
bool Match(short int id) const
#define kXPD_ClientMaster
short int ProofProtocol() const
XrdProofdProtocol * P() const
struct ClientRequestHdr header
std::vector< XrdClientID * > fClients
const char * User() const
XrdOucString ExportSessions(XrdOucString &emsg, XrdProofdResponse *r=0)
Return a string describing the existing sessions.
bool Match(const char *usr, const char *grp=0)
return TRUE if this instance matches 'id' (and 'grp', if defined)
void Broadcast(const char *msg)
Broadcast message 'msg' to the connected clients.
XrdProofdClient(XrdProofUI ui, bool master, bool changeown, XrdSysError *edest, const char *tmp, int rtime)
Constructor.
int changeown(const std::string &path, uid_t u, gid_t g)
Change the ownership of 'path' to the entity described by {u,g}.
void SetP(XrdProofdProtocol *p)
#define XrdSysMutexHelper
bool VerifySession(XrdProofdProofServ *xps, XrdProofdResponse *r=0)
Quick verification of session 'xps' to avoid attaching clients to non responding sessions.
int TerminateProofServ(bool changeown)
Terminate the associated process.
int GuessTag(XrdOucString &tag, int ridx=1)
Guess session tag completing 'tag' (typically "-<pid>") by scanning the active session file or the se...
void Reset(Detail::TBranchProxy *x)
int RemoveSession(const char *tag)
Move record for tag from the active sessions file to the old sessions file (<SandBox>/.sessions).
const char * AdminPath() const
int Touch(bool reset=0)
Send a touch the connected clients: this will remotely touch the associated TSocket instance and sche...
static int AssertDir(const char *path, XrdProofUI ui, bool changeown)
Make sure that 'path' exists and is owned by the entity described by 'ui'.
void TerminateSessions(int srvtype, XrdProofdProofServ *ref, const char *msg, XrdProofdPipe *pipe, bool changeown)
Terminate client sessions; IDs of signalled processes are added to sigpid.
XrdProofdSandbox fSandbox
void SetValid(bool valid=1)
int GetTopServers()
Return the number of valid proofserv topmaster sessions in the list.
R__EXTERN C unsigned int sleep(unsigned int seconds)
XrdProofdProtocol * GetProtocol(int ic)
Return protocol attached to client slot at 'ic'.
void EraseServer(int psid)
Erase server with id psid from the list.
void SkipSessionsCheck(std::list< XrdProofdProofServ *> *active, XrdOucString &emsg, XrdProofdResponse *r=0)
Skip the next sessions status check.
int Post(int type, const char *msg)
Post message on the pipe.
static int VerifyProcessByID(int pid, const char *pname="proofserv")
Check if a process named 'pname' and process 'pid' is still in the process table. ...
XrdProofdProofServ * GetServer(int psid)
Get from the vector server instance with ID psid.
std::vector< XrdProofdProofServ * > fProofServs
int VerifyProofServ(bool fw)
Check if the associated proofserv process is alive.
XrdProofdProofServ * GetFreeServObj()
Get next free server ID.
int Send(void)
Auxilliary Send method.
XrdProofdResponse * R() const
XPClientRequest * Request() const
void ResetSessions()
Reset this instance.
int SetClientID(int cid, XrdProofdProtocol *p)
Set slot cid to instance 'p'.