51 #include <sys/param.h>
53 #include <sys/types.h>
84 int XrdW41Gate::gateOpen = 0;
116 int main(
int argc,
char *argv[])
127 signal(SIGPIPE, SIG_IGN);
129 sigaddset(&myset, SIGPIPE);
130 sigaddset(&myset, SIGCHLD);
131 pthread_sigmask(SIG_BLOCK, &myset, NULL);
140 for (i = 1; i < argc; i++)
143 std::cerr <<
"wait41: " <<eText <<
" processing " <<argv[i] <<std::endl;
146 if (S_ISREG(
Stat.st_mode))
148 else if (S_ISDIR(
Stat.st_mode))
155 {std::cerr <<
"wait41: Nothing to wait on!" <<std::endl;
156 std::cout <<
"BAD\n" <<std::endl;
163 std::cout <<eText <<std::endl;
167 if (
read(STDIN_FILENO, buff,
sizeof(buff))) {}
183 char buff[1024], *sfxDir;
188 std::cerr <<
"wait41: " <<eText <<
" opening directory" <<
Path <<std::endl;
192 strcpy(buff,
Path); sfxDir = buff + strlen(
Path);
193 if (*(sfxDir-1) !=
'/') *sfxDir++ =
'/';
197 {
if (!strcmp(dp->d_name,
".") || !strcmp(dp->d_name,
".."))
continue;
198 strcpy(sfxDir, dp->d_name);
201 std::cerr <<
"wait41: " <<eText <<
" processing " <<buff <<std::endl;
210 std::cerr <<
"wait41: " <<eText <<
" reading directory" <<
Path <<std::endl;
231 bzero(&lock_args,
sizeof(lock_args));
232 lock_args.l_type = F_WRLCK;
233 Act = (Wait ? F_SETLKW : F_SETLK);
237 do {rc =
fcntl(gfP->val, Act, &lock_args);}
while(rc == -1 && errno == EINTR);
241 if (rc != -1) rc = 0;
243 std::cerr <<
"Serialize: " <<
XrdSysE2T(rc) <<
" locking FD " <<gfP->
text <<std::endl;
249 if (rc || gateOpen)
close(gfP->val);
261 static const int AMode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
272 if (gateOpen) {gateMutex.UnLock();
return 1;}
275 if ((gfP->val =
open(gfP->
text, O_CREAT|O_RDWR, AMode)) < 0)
277 std::cerr <<
"Wait41: " <<eTxt <<
" opening " <<gfP->
text <<std::endl;
282 std::cerr <<
"Wait41: " <<eTxt <<
" creating gate thread for "
283 <<gfP->text <<std::endl;
294 if (gateOpen) {gateMutex.UnLock();
return 1;}
int stat(const char *path, struct stat *buf)
struct dirent * readdir(DIR *dirp)
int open(const char *path, int oflag,...)
int fcntl(int fd, int cmd,...)
ssize_t read(int fildes, void *buf, size_t nbyte)
DIR * opendir(const char *path)
const char * XrdSysE2T(int errcode)
#define XRDSYSTHREAD_BIND
int main(int argc, char *argv[])
static int Run(pthread_t *, void *(*proc)(void *), void *arg, int opts=0, const char *desc=0)
static void setStackSize(size_t stsz, bool force=false)
static XrdOucTList * Expand(const char *Path, XrdOucTList *ptl)
static int Wait41(XrdOucTList *fP)
static void Serialize(XrdOucTList *gfP, int Wait=1)
void * GateWait(void *parg)