Skip to content

Commit

Permalink
[All] Implement thread-safe strerror() replacement.
Browse files Browse the repository at this point in the history
[All] Change all uses of strerror to XrdSysET() part 1.
  • Loading branch information
abh3 committed Oct 25, 2019
1 parent b50b0c8 commit e62ab78
Show file tree
Hide file tree
Showing 71 changed files with 502 additions and 260 deletions.
5 changes: 3 additions & 2 deletions src/XrdApps/XrdAppsCconfig.cc
Expand Up @@ -40,6 +40,7 @@
#include "XrdOuc/XrdOucNList.hh"
#include "XrdOuc/XrdOucStream.hh"
#include "XrdOuc/XrdOucUtils.hh"
#include "XrdSys/XrdSysE2T.hh"
#include "XrdSys/XrdSysError.hh"
#include "XrdSys/XrdSysLogger.hh"
#include "XrdSys/XrdSysHeaders.hh"
Expand Down Expand Up @@ -133,7 +134,7 @@ int main(int argc, char *argv[])
// Open the config file
//
if ( (cfgFD = open(Cfn, O_RDONLY, 0)) < 0)
{Say.Say(Pgm, strerror(errno), " opening config file ", Cfn);
{Say.Say(Pgm, XrdSysE2T(errno), " opening config file ", Cfn);
exit(4);
}

Expand Down Expand Up @@ -168,7 +169,7 @@ int main(int argc, char *argv[])
// Now check if any errors occured during file i/o
//
if ((retc = Config->LastError()))
{Say.Say(Pgm, strerror(retc), " reading config file ", Cfn); retc = 8;}
{Say.Say(Pgm, XrdSysE2T(retc), " reading config file ", Cfn); retc = 8;}
Config->Close();

// Should never get here
Expand Down
10 changes: 5 additions & 5 deletions src/XrdApps/XrdCpConfig.cc
Expand Up @@ -28,7 +28,6 @@
/* specific prior written permission of the institution or contributor. */
/******************************************************************************/

#include <errno.h>
#include <fcntl.h>
#include <getopt.h>
#include <stdio.h>
Expand All @@ -43,6 +42,7 @@
#include "XrdCks/XrdCksCalc.hh"
#include "XrdCks/XrdCksManager.hh"
#include "XrdOuc/XrdOucStream.hh"
#include "XrdSys/XrdSysE2T.hh"
#include "XrdSys/XrdSysError.hh"
#include "XrdSys/XrdSysHeaders.hh"
#include "XrdSys/XrdSysLogger.hh"
Expand Down Expand Up @@ -369,7 +369,7 @@ do{while(optind < Argc && Legacy(optind)) {}
| (dstFile->Protocol == XrdCpFile::isStdIO);
if (isLcl && (rc = dstFile->Resolve()))
{if (rc != ENOENT || (Argc - optind - 1) > 1 || OpSpec & DoRecurse)
FMSG(strerror(rc) <<" processing " <<dstFile->Path, 2);
FMSG(XrdSysE2T(rc) <<" processing " <<dstFile->Path, 2);
}

// Now pick up all the source files from the command line
Expand All @@ -383,7 +383,7 @@ do{while(optind < Argc && Legacy(optind)) {}
{XrdOucStream inList(Log);
char *fname;
int inFD = open(inFile, O_RDONLY);
if (inFD < 0) FMSG(strerror(errno) <<" opening infiles " <<inFile, 2);
if (inFD < 0) FMSG(XrdSysE2T(errno) <<" opening infiles " <<inFile, 2);
inList.Attach(inFD);
while((fname = inList.GetLine())) if (*fname) ProcFile(fname);
}
Expand Down Expand Up @@ -426,7 +426,7 @@ do{while(optind < Argc && Legacy(optind)) {}
if (Verbose) EMSG("Indexing files in " <<Path);
numFiles--;
if ((rc = pFile->Extend(&pLast, numFiles, totBytes)))
FMSG(strerror(rc) <<" indexing " <<Path, 2);
FMSG(XrdSysE2T(rc) <<" indexing " <<Path, 2);
if (pFile->Next)
{pLast->Next = pPrev->Next;
pPrev->Next = pFile->Next;
Expand Down Expand Up @@ -846,7 +846,7 @@ void XrdCpConfig::ProcFile(const char *fname)
// For local files, make sure it exists and get its size
//
if (pFile->Protocol == XrdCpFile::isFile && (rc = pFile->Resolve()))
FMSG(strerror(rc) <<" processing " <<pFile->Path, 2);
FMSG(XrdSysE2T(rc) <<" processing " <<pFile->Path, 2);

// Process file based on type (local or remote)
//
Expand Down
16 changes: 8 additions & 8 deletions src/XrdApps/XrdWait41.cc
Expand Up @@ -41,7 +41,6 @@

#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <stdlib.h>
Expand All @@ -54,6 +53,7 @@
#include <sys/types.h>

#include "XrdOuc/XrdOucTList.hh"
#include "XrdSys/XrdSysE2T.hh"
#include "XrdSys/XrdSysHeaders.hh"
#include "XrdSys/XrdSysPlatform.hh"
#include "XrdSys/XrdSysPthread.hh"
Expand Down Expand Up @@ -139,7 +139,7 @@ int main(int argc, char *argv[])
//
for (i = 1; i < argc; i++)
{if (stat(argv[i], &Stat))
{eText = strerror(errno);
{eText = XrdSysE2T(errno);
cerr <<"wait41: " <<eText <<" processing " <<argv[i] <<endl;
continue;
}
Expand Down Expand Up @@ -184,7 +184,7 @@ XrdOucTList *XrdW41Dirs::Expand(const char *Path, XrdOucTList *ptl)
DIR *DFD;

if (!(DFD = opendir(Path)))
{eText = strerror(errno);
{eText = XrdSysE2T(errno);
cerr <<"wait41: " <<eText <<" opening directory" <<Path <<endl;
return ptl;
}
Expand All @@ -197,7 +197,7 @@ XrdOucTList *XrdW41Dirs::Expand(const char *Path, XrdOucTList *ptl)
{if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, "..")) continue;
strcpy(sfxDir, dp->d_name);
if (stat(buff, &Stat))
{eText = strerror(errno);
{eText = XrdSysE2T(errno);
cerr <<"wait41: " <<eText <<" processing " <<buff <<endl;
continue;
}
Expand All @@ -206,7 +206,7 @@ XrdOucTList *XrdW41Dirs::Expand(const char *Path, XrdOucTList *ptl)
}

if (errno)
{eText = strerror(errno);
{eText = XrdSysE2T(errno);
cerr <<"wait41: " <<eText <<" reading directory" <<Path <<endl;
}

Expand Down Expand Up @@ -240,7 +240,7 @@ void XrdW41Gate::Serialize(XrdOucTList *gfP, int Wait)
//
if (rc != -1) rc = 0;
else {rc = errno;
cerr <<"Serialize: " <<strerror(rc) <<" locking FD " <<gfP->text <<endl;
cerr <<"Serialize: " <<XrdSysE2T(rc) <<" locking FD " <<gfP->text <<endl;
}

// Reflect what happened here
Expand Down Expand Up @@ -273,12 +273,12 @@ int XrdW41Gate::Wait41(XrdOucTList *gfP)
gateMutex.UnLock();
}
if ((gfP->val = open(gfP->text, O_CREAT|O_RDWR, AMode)) < 0)
{eTxt = strerror(errno);
{eTxt = XrdSysE2T(errno);
cerr <<"Wait41: " <<eTxt <<" opening " <<gfP->text <<endl;
}
else if ((rc = XrdSysThread::Run(&tid, GateWait, (void *)gfP,
XRDSYSTHREAD_BIND, "Gate Wait")))
{eTxt = strerror(errno);
{eTxt = XrdSysE2T(errno);
cerr <<"Wait41: " <<eTxt <<" creating gate thread for "
<<gfP->text <<endl;
close(gfP->val);
Expand Down
6 changes: 3 additions & 3 deletions src/XrdBwm/XrdBwm.cc
Expand Up @@ -964,13 +964,13 @@ int XrdBwm::Emsg(const char *pfx, // Message prefix value
const char *op, // Operation being performed
const char *target) // The target (e.g., fname)
{
char *etext, buffer[MAXPATHLEN+80], unkbuff[64];
const char *etext;
char buffer[MAXPATHLEN+80];

// Get the reason for the error
//
if (ecode < 0) ecode = -ecode;
if (!(etext = BwmEroute.ec2text(ecode)))
{sprintf(unkbuff, "reason unknown (%d)", ecode); etext = unkbuff;}
etext = BwmEroute.ec2text(ecode);

// Format the error message
//
Expand Down
9 changes: 5 additions & 4 deletions src/XrdCl/XrdClAsyncSocketHandler.cc
Expand Up @@ -24,6 +24,7 @@
#include "XrdCl/XrdClXRootDTransport.hh"
#include "XrdCl/XrdClXRootDMsgHandler.hh"
#include "XrdCl/XrdClOptimizers.hh"
#include "XrdSys/XrdSysE2T.hh"
#include <netinet/tcp.h>

namespace XrdCl
Expand Down Expand Up @@ -309,7 +310,7 @@ namespace XrdCl
{
log->Error( AsyncSockMsg, "[%s] Unable to get the status of the "
"connect operation: %s", pStreamName.c_str(),
strerror( errno ) );
XrdSysE2T( errno ) );
pStream->OnConnectError( pSubStreamNum,
Status( stFatal, errSocketOptError, errno ) );
return;
Expand All @@ -321,7 +322,7 @@ namespace XrdCl
if( errorCode )
{
log->Error( AsyncSockMsg, "[%s] Unable to connect: %s",
pStreamName.c_str(), strerror( errorCode ) );
pStreamName.c_str(), XrdSysE2T( errorCode ) );
pStream->OnConnectError( pSubStreamNum,
Status( stError, errConnectionError ) );
return;
Expand Down Expand Up @@ -470,7 +471,7 @@ namespace XrdCl
{
Log *log = DefaultEnv::GetLog();
log->Error( AsyncSockMsg, "[%s] Unable to flash the socket: %s",
pStreamName.c_str(), strerror( st.errNo ) );
pStreamName.c_str(), XrdSysE2T( st.errNo ) );
OnFaultWhileHandshaking( st );
}

Expand Down Expand Up @@ -549,7 +550,7 @@ namespace XrdCl
{
Log *log = DefaultEnv::GetLog();
log->Error( AsyncSockMsg, "[%s] Unable to flash the socket: %s",
pStreamName.c_str(), strerror( st.errNo ) );
pStreamName.c_str(), XrdSysE2T( st.errNo ) );
}

return st;
Expand Down
5 changes: 3 additions & 2 deletions src/XrdCl/XrdClCheckSumManager.cc
Expand Up @@ -28,6 +28,7 @@
#include "XrdCks/XrdCksCalcmd5.hh"
#include "XrdCks/XrdCksCalccrc32.hh"
#include "XrdCks/XrdCksCalcadler32.hh"
#include "XrdSys/XrdSysE2T.hh"
#include "XrdVersion.hh"

#include <sys/types.h>
Expand Down Expand Up @@ -122,7 +123,7 @@ namespace XrdCl
if( fd == -1 )
{
log->Error( UtilityMsg, "Unable to open %s: %s", filePath.c_str(),
strerror( errno ) );
XrdSysE2T( errno ) );
return false;
}

Expand All @@ -138,7 +139,7 @@ namespace XrdCl
if( bytesRead == -1 )
{
log->Error( UtilityMsg, "Unable read from %s: %s", filePath.c_str(),
strerror( errno ) );
XrdSysE2T( errno ) );
close( fd );
delete [] buffer;
return false;
Expand Down
5 changes: 3 additions & 2 deletions src/XrdCl/XrdClClassicCopyJob.cc
Expand Up @@ -36,6 +36,7 @@
#include "XrdCl/XrdClZipArchiveReader.hh"
#include "XrdCl/XrdClPostMaster.hh"
#include "XrdCl/XrdClJobManager.hh"
#include "XrdSys/XrdSysE2T.hh"

#include <memory>
#include <mutex>
Expand Down Expand Up @@ -374,7 +375,7 @@ namespace
if( bRead == -1 )
{
log->Debug( UtilityMsg, "Unable to read from stdin: %s",
strerror( errno ) );
XrdSysE2T( errno ) );
delete [] buffer;
return XRootDStatus( stError, errOSError, errno );
}
Expand Down Expand Up @@ -1198,7 +1199,7 @@ namespace
if( wr == -1 )
{
log->Debug( UtilityMsg, "Unable to write to stdout: %s",
strerror( errno ) );
XrdSysE2T( errno ) );
delete [] (char*)ci.buffer; ci.buffer = 0;
return XRootDStatus( stError, errOSError, errno );
}
Expand Down
5 changes: 3 additions & 2 deletions src/XrdCl/XrdClCopy.cc
Expand Up @@ -31,6 +31,7 @@
#include "XrdCl/XrdClFileSystem.hh"
#include "XrdCl/XrdClUtils.hh"
#include "XrdCl/XrdClDlgEnv.hh"
#include "XrdSys/XrdSysE2T.hh"
#include "XrdSys/XrdSysPthread.hh"

#include <stdio.h>
Expand Down Expand Up @@ -628,7 +629,7 @@ int main( int argc, char **argv )
char *cwd = getcwd( buf, FILENAME_MAX );
if( !cwd )
{
XRootDStatus st( stError, XProtocol::mapError( errno ), errno, strerror( errno ) );
XRootDStatus st( stError, XProtocol::mapError( errno ), errno, XrdSysE2T( errno ) );
std::cerr << st.GetErrorMessage() << std::endl;
return st.GetShellCode();
}
Expand Down Expand Up @@ -732,7 +733,7 @@ int main( int argc, char **argv )
char *cwd = getcwd( buf, FILENAME_MAX );
if( !cwd )
{
XRootDStatus st( stError, XProtocol::mapError( errno ), errno, strerror( errno ) );
XRootDStatus st( stError, XProtocol::mapError( errno ), errno, XrdSysE2T( errno ) );
std::cerr << st.GetErrorMessage() << std::endl;
return st.GetShellCode();
}
Expand Down
3 changes: 2 additions & 1 deletion src/XrdCl/XrdClFS.cc
Expand Up @@ -32,6 +32,7 @@
#include "XrdCl/XrdClUtils.hh"
#include "XrdCl/XrdClCopyProcess.hh"
#include "XrdCl/XrdClFile.hh"
#include "XrdSys/XrdSysE2T.hh"

#include <cstdlib>
#include <cstdio>
Expand Down Expand Up @@ -1475,7 +1476,7 @@ XRootDStatus DoTail( FileSystem *fs,
if( ret == -1 )
{
log->Error( AppMsg, "Unable to write to stdout: %s",
strerror(errno) );
XrdSysE2T(errno) );
delete [] buffer;
return st;
}
Expand Down
9 changes: 5 additions & 4 deletions src/XrdCl/XrdClFileSystem.cc
Expand Up @@ -36,6 +36,7 @@
#include "XrdCl/XrdClPlugInManager.hh"
#include "XrdCl/XrdClLocalFileTask.hh"
#include "XrdCl/XrdClZipListHandler.hh"
#include "XrdSys/XrdSysE2T.hh"
#include "XrdSys/XrdSysPthread.hh"

#include <sys/stat.h>
Expand All @@ -62,10 +63,10 @@ namespace
struct stat ssp;
if( stat( path.c_str(), &ssp ) == -1 )
{
log->Error( FileMsg, "Stat: failed: %s", strerror( errno ) );
log->Error( FileMsg, "Stat: failed: %s", XrdSysE2T( errno ) );
XRootDStatus *error = new XRootDStatus( stError, errErrorResponse,
XProtocol::mapError( errno ),
strerror( errno ) );
XrdSysE2T( errno ) );
return QueueTask( error, 0, handler );
}

Expand Down Expand Up @@ -100,10 +101,10 @@ namespace
Log *log = DefaultEnv::GetLog();
if( unlink( path.c_str() ) )
{
log->Error( FileMsg, "Rm: failed: %s", strerror( errno ) );
log->Error( FileMsg, "Rm: failed: %s", XrdSysE2T( errno ) );
XRootDStatus *error = new XRootDStatus( stError, errErrorResponse,
XProtocol::mapError( errno ),
strerror( errno ) );
XrdSysE2T( errno ) );
return QueueTask( error, 0, handler );
}

Expand Down
7 changes: 4 additions & 3 deletions src/XrdCl/XrdClJobManager.cc
Expand Up @@ -20,6 +20,7 @@
#include "XrdCl/XrdClLog.hh"
#include "XrdCl/XrdClDefaultEnv.hh"
#include "XrdCl/XrdClConstants.hh"
#include "XrdSys/XrdSysE2T.hh"

//------------------------------------------------------------------------------
// The thread
Expand Down Expand Up @@ -75,7 +76,7 @@ namespace XrdCl
if( ret != 0 )
{
log->Error( JobMgrMsg, "Unable to spawn a job worker thread: %s",
strerror( errno ) );
XrdSysE2T( errno ) );
if( i > 0 )
StopWorkers( i );
return false;
Expand Down Expand Up @@ -120,14 +121,14 @@ namespace XrdCl
if( pthread_cancel( pWorkers[i] ) != 0 )
{
log->Error( TaskMgrMsg, "Unable to cancel worker #%d: %s", i,
strerror( errno ) );
XrdSysE2T( errno ) );
abort();
}

if( pthread_join( pWorkers[i], (void**)&threadRet ) != 0 )
{
log->Error( TaskMgrMsg, "Unable to join worker #%d: %s", i,
strerror( errno ) );
XrdSysE2T( errno ) );
abort();
}

Expand Down

0 comments on commit e62ab78

Please sign in to comment.