23 #include "XrdOuc/XrdOucStream.hh"
39 #define XPD_MAXLEN 1024
49 static const char *msgtypes[] = {
"Undef",
50 "QuerySessions",
"SessionTag",
"SessionAlias",
"GetWorkers",
"QueryWorkers",
51 "CleanupSessions",
"QueryLogPaths",
"ReadBuffer",
"QueryROOTVersions",
52 "ROOTVersion",
"GroupProperties",
"SendMsgToUser",
"ReleaseWorker",
53 "Exec",
"GetFile",
"PutFile",
"CpFile",
"QueryMssUrl"};
55 if (type < 1000 || type >=
kUndef) {
70 static const char *reqtypes[] = {
"Undef",
71 "XP_login",
"XP_auth",
"XP_create",
"XP_destroy",
"XP_attach",
"XP_detach",
72 "XP_3107",
"XP_3108",
"XP_3109",
"XP_3110",
73 "XP_urgent",
"XP_sendmsg",
"XP_admin",
"XP_interrupt",
"XP_ping",
74 "XP_cleanup",
"XP_readbuf",
"XP_touch",
"XP_ctrlc",
"XR_direct" };
98 if (!p || strlen(p) <= 0 || p[0] ==
'/')
106 XrdOucString env(&p[1]);
107 int isl = env.find(
'/');
109 char *
p1 = (isl > 0) ? (
char *)(p + isl + 2) : 0;
110 if (getenv(env.c_str())) {
111 int lenv = strlen(getenv(env.c_str()));
112 int lp1 = p1 ? strlen(p1) : 0;
113 po = (
char *)
malloc(lp1 + lenv + 2);
115 memcpy(po, getenv(env.c_str()), lenv);
117 memcpy(po+lenv+1, p1, lp1);
120 po[lp1 + lenv + 1] = 0;
131 int lpwd = strlen(getenv(
"PWD"));
133 po = (
char *)
malloc(lp + lpwd + 2);
135 memcpy(po, getenv(
"PWD"), lpwd);
136 memcpy(po+lpwd+1, p, lp);
149 char *pd = strchr(pu,
'/');
154 if (strlen(pu) > 0) {
161 int lpd = strlen(pd);
162 po = (
char *)
malloc(lpd + ldir + 2);
164 memcpy(po, ui.
fHomeDir.c_str(), ldir);
165 memcpy(po+ldir+1, pd, lpd);
167 po[lpd + ldir + 1] = 0;
191 char *po = strdup((
char *)p.c_str());
204 while ((*p < 48 || *p > 57) && (*p) !=
'\0')
211 while (*(p+j) >= 48 && *(p+j) <= 57)
216 return strtol(p, 0, 10);
226 if (!grp || strlen(grp) <= 0)
231 struct group *pgr = 0;
233 #if defined(__sun) && !defined(__GNUC__)
234 pgr = getgrnam_r(grp, &gr, buf,
sizeof(buf));
236 getgrnam_r(grp, &gr, buf,
sizeof(buf), &pgr);
248 return ((
int) -errno);
265 struct group *pgr = 0;
267 #if defined(__sun) && !defined(__GNUC__)
268 pgr = getgrgid_r((gid_t)gid, &gr, buf,
sizeof(buf));
270 getgrgid_r((gid_t)gid, &gr, buf,
sizeof(buf), &pgr);
282 return ((
int) -errno);
294 if (!usr || strlen(usr) <= 0)
301 #if defined(__sun) && !defined(__GNUC__)
302 ppw = getpwnam_r(usr, &pw, buf,
sizeof(buf));
304 getpwnam_r(usr, &pw, buf,
sizeof(buf), &ppw);
318 return ((
int) -errno);
337 #if defined(__sun) && !defined(__GNUC__)
338 ppw = getpwuid_r((uid_t)uid, &pw, buf,
sizeof(buf));
340 getpwuid_r((uid_t)uid, &pw, buf,
sizeof(buf), &ppw);
354 return ((
int) -errno);
368 const char *pw = (
const char *)buf;
370 int nw = 0, written = 0;
372 if ((nw =
write(fd, pw + written, lw)) < 0) {
373 if (errno == EINTR) {
394 XPDLOC(AUX,
"Aux::LogEmsgToFile")
396 if (flog && strlen(flog)) {
398 int logfd =
open(flog, O_WRONLY|O_APPEND, 0644);
400 fcntl(logfd, F_SETFD, FD_CLOEXEC);
405 if (emsg && strlen(emsg) > 0) error.Emsg(
"-E", pfx, emsg);
407 if (fsync(logfd) != 0)
408 TRACE(XERR,
"problem syncing file "<<flog<<
" - errno: "<<errno);
410 if (
close(logfd) != 0)
411 TRACE(XERR,
"problem closing file "<<flog<<
" - errno: "<<errno);
413 TRACE(XERR,
"file "<<flog<<
" could not be opened - errno: "<<errno);
416 TRACE(XERR,
"file path undefined!");
430 XPDLOC(AUX,
"Aux::AssertDir")
434 if (!path || strlen(path) <= 0)
438 TRACE(XERR,
"could not get privileges to change ownership");
442 if (mkdir(path, 0755) != 0 && (errno != EEXIST)) {
443 TRACE(XERR,
"unable to create dir: "<<path<<
" (errno: "<<errno<<
")");
449 if (chown(path, ui.
fUid, ui.
fGid) == -1) {
450 TRACE(XERR,
"cannot set user ownership on path (errno: "<<errno<<
")");
467 XPDLOC(AUX,
"Aux::AssertBaseDir")
471 if (!path || strlen(path) <= 0)
474 XrdOucString base(path);
475 if (base.endswith(
"/")) base.erasefromend(1);
476 int isl = base.rfind(
'/');
477 if (isl != 0) base.erase(isl);
478 TRACE(DBG,
"base: " <<base);
481 if (stat(base.c_str(), &st) != 0) {
483 TRACE(XERR,
"unable to stat base path: "<<base<<
" (errno: "<<errno<<
")");
488 if (ui.
fUid != (
int) st.st_uid) {
489 unsigned pa = (st.st_mode & S_IRWXG);
490 if (ui.
fGid != (
int) st.st_gid)
491 pa |= (st.st_mode & S_IRWXO);
495 TRACE(XERR,
"effective user has not full permissions on base path: "<<base);
511 XPDLOC(AUX,
"Aux::ChangeOwn")
515 if (!path || strlen(path) <= 0)
517 DIR *dir = opendir(path);
520 XrdOucString proot(path);
521 if (!proot.endswith(
'/')) proot +=
"/";
523 struct dirent *ent = 0;
524 while ((ent = readdir(dir))) {
525 if (ent->d_name[0] ==
'.' || !strcmp(ent->d_name,
".."))
continue;
526 XrdOucString fn(proot);
531 TRACE(XERR,
"problems changing recursively ownership of: "<<fn);
541 if (errno != 0 && (errno != ENOTDIR)) {
542 TRACE(XERR,
"cannot open "<<path<<
"- errno: "<< errno);
548 TRACE(XERR,
"could not get privileges to change ownership");
552 if (chown(path, ui.
fUid, ui.
fGid) == -1) {
553 TRACE(XERR,
"cannot set user ownership on path (errno: "<<errno<<
")");
568 XPDLOC(AUX,
"Aux::ChangeMod")
570 TRACE(HDBG,
"path: "<<path);
572 if (!path || strlen(path) <= 0)
576 if (stat(path,&st) != 0) {
578 TRACE(XERR,
"unable to stat path: "<<path<<
" (errno: "<<errno<<
")");
586 TRACE(XERR,
"could not get privileges to change ownership");
590 if (chmod(path, mode) == -1) {
591 TRACE(XERR,
"cannot change permissions on path (errno: "<<errno<<
")");
597 if (S_ISDIR(st.st_mode)) {
599 DIR *dir = opendir(path);
601 TRACE(XERR,
"cannot open "<<path<<
"- errno: "<< errno);
604 XrdOucString proot(path);
605 if (!proot.endswith(
'/')) proot +=
"/";
607 struct dirent *ent = 0;
608 while ((ent = readdir(dir))) {
609 if (ent->d_name[0] ==
'.' || !strcmp(ent->d_name,
".."))
continue;
610 XrdOucString fn(proot);
614 if (stat(fn.c_str(),&xst) == 0) {
616 TRACE(HDBG,
"getting {"<<xst.st_uid<<
", "<< xst.st_gid<<
"} identity");
619 TRACE(XERR,
"could not get privileges to change ownership");
624 if (chmod(fn.c_str(), mode) == -1) {
625 TRACE(XERR,
"cannot change permissions on path (errno: "<<errno<<
")");
631 if (S_ISDIR(xst.st_mode)) {
633 TRACE(XERR,
"problems changing recursively permissions of: "<<fn);
639 TRACE(XERR,
"unable to stat dir: "<<fn<<
" (errno: "<<errno<<
")");
657 XPDLOC(AUX,
"Aux::ChangeToDir")
659 TRACE(DBG,
"changing to " << ((dir) ? dir :
"**undef***"));
661 if (!dir || strlen(dir) <= 0)
664 if (changeown && ((
int) geteuid() != ui.
fUid || (
int) getegid() != ui.
fGid)) {
668 TRACE(XERR, changeown <<
": could not get privileges; {uid,gid} req: {"<< ui.
fUid <<
","<<ui.
fGid<<
669 "}, {euid,egid}: {" << geteuid() <<
","<<getegid()<<
"}, {uid,gid}: {"<<getuid()<<
","<<getgid() <<
"}; errno: "<<errno);
672 if (chdir(dir) == -1) {
673 TRACE(XERR, changeown <<
": can't change directory to '"<< dir<<
"'; {ui.fUid,ui.fGid}: {"<< ui.
fUid <<
","<<ui.
fGid<<
674 "}, {euid,egid}: {" << geteuid() <<
","<<getegid()<<
"}, {uid,gid}: {"<<getuid()<<
","<<getgid() <<
"}; errno: "<<errno);
678 if (chdir(dir) == -1) {
679 TRACE(XERR, changeown <<
": can't change directory to "<< dir <<
680 ", euid: " << geteuid() <<
", uid:"<<getuid()<<
"; errno: "<<errno);
695 XPDLOC(AUX,
"Aux::SymLink")
697 TRACE(DBG, path<<
" -> "<<link);
699 if (!path || strlen(path) <= 0 || !link || strlen(link) <= 0)
703 if (unlink(link) != 0 && errno != ENOENT) {
704 TRACE(XERR,
"problems unlinking existing symlink "<< link<<
705 " (errno: "<<errno<<
")");
708 if (symlink(path, link) != 0) {
709 TRACE(XERR,
"problems creating symlink " << link<<
710 " (errno: "<<errno<<
")");
728 char *val = s ? s->GetWord() : 0;
729 if (!val || strncmp(val,
"if",2)) {
742 TRACE(ALL,
">>> Warning: 'if' conditions at the end of the directive are deprecated ");
743 TRACE(ALL,
">>> Please use standard Scalla/Xrootd 'if-else-fi' constructs");
744 TRACE(ALL,
">>> (see http://xrootd.slac.stanford.edu/doc/xrd_config/xrd_config.htm)");
747 TRACE(DBG,
"Aux::CheckIf: <pattern>: " <<val);
750 XrdOucString
h(host);
751 return h.matches((
const char *)val);
760 XPDLOC(AUX,
"Aux::GetNumCPUs")
762 static int ncpu = -1;
773 XrdOucString fcpu(
"/proc/cpuinfo");
774 FILE *
fc = fopen(fcpu.c_str(),
"r");
776 if (errno == ENOENT) {
777 TRACE(XERR,
"/proc/cpuinfo missing!!! Something very bad going on");
779 XPDFORM(emsg,
"cannot open %s; errno: %d", fcpu.c_str(), errno);
785 char line[2048] = { 0 };
786 while (fgets(line,
sizeof(line), fc)) {
787 if (!strncmp(line,
"processor", strlen(
"processor")))
796 FILE *fp = popen(
"psrinfo",
"r");
798 char line[2048] = { 0 };
799 while (fgets(line,
sizeof(line), fp))
804 #elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
807 FILE *fp = popen(
"sysctl -n hw.ncpu",
"r");
809 char line[2048] = { 0 };
810 while (fgets(line,
sizeof(line), fp))
816 TRACE(DBG,
"# of cores found: "<<ncpu);
819 return (ncpu <= 0) ? (int)(-1) : ncpu ;
822 #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
835 int XrdProofdAux::GetMacProcList(kinfo_proc **plist,
int &nproc)
837 XPDLOC(AUX,
"Aux::GetMacProcList")
842 static const
int name[] = {CTL_KERN, KERN_PROC, KERN_PROC_ALL, 0};
850 if (!plist || (*plist))
868 if ((rc = sysctl((
int *)
name, (
sizeof(
name)/
sizeof(*
name)) - 1,
869 0, &len, 0, 0)) == -1) {
876 res = (kinfo_proc *)
malloc(len);
884 if ((rc = sysctl((
int *)
name, (
sizeof(
name)/
sizeof(*
name)) - 1,
885 res, &len, 0, 0)) == -1) {
890 }
else if (rc == ENOMEM) {
897 }
while (rc == 0 && !done);
900 if (rc != 0 && !res) {
906 nproc = len /
sizeof(kinfo_proc);
921 XPDLOC(AUX,
"Aux::GetProcesses")
926 if (!pn || strlen(pn) <= 0 || !pmap) {
927 TRACE(XERR,
"invalid inputs");
930 TRACE(DBG,
"process name: "<<pn);
934 #if defined(linux) || defined(__sun)
936 DIR *dir = opendir(
"/proc");
938 emsg =
"cannot open /proc - errno: ";
940 TRACE(DBG, emsg.c_str());
944 struct dirent *ent = 0;
945 while ((ent = readdir(dir))) {
946 if (
DIGIT(ent->d_name[0])) {
947 XrdOucString fn(
"/proc/", 256);
952 FILE *ffn = fopen(fn.c_str(),
"r");
954 emsg =
"cannot open file ";
955 emsg += fn; emsg +=
" - errno: "; emsg += errno;
962 char line[2048] = { 0 };
963 while (fgets(line,
sizeof(line), ffn)) {
965 if (strstr(line,
"Name:")) {
966 if (strstr(line, pn)) {
976 fn.replace(
"/status",
"/cmdline");
978 if (!(ffn = fopen(fn.c_str(),
"r"))) {
979 emsg =
"cannot open file ";
980 emsg += fn; emsg +=
" - errno: "; emsg += errno;
988 int pos = 0, ltot = 0, nr = 1;
991 while ((nr =
read(fileno(ffn), p + pos, 1)) == -1 && errno == EINTR) {
1000 }
else if (nr > 0) {
1001 if (*p == 0) *p =
' ';
1009 pid = strtol(ent->d_name, 0, 10);
1010 pmap->insert(std::make_pair(pid, cmd));
1015 #elif defined(__sun)
1018 int ffd =
open(fn.c_str(), O_RDONLY);
1020 emsg =
"cannot open file ";
1021 emsg += fn; emsg +=
" - errno: "; emsg += errno;
1027 if (
read(ffd, &psi,
sizeof(psinfo_t)) !=
sizeof(psinfo_t)) {
1028 emsg =
"cannot read ";
1029 emsg += fn; emsg +=
": errno: "; emsg += errno;
1035 if (strstr(psi.pr_fname, pn)) {
1037 XrdOucString cmd(psi.pr_fname);
1038 if (cmd.length() > 0) cmd +=
" ";
1039 cmd += psi.pr_psargs;
1041 int pid = strtol(ent->d_name, 0, 10);
1042 pmap->insert(std::make_pair(pid, cmd));
1053 #elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
1058 if ((ern = XrdProofdAux::GetMacProcList(&pl, np)) != 0) {
1059 emsg =
"cannot get the process list: errno: ";
1068 if (strstr(pl[ii].kp_proc.p_comm, pn)) {
1070 pmap->insert(std::make_pair(pl[ii].kp_proc.p_pid, XrdOucString(pl[ii].kp_proc.p_comm)));
1081 XrdOucString cmd =
"ps ax -ww | grep proofserv 2>/dev/null";
1084 XrdOucString pids =
":";
1085 FILE *fp = popen(cmd.c_str(),
"r");
1087 char line[2048] = { 0 };
1088 while (fgets(line,
sizeof(line), fp)) {
1090 pmap->insert(std::make_pair(pid, XrdOucString(line)));
1113 FILE *fid = fopen(path,
"r");
1116 if (fgets(line,
sizeof(line), fid)) {
1117 if (line[strlen(line)-1] ==
'\n') line[strlen(line)-1] = 0;
1121 }
else if (errno != ENOENT) {
1122 XPDFORM(emsg,
"GetIDFromPath: error reading id from: %s (errno: %d)",
1135 if (s && strlen(s) > 0) {
1136 XrdOucString tks(tokens), tok;
1138 while ((from = tks.tokenize(tok, from,
',')) != -1)
1139 if (strstr(s, tok.c_str()))
return 1;
1153 XPDLOC(AUX,
"Aux::VerifyProcessByID")
1157 TRACE(DBG,
"pid: "<<pid);
1161 TRACE(XERR,
"invalid pid");
1168 const char *pn = (pname && strlen(pname) > 0) ? pname :
"proofserv";
1172 XrdOucString fn(
"/proc/");
1175 FILE *ffn = fopen(fn.c_str(),
"r");
1177 if (errno == ENOENT) {
1178 TRACE(DBG,
"process does not exists anymore");
1181 XPDFORM(emsg,
"cannot open %s; errno: %d", fn.c_str(), errno);
1187 char line[2048] = { 0 };
1188 if (fgets(line,
sizeof(line), ffn)) {
1193 XPDFORM(emsg,
"cannot read %s; errno: %d", fn.c_str(), errno);
1201 #elif defined(__sun)
1204 XrdOucString fn(
"/proc/");
1207 int ffd =
open(fn.c_str(), O_RDONLY);
1209 if (errno == ENOENT) {
1210 TRACE(DBG,
"VerifyProcessByID: process does not exists anymore");
1213 XPDFORM(emsg,
"cannot open %s; errno: %d", fn.c_str(), errno);
1221 if (
read(ffd, &psi,
sizeof(psinfo_t)) !=
sizeof(psinfo_t)) {
1222 XPDFORM(emsg,
"cannot read %s; errno: %d", fn.c_str(), errno);
1236 #elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
1242 if ((ern = XrdProofdAux::GetMacProcList(&pl, np)) != 0) {
1243 XPDFORM(emsg,
"cannot get the process list: errno: %d", ern);
1250 if (pl[np].kp_proc.p_pid == pid &&
1261 XrdOucString cmd =
"ps ax | grep proofserv 2>/dev/null";
1262 if (pname && strlen(pname))
1263 cmd.replace(
"proofserv", pname);
1264 FILE *fp = popen(cmd.c_str(),
"r");
1266 char line[2048] = { 0 };
1267 while (fgets(line,
sizeof(line), fp)) {
1293 XPDLOC(AUX,
"Aux::KillProcess")
1295 TRACE(DBG,
"pid: "<<pid<<
", forcekill: "<< forcekill);
1302 TRACE(XERR,
"could not get privileges");
1308 if (kill(pid, SIGKILL) != 0) {
1309 if (errno != ESRCH) {
1310 XPDFORM(msg,
"kill(pid,SIGKILL) failed for process %d; errno: %d", pid, errno);
1318 if (kill(pid, SIGTERM) != 0) {
1319 if (errno != ESRCH) {
1320 XPDFORM(msg,
"kill(pid,SIGTERM) failed for process %d; errno: %d", pid, errno);
1329 TRACE(DBG,
"process ID "<<pid<<
" not found in the process table");
1346 XPDLOC(AUX,
"Aux::RmDir")
1353 DIR *dir = opendir(path);
1355 TRACE(XERR,
"cannot open dir "<<path<<
" ; error: "<<errno);
1362 struct dirent *ent = 0;
1363 while ((ent = (
struct dirent *)readdir(dir))) {
1365 if (!strcmp(ent->d_name,
".") || !strcmp(ent->d_name,
".."))
continue;
1367 XPDFORM(entry,
"%s/%s", path, ent->d_name);
1368 if (stat(entry.c_str(), &st) != 0) {
1369 TRACE(XERR,
"cannot stat entry "<<entry<<
" ; error: "<<errno);
1374 if (S_ISDIR(st.st_mode)) {
1377 TRACE(XERR,
"problems removing"<<entry<<
" ; error: "<<-rc);
1382 if (unlink(entry.c_str()) != 0) {
1384 TRACE(XERR,
"problems removing"<<entry<<
" ; error: "<<-rc);
1393 if (!rc && rmdir(path) != 0) {
1395 TRACE(XERR,
"problems removing"<<path<<
" ; error: "<<-rc);
1409 XPDLOC(AUX,
"Aux::MvDir")
1413 TRACE(DBG,
"oldpath "<<oldpath<<
", newpath: "<<newpath);
1416 DIR *dir = opendir(oldpath);
1418 TRACE(XERR,
"cannot open dir "<<oldpath<<
" ; error: "<<errno);
1424 if (stat(newpath, &st) != 0 || !S_ISDIR(st.st_mode)) {
1425 TRACE(XERR,
"destination dir "<<newpath<<
1426 " does not exist or is not a directory; errno: "<<errno);
1432 XrdOucString srcentry, dstentry;
1433 struct dirent *ent = 0;
1434 while ((ent = (
struct dirent *)readdir(dir))) {
1436 if (!strcmp(ent->d_name,
".") || !strcmp(ent->d_name,
".."))
continue;
1438 XPDFORM(srcentry,
"%s/%s", oldpath, ent->d_name);
1439 if (stat(srcentry.c_str(), &st) != 0) {
1440 TRACE(XERR,
"cannot stat entry "<<srcentry<<
" ; error: "<<errno);
1445 XPDFORM(dstentry,
"%s/%s", newpath, ent->d_name);
1447 if (S_ISDIR(st.st_mode)) {
1448 mode_t srcmode = st.st_mode;
1450 if (mkdir(dstentry.c_str(), srcmode) != 0 && (errno != EEXIST)) {
1451 TRACE(XERR,
"cannot create entry "<<dstentry<<
" ; error: "<<errno);
1456 TRACE(XERR,
"problems moving "<<srcentry<<
" to "<<dstentry<<
"; error: "<<-rc);
1460 TRACE(XERR,
"problems removing "<<srcentry<<
"; error: "<<-rc);
1465 if (rename(srcentry.c_str(), dstentry.c_str()) != 0) {
1467 TRACE(XERR,
"problems moving "<<srcentry<<
" to "<<dstentry<<
"; error: "<<-rc);
1487 if (utime(path, 0) != 0)
1489 }
else if (opt <= 2) {
1491 if (stat(path, &st) != 0)
1493 struct utimbuf ut = {0,0};
1495 ut.actime = time(0);
1496 ut.modtime = st.st_mtime;
1497 }
else if (opt == 2) {
1498 ut.modtime = time(0);
1499 ut.actime = st.st_atime;
1501 if (utime(path, &ut) != 0)
1516 XPDLOC(AUX,
"Aux::ReadMsg")
1523 if (
read(fd, &len,
sizeof(len)) !=
sizeof(len))
1525 TRACE(HDBG,fd<<
": len: "<<len);
1532 while ((nr =
read(fd, buf, wanted)) < 0 &&
1542 len = (nr >= len) ? 0 : len - nr;
1543 }
while (nr > 0 && len > 0);
1545 TRACE(HDBG,fd<<
": buf: "<<buf);
1551 TRACE(XERR,
"pipe descriptor undefined: "<<fd);
1562 XrdOucString &before, XrdOucString &after)
1564 XPDLOC(AUX,
"ParsePidPath")
1569 if (path && strlen(path)) {
1572 XrdOucString spid, s(path);
1574 while ((from = s.tokenize(spid, from,
'.')) != -1) {
1575 if (spid.length() > 0) {
1576 if (spid.isdigit()) {
1578 pid = (int) spid.atoi();
1584 if (nopid && pid > 0) {
1587 if (before.length() > 0) before +=
".";
1590 if (after.length() > 0) after +=
".";
1595 if (pid == 0 && before.length() == 0) {
1601 TRACE(HDBG,
"path: "<<(path ? path :
"<nul>")<<
" --> before: '"<<before
1602 <<
"', pid: "<<pid<<
", after: '"<<after<<
"'");
1614 XrdOucString rest, after;
1617 if (pid >= 0 && rest.length() > 0) {
1621 if ((ip = rest.rfind(
'.')) != STR_NPOS) {
1625 grp.erase(0, ip + 1);
1641 if (!d || !(d->
fVal))
1653 XPDLOC(AUX,
"DoDirectiveInt")
1655 if (!d || !(d->
fVal) || !val)
1659 if (rcf && !d->
fRcf)
1664 if (d->
fHost && cfg)
1668 long int v = strtol(val,0,10);
1669 *((
int *)d->
fVal) =
v;
1681 XPDLOC(AUX,
"DoDirectiveString")
1683 if (!d || !(d->
fVal) || !val)
1687 if (rcf && !d->
fRcf)
1692 if (d->
fHost && cfg)
1696 *((XrdOucString *)d->
fVal) = val;
1698 TRACE(DBG,
"set "<<d->
fName<<
" to "<<*((XrdOucString *)d->
fVal));
1707 const char *host = (
const char *)h;
1709 if (!d || !host || strlen(host) <= 0)
1728 if (pipe(
fPipe) != 0) {
1761 XPDLOC(AUX,
"Pipe::Post")
1766 if (msg && strlen(msg) > 0) {
1767 XPDFORM(buf,
"%d %s", type, msg);
1771 TRACE(HDBG,
fPipe[1] <<
": posting: type: "<<type<<
", buf: "<<buf);
1772 int len = buf.length() + 1;
1774 if (
write(
fPipe[1], &len,
sizeof(len)) !=
sizeof(len))
1776 if (
write(
fPipe[1], buf.c_str(), len) != len)
1782 TRACE(XERR,
"pipe is invalid");
1791 XPDLOC(AUX,
"Pipe::Recv")
1799 TRACE(HDBG,
fPipe[0] <<
": receiving: msg: "<< buf);
1800 msg.
Init(buf.c_str());
1805 TRACE(XERR,
"pipe is invalid");
1814 XPDLOC(AUX,
"Pipe::Poll")
1819 struct pollfd fds_r;
1820 fds_r.fd =
fPipe[0];
1821 fds_r.events = POLLIN;
1825 int xto = (to > 0) ? to * 1000 : -1;
1826 while ((pollrc = poll(&fds_r, 1, xto)) < 0 && (errno == EINTR)) {
1830 return (pollrc >= 0) ? pollrc : -errno;
1833 TRACE(XERR,
"pipe is invalid");
1851 TRACE(HDBG,
"buf: "<< (
const char *)(buf ? buf :
"+++ empty +++"));
1853 if (buf && strlen(buf) > 0) {
1858 if ((
fFrom =
fBuf.tokenize(ctyp,
fFrom,
' ')) == -1 || ctyp.length() <= 0) {
1859 TRACE(XERR,
"ctyp: "<<ctyp<<
" fFrom: "<<
fFrom);
1864 fType = ctyp.atoi();
1866 TRACE(XERR,
"ctyp: "<<ctyp<<
" fType: "<<
fType);
1872 while (
fBuf.beginswith(
' '))
1892 if ((
fFrom =
fBuf.tokenize(tkn,
fFrom,
' ')) == -1 || tkn.length() <= 0)
1896 TRACE(XERR,
"tkn: "<<tkn<<
" i: "<<i);
1913 if ((
fFrom =
fBuf.tokenize(s,
fFrom,
' ')) == -1 || s.length() <= 0) {
1932 if ((
fFrom =
fBuf.tokenize(tkn,
fFrom,
' ')) == -1 || tkn.length() <= 0) {
1933 TRACE(XERR,
"tkn: "<<tkn<<
" fFrom: "<<
fFrom);
1936 sscanf(tkn.c_str(),
"%p", p);
1964 if (s && strlen(s)) {
1965 XrdOucString kernel(s);
1967 int ib = kernel.find(
'[');
1968 if (ib == STR_NPOS)
return;
1970 int ie = kernel.find(
']', ib + 1);
1971 if (ie == STR_NPOS)
return;
1973 if (ie == ib + 1)
return;
1975 fHead.assign(kernel, 0, ib -1);
1976 fTail.assign(kernel, ie + 1);
1978 XrdOucString tkns(kernel, ib + 1, ie - 1);
1982 while ((from = tkns.tokenize(tkn, from,
',')) != -1) {
1983 if (tkn.length() > 0) {
2004 if (s && strlen(s)) {
2005 XrdOucString str(s);
2006 if (
fHead.length() <= 0 || str.beginswith(
fHead)) {
2007 if (
fTail.length() <= 0 || str.endswith(
fTail)) {
2008 str.replace(
fHead,
"");
2009 str.replace(
fTail,
"");
2010 std::list<XrdProofdMultiStrToken>::iterator it =
fTokens.begin();
2011 for (; it !=
fTokens.end(); it++) {
2012 if ((*it).Matches(str.c_str()))
2027 XrdOucString str(
fN * (
fHead.length() +
fTail.length() + 4)) ;
2030 std::list<XrdProofdMultiStrToken>::iterator it =
fTokens.begin();
2031 for (; it !=
fTokens.end(); it++) {
2032 int n = (*it).N(), j = -1;
2035 str += (*it).Export(j);
2042 if (str.endswith(
','))
2043 str.erase(str.rfind(
','));
2056 std::list<XrdProofdMultiStrToken>::iterator it =
fTokens.begin();
2057 for (; it !=
fTokens.end(); it++) {
2058 int n = (*it).N(), j = -1;
2064 str += (*it).Export(j);
2090 XPDLOC(AUX,
"MultiStrToken::Init")
2098 if (s && strlen(s)) {
2101 int id =
fA.find(
'-');
2102 if (
id == STR_NPOS) {
2109 fB.assign(
fA,
id + 1);
2111 if (
fB.length() <= 0) {
2112 if (
fA.length() > 0) {
2121 char *
a = (
char *)
fA.c_str();
2122 char *b = (
char *)
fB.c_str();
2123 if (
fA.length() == 1 &&
fB.length() == 1) {
2125 if (
fIa != LONG_MAX) {
2134 (
fIa = *a) <= (
fIb = *b)) {
2141 emsg =
"not-supported single-field extremes";
2146 if (
fIa != LONG_MAX &&
fIa != LONG_MIN) {
2148 if (
fIb != LONG_MAX &&
fIb != LONG_MIN &&
fIb >=
fIa) {
2154 emsg =
"non-digit or wrong-ordered extremes";
2158 emsg =
"non-digit extremes";
2180 if (s && strlen(s)) {
2182 return ((
fA == s) ? 1 : 0);
2184 XrdOucString str(s);
2187 if (str.length() > 1)
2189 char *ps = (
char *)s;
2191 if (!
DIGIT(*ps) || *ps < fIa || *ps >
fIb)
2195 if (ls == LONG_MAX || ls < fIa || ls >
fIb)
2200 if (ls == LONG_MAX || ls < fIa || ls >
fIb)
2215 XrdOucString tkn(
fA.length());
2239 tkn = (char)(
fIa + next);
2245 XrdOucString tmp(
fA.length());
2246 tmp.form(
"%ld",
fIa + next);
2248 int dl =
fA.length() - tmp.length();
2249 if (dl <= 0)
return tmp;
2252 while (dl--) tkn +=
"0";
2262 int ns,
const char *ss[5],
2264 int np,
void *pp[5],
2265 int nu,
unsigned int ui)
2268 if (!fmt || (len = strlen(fmt)) <= 0)
return;
2270 char si[32], sp[32];
2274 while (i-- > 0) {
if (ss[i]) { len += strlen(ss[i]); } }
2276 while (i-- > 0) { len += 32; }
2281 s.assign(fmt, from);
2282 int nii = 0, nss = 0, npp = 0, nui = 0;
2284 while ((k = s.find(
'%', from)) != STR_NPOS) {
2286 if (s[k+1] ==
's') {
2288 s.replace(
"%s", ss[nss++], k, k + 1);
2291 }
else if (s[k+1] ==
'd') {
2293 snprintf(si, 32,
"%d", ii[nii++]);
2294 s.replace(
"%d", si, k, k + 1);
2297 }
else if (s[k+1] ==
'u') {
2299 snprintf(si, 32,
"%u", ui);
2300 s.replace(
"%u", si, k, k + 1);
2303 }
else if (s[k+1] ==
'p') {
2305 snprintf(sp, 32,
"%p", pp[npp++]);
2306 s.replace(
"%p", sp, k, k + 1);
2310 if (!replaced) from = k + 1;
2318 const char *s0,
const char *s1,
2319 const char *s2,
const char *s3,
const char *s4)
2321 const char *ss[5] = {s0, s1, s2, s3, s4};
2322 int ii[6] = {0,0,0,0,0,0};
2323 void *pp[5] = {0,0,0,0,0};
2332 int i1,
int i2,
int i3,
int i4,
int i5)
2334 const char *ss[5] = {0, 0, 0, 0, 0};
2335 int ii[6] = {i0,i1,i2,i3,i4,i5};
2336 void *pp[5] = {0,0,0,0,0};
2345 void *p0,
void *
p1,
void *
p2,
void *
p3,
void *p4)
2347 const char *ss[5] = {0, 0, 0, 0, 0};
2348 int ii[6] = {0,0,0,0,0,0};
2349 void *pp[5] = {p0,
p1,
p2,
p3,p4};
2359 const char *s1,
const char *s2,
const char *s3)
2361 const char *ss[5] = {s0, s1, s2, s3, 0};
2362 int ii[6] = {i0,0,0,0,0,0};
2363 void *pp[5] = {0,0,0,0,0};
2372 int i0,
int i1,
int i2,
int i3)
2374 const char *ss[5] = {s0,0,0,0,0};
2375 int ii[6] = {i0,i1,i2,i3,0,0};
2376 void *pp[5] = {0,0,0,0,0};
2385 int i0,
int i1,
unsigned int ui)
2387 const char *ss[5] = {s0,0,0,0,0};
2388 int ii[6] = {i0,i1,0,0,0,0};
2389 void *pp[5] = {0,0,0,0,0};
2398 int i0,
int i1,
int i2)
2400 const char *ss[5] = {s0,s1,0,0,0};
2401 int ii[6] = {i0,i1,i2,0,0,0};
2402 void *pp[5] = {0,0,0,0,0};
2411 const char *s0,
const char *s1,
const char *s2)
2413 const char *ss[5] = {s0,s1,s2,0,0};
2414 int ii[6] = {i0,i1,0,0,0,0};
2415 void *pp[5] = {0,0,0,0,0};
2425 const char *s1,
const char *s2,
2427 const char *s3,
const char *s4)
2429 const char *ss[5] = {s0,s1,s2,s3,s4};
2430 int ii[6] = {i0,i1,0,0,0,0};
2431 void *pp[5] = {0,0,0,0,0};
2440 int i0,
int i1,
const char *s1,
2441 const char *s2,
const char *s3)
2443 const char *ss[5] = {s0,s1,s2,s3,0};
2444 int ii[6] = {i0,i1,0,0,0,0};
2445 void *pp[5] = {0,0,0,0,0};
2454 const char *s1,
const char *s2,
2455 int i0,
unsigned int ui)
2457 const char *ss[5] = {s0,s1,s2,0,0};
2458 int ii[6] = {i0,0,0,0,0,0};
2459 void *pp[5] = {0,0,0,0,0};
2468 const char *s0,
const char *s1)
2470 const char *ss[5] = {s0,s1,0,0,0};
2471 int ii[6] = {i0,i1,i2,0,0,0};
2472 void *pp[5] = {0,0,0,0,0};
2482 const char *s1,
const char *s2,
const char *s3,
int i0)
2484 const char *ss[5] = {s0,s1,s2,s3,0};
2485 int ii[6] = {i0,0,0,0,0,0};
2486 void *pp[5] = {0,0,0,0,0};
2495 int i3,
const char *s0)
2497 const char *ss[5] = {s0,0,0,0,0};
2498 int ii[6] = {i0,i1,i2,i3,0,0};
2499 void *pp[5] = {0,0,0,0,0};
2509 const char *ss[5] = {0,0,0,0,0};
2510 int ii[6] = {i0,i1,0,0,0,0};
2511 void *pp[5] = {p0,0,0,0,0};
2520 int i0,
int i1,
int i2,
void *p0)
2522 const char *ss[5] = {0,0,0,0,0};
2523 int ii[6] = {i0,i1,i2,0,0,0};
2524 void *pp[5] = {p0,0,0,0,0};
2533 int i0,
int i1,
int i2,
int i3,
void *p0)
2535 const char *ss[5] = {0,0,0,0,0};
2536 int ii[6] = {i0,i1,i2,i3,0,0};
2537 void *pp[5] = {p0,0,0,0,0};
2546 void *p0,
int i2,
int i3)
2548 const char *ss[5] = {0,0,0,0,0};
2549 int ii[6] = {i0,i1,i2,i3,0,0};
2550 void *pp[5] = {p0,0,0,0,0};
2560 const char *ss[5] = {0,0,0,0,0};
2561 int ii[6] = {i0,i1,0,0,0,0};
2562 void *pp[5] = {p0,0,0,0,0};
2571 const char *s0,
void *p0,
int i0,
int i1)
2573 const char *ss[5] = {s0,0,0,0,0};
2574 int ii[6] = {i0,i1,0,0,0,0};
2575 void *pp[5] = {p0,0,0,0,0};
2584 void *p0,
const char *s0,
int i0)
2586 const char *ss[5] = {s0,0,0,0,0};
2587 int ii[6] = {i0,0,0,0,0,};
2588 void *pp[5] = {p0,0,0,0,0};
2597 const char *s0,
const char *s1,
void *p0)
2599 const char *ss[5] = {s0,s1,0,0,0};
2600 int ii[6] = {0,0,0,0,0,0};
2601 void *pp[5] = {p0,0,0,0,0};
2610 const char *s0,
const char *s1,
int i1,
int i2)
2612 const char *ss[5] = {s0,s1,0,0,0};
2613 int ii[6] = {i0,i1,i2,0,0,0};
2614 void *pp[5] = {0,0,0,0,0};
2623 const char *s0,
int i1,
int i2)
2625 const char *ss[5] = {s0,0,0,0,0};
2626 int ii[6] = {i0,i1,i2,0,0,0};
2627 void *pp[5] = {0,0,0,0,0};
double read(const std::string &file_name)
reading
static int GetNumCPUs()
Find out and return the number of CPUs in the local machine.
static int Write(int fd, const void *buf, size_t nb)
Write nb bytes at buf to descriptor 'fd' ignoring interrupts Return the number of bytes written or -1...
int DoDirectiveInt(XrdProofdDirective *d, char *val, XrdOucStream *cfg, bool rcf)
Process directive for an integer.
int Poll(int to=-1)
Poll over the read pipe for to secs; return whatever poll returns.
static int AssertBaseDir(const char *path, XrdProofUI ui)
Make sure that the base dir of 'path' is either owned by 'ui' or gives full permissions to 'ui'...
static double p3(double t, double a, double b, double c, double d)
double write(int n, const std::string &file_name, const std::string &vector_type, int compress=0)
writing
ClassImp(TSeqCollection) Int_t TSeqCollection TIter next(this)
Return index of object in collection.
static int GetUserInfo(const char *usr, XrdProofUI &ui)
Get information about user 'usr' in a thread safe way.
static const char * AdminMsgType(int type)
Translates the admin message type in a human readable string.
static int RmDir(const char *path)
Remove directory at path and its content.
int DoDirectiveClass(XrdProofdDirective *d, char *val, XrdOucStream *cfg, bool rcf)
Generic class directive processor.
#define TRACE(Flag, Args)
int Init(const char *buf)
Init from buffer.
static bool HasToken(const char *s, const char *tokens)
Returns true is 's' contains at least one of the comma-separated tokens in 'tokens'.
static struct mg_connection * fc(struct mg_context *ctx)
int Recv(XpdMsg &msg)
Recv message from the pipe.
ClassImp(RooList) TObjOptLink *RooList TObjLink * link
Find the link corresponding to the named object in this list.
Vc_ALWAYS_INLINE void free(T *p)
Frees memory that was allocated with Vc::malloc.
static int ParsePidPath(const char *path, XrdOucString &before, XrdOucString &after)
Parse a path in the form of "
[.][.]", filling 'rest' and returning 'pid'...
static int SymLink(const char *path, const char *link)
Create a symlink 'link' to 'path' Return 0 in case of success, -1 in case of error.
#define LETTOIDX(x, ilet)
static double p2(double t, double a, double b, double c)
void Close()
If open, close and invalidated the pipe descriptors.
bool Matches(const char *s)
Return true if 's' is compatible with this multi-string.
static void Form(XrdOucString &s, const char *fmt, int ns, const char *ss[5], int ni, int ii[6], int np, void *pp[5], int nu=0, unsigned int ui=0)
Recreate the string according to 'fmt', the up to 5 'const char *', up to 6 'int' arguments...
static const char * ProofRequestTypes(int type)
Translates the proof request type in a human readable string.
static int GetIDFromPath(const char *path, XrdOucString &emsg)
Extract an integer from a file.
int DoDirectiveString(XrdProofdDirective *d, char *val, XrdOucStream *cfg, bool rcf)
Process directive for a string.
int changeown(const std::string &path, uid_t u, gid_t g)
Change the ownership of 'path' to the entity described by {u,g}.
#define XrdSysMutexHelper
static int Touch(const char *path, int opt=0)
Set access (opt == 1), modify (opt =2 ) or access&modify (opt = 0, default) times of path to current ...
#define XpdBadPGuard(g, u)
static double p1(double t, double a, double b)
static long int GetLong(char *str)
Extract first integer from string at 'str', if any.
static int GetGroupInfo(const char *grp, XrdProofGI &gi)
Get information about group with 'gid' 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 ReadMsg(int fd, XrdOucString &msg)
Receive 'msg' from pipe fd.
static int CheckIf(XrdOucStream *s, const char *h)
Check existence and match condition of an 'if' directive If none (valid) is found, return -1.
static char * Expand(char *p)
Expand path 'p' relative to: $HOME if begins with ~/ 's $HOME if begins with ~/ $PWD if d...
static int ParseUsrGrp(const char *path, XrdOucString &usr, XrdOucString &grp)
Parse a path in the form of "
[.][.]", filling 'usr' and 'grp'.
bool Matches(const char *s)
Return true if 's' is compatible with this token.
static int ChangeMod(const char *path, unsigned int mode)
Change the permission mode of 'path' to 'mode'.
XrdOucString Export()
Return a string with comma-separated elements.
virtual ~XrdProofdPipe()
Destructor.
std::list< XrdProofdMultiStrToken > fTokens
int Get(int &i)
Get next token and interpret it as an int.
XrdOucString Get(int i)
Return i-th combination (i : 0 -> fN-1)
static int ChangeToDir(const char *dir, XrdProofUI ui, bool changeown)
Change current directory to 'dir'.
ClassImp(TSlaveInfo) Int_t TSlaveInfo const TSlaveInfo * si
Used to sort slaveinfos by ordinal.
static int ChangeOwn(const char *path, XrdProofUI ui)
Change the ownership of 'path' to the entity described by 'ui'.
int Post(int type, const char *msg)
Post message on the pipe.
void Init(const char *s)
Init the multi-string token.
static int VerifyProcessByID(int pid, const char *pname="proofserv")
Check if a process named 'pname' and process 'pid' is still in the process table. ...
void Init(const char *s)
Init the multi-string handler.
XrdProofdPipe()
Constructor: create the pipe.
static int GetProcesses(const char *pn, std::map< int, XrdOucString > *plist)
Get from the process table list of PIDs for processes named "proofserv' For {linux, sun, macosx} it uses the system info; for other systems it invokes the command shell 'ps ax' via popen.
static void LogEmsgToFile(const char *flog, const char *emsg, const char *pfx=0)
Logs error message 'emsg' to file 'flog' using standard technology.
XrdOucString Export(int &next)
Export 'next' token; use next < 0 start from the first.
Vc_ALWAYS_INLINE_L T *Vc_ALWAYS_INLINE_R malloc(size_t n)
Allocates memory on the Heap with alignment and padding suitable for vectorized access.
int SetHostInDirectives(const char *, XrdProofdDirective *d, void *h)
Set host field for directive 'd' to (const char *h)
static int MvDir(const char *oldpath, const char *newpath)
Move content of directory at oldpath to newpath.
static int KillProcess(int pid, bool forcekill, XrdProofUI ui, bool changeown)
Kill the process 'pid'.
#define IDXTOLET(ilet, x)
static XrdSysRecMutex fgFormMutex