34 #include <sys/param.h>
35 #include <sys/types.h>
56 char *XrdFrmCns::cnsPath = 0;
57 char *XrdFrmCns::cnsHdr[2] = {0, 0};
58 int XrdFrmCns::cnsHdrLen = 0;
59 int XrdFrmCns::cnsFD = -1;
61 int XrdFrmCns::cnsInit = 1;
68 long long Size, mode_t
Mode)
70 static const int mMask = S_IRWXU|S_IRWXG|S_IRWXO;
71 static char NewLine =
'\n';
73 char mBuff[8], sBuff[24];
78 if (cnsInit && !Init())
79 {
Say.
Emsg(
"FrmCns",
"Auto-ignore cnsd create",
Path);
return;}
83 iov[0].iov_base = (
char *)tID;
84 iov[0].iov_len = strlen(tID);
85 iov[1].iov_base = (
char *)
" create ";
87 iov[2].iov_base = mBuff;
88 iov[2].iov_len = sprintf(mBuff,
"%3o ",
Mode&mMask);
91 iov[4].iov_base = 

94 iov[6].iov_base = (
char *)
" closew ";
97 iov[8].iov_base = sBuff;
98 iov[8].iov_len = sprintf(sBuff,
" %lld\n", Size);
102 if (!Send2Cnsd(
iov, 9))
Say.
Emsg(
"FrmCns",
"Auto-ignore cnsd create",
Path);
109 void XrdFrmCns::Del(
const char *
Path,
int HdrType,
int islfn)
111 static char NewLine =
'\n';
112 struct iovec
iov[] = {{cnsHdr[HdrType],(size_t)cnsHdrLen},{0,0},{&NewLine,1}};
113 char buff[MAXPATHLEN];
117 if (cnsInit && !Init())
118 {
Say.
Emsg(
"FrmCns",
"Auto-ignore cnsd remove",
Path);
return;}
123 {
iov[1].iov_base = (
char *)
Path;
125 }
else if (!
Config.LogicalPath(
Path, buff,
sizeof(buff)))
return;
126 else {
iov[1].iov_base = buff;
127 iov[1].iov_len = strlen(buff);
132 if (!Send2Cnsd(
iov, 3))
Say.
Emsg(
"FrmCns",
"Auto-ignore cnsd remove",
Path);
141 static const int oMode= O_WRONLY | O_NONBLOCK | O_NDELAY;
148 if (!cnsInit) {initMutex.
UnLock();
return 1;}
152 while((cnsFD =
open(cnsPath, oMode)) < 0 && Retry(errno, pMsg)) {}
156 cnsInit = (cnsFD < 0 ? 1 : 0);
171 if (aPath && (rc = setPath(aPath, 0)))
return rc;
185 if (!cnsMode)
return 0;
189 if (!cnsPath && (rc = setPath(aPath, iName)))
return rc;
193 cnsHdrLen = sprintf(buff,
"%s.%d.0@localhost rmdir ", myID, getpid());
194 cnsHdr[HdrRmd] = strdup(buff);
195 sprintf(buff,
"%s.%d.0@localhost rm ", myID, getpid());
196 cnsHdr[HdrRmf] = strdup(buff);
207 int XrdFrmCns::Retry(
int eNum,
int &pMsg)
209 static const char *eAct = (cnsMode > 0 ?
"Waiting for" :
"Ignoring");
210 static const int Yawn = 10, Blurt = 6;
214 if (eNum == EINTR)
return 1;
218 if (eNum == ENOENT || eNum == EAGAIN || eNum == ENXIO || eNum == EPIPE)
219 {
if (!(pMsg++%Blurt))
Say.
Emsg(
"FrmCns", eAct,
"cnsd on path", cnsPath);}
220 else Say.
Emsg(
"FrmCns", errno,
"notify cnsd via", cnsPath);
224 if (cnsMode <= 0)
return 0;
233 int XrdFrmCns::Send2Cnsd(
struct iovec *
iov,
int iovn)
245 while((rc =
writev(cnsFD,
iov, iovn)) < 0 && Retry(errno, pMsg)) {}
260 int XrdFrmCns::setPath(
const char *aPath,
const char *iName)
262 static const char *sfx =
"XrdCnsd.events";
264 char buff[2048], *pP;
268 if (cnsPath) {free(cnsPath); cnsPath = 0;}
273 if (strlen(pP) + strlen(sfx) >= (
int)
sizeof(buff))
274 {
Say.
Emsg(
"FrmCns",
"Invalid cnsd apath", aPath); free(pP);
return 1;}
275 strcpy(buff, pP); free(pP);
276 strcat(buff,
"XrdCnsd.events");
277 if (
stat(buff, &
Stat) && errno != ENOENT)
278 {
Say.
Emsg(
"FrmCns", errno,
"use cnsd file", buff);
return 1;}
279 cnsPath = strdup(buff);
int stat(const char *path, struct stat *buf)
int open(const char *path, int oflag,...)
ssize_t writev(int fildes, const struct iovec *iov, int iovcnt)
static const int cnsIgnore
static int Init(const char *aPath, int Opts)
static void Add(const char *tID, const char *Path, long long Size, mode_t Mode)
int Serialize(int Opts=0)
static char * genPath(const char *path, const char *inst, const char *psfx=0)
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
static void Snooze(int seconds)