From 73a63ef54764bf2f19d12119d38eb63e47ebc6da Mon Sep 17 00:00:00 2001 From: Alexander van Amesfoort <amesfoort@astron.nl> Date: Wed, 3 Jul 2013 12:43:38 +0000 Subject: [PATCH] Task #4643: use THROW_SYSCALL() macro instead of 'throw SystemCallException(...)' to ensure that errno is loaded immediately and not after it was possible clobbered by string() or Backtrace(). Replace open-coded version in a few instances where the problem had already bitten. Note that all pthread_*() do not set errno, but return it (or 0), so keep those as-is. Fix up errno passing of pthread_kill() in this regard. --- LCS/Common/include/Common/Exception.h | 2 ++ .../include/Common/SystemCallException.h | 1 + LCS/Common/src/Mmap.cc | 2 +- LCS/Stream/src/FileDescriptorBasedStream.cc | 8 ++--- LCS/Stream/src/FileStream.cc | 10 +++--- LCS/Stream/src/NamedPipeStream.cc | 4 +-- LCS/Stream/src/SocketStream.cc | 34 +++++++++---------- .../GPUProc/src/Storage/StorageProcess.cc | 2 +- .../GPUProc/src/Storage/StorageProcesses.cc | 2 +- RTCP/Cobalt/GPUProc/src/cuda/gpu_utils.cc | 3 +- .../InputProc/src/Buffer/SharedMemory.cc | 19 +++++------ RTCP/Cobalt/InputProc/src/OMPThread.h | 8 +++-- RTCP/Cobalt/InputProc/src/obsolete/Poll.h | 8 ++--- .../OutputProc/src/ExitOnClosedStdin.cc | 4 +-- RTCP/Cobalt/OutputProc/src/FastFileStream.cc | 6 ++-- RTCP/Cobalt/OutputProc/src/OutputThread.cc | 6 ++-- RTCP/Cobalt/OutputProc/src/TBB_Writer.cc | 2 +- RTCP/Cobalt/OutputProc/src/TBB_Writer_main.cc | 2 +- RTCP/IONProc/src/StorageProcesses.cc | 4 +-- RTCP/Storage/src/ExitOnClosedStdin.cc | 4 +-- RTCP/Storage/src/FastFileStream.cc | 6 ++-- RTCP/Storage/src/OutputThread.cc | 6 ++-- RTCP/Storage/src/TBB_Writer.cc | 2 +- RTCP/Storage/src/TBB_Writer_main.cc | 2 +- 24 files changed, 72 insertions(+), 75 deletions(-) diff --git a/LCS/Common/include/Common/Exception.h b/LCS/Common/include/Common/Exception.h index 89eeda3e9df..7a0cd139f5c 100644 --- a/LCS/Common/include/Common/Exception.h +++ b/LCS/Common/include/Common/Exception.h @@ -199,6 +199,8 @@ namespace LOFAR // // Throw an exception of type \c excp; use \c strm for the message, // and \c THROW_ARGS for the other constructor arguments. +// Do not use this to 'throw SystemCallException(...)' (unless an errno was +// already avail (e.g pthread functions return it)). Use THROW_SYSCALL() instead. // #if !defined(THROW) # include <sstream> diff --git a/LCS/Common/include/Common/SystemCallException.h b/LCS/Common/include/Common/SystemCallException.h index 6d034915924..f2b2593dc02 100644 --- a/LCS/Common/include/Common/SystemCallException.h +++ b/LCS/Common/include/Common/SystemCallException.h @@ -33,6 +33,7 @@ namespace LOFAR { // Use THROW_SYSCALL(...) below instead of 'throw SystemCallException(...)' // to enforce sampling errno right after the syscall before it can be clobbered. +// (If an errno was already avail (e.g. pthread functions return it), throw ... is fine.) #define THROW_SYSCALL(msg) \ do { \ int err = errno; \ diff --git a/LCS/Common/src/Mmap.cc b/LCS/Common/src/Mmap.cc index 3cb183c1ccc..6f7e3bff851 100644 --- a/LCS/Common/src/Mmap.cc +++ b/LCS/Common/src/Mmap.cc @@ -40,7 +40,7 @@ namespace LOFAR } _ptr = ::mmap(addr, length, prot, flags, fd, offset); if (_ptr == MAP_FAILED) { - throw SystemCallException("mmap", errno, THROW_ARGS); + THROW_SYSCALL("mmap"); } } diff --git a/LCS/Stream/src/FileDescriptorBasedStream.cc b/LCS/Stream/src/FileDescriptorBasedStream.cc index aedf554753a..bc2be0eab03 100644 --- a/LCS/Stream/src/FileDescriptorBasedStream.cc +++ b/LCS/Stream/src/FileDescriptorBasedStream.cc @@ -45,7 +45,7 @@ FileDescriptorBasedStream::~FileDescriptorBasedStream() // backtrace if available, and the proper representation // of exceptions in general. try { - throw SystemCallException("close", errno, THROW_ARGS); + THROW_SYSCALL("close"); } catch (Exception &ex) { LOG_ERROR_STR("Exception in destructor: " << ex); } @@ -58,7 +58,7 @@ size_t FileDescriptorBasedStream::tryRead(void *ptr, size_t size) ssize_t bytes = ::read(fd, ptr, size); if (bytes < 0) - throw SystemCallException("read", errno, THROW_ARGS); + THROW_SYSCALL("read"); if (bytes == 0) throw EndOfStreamException("read", THROW_ARGS); @@ -72,7 +72,7 @@ size_t FileDescriptorBasedStream::tryWrite(const void *ptr, size_t size) ssize_t bytes = ::write(fd, ptr, size); if (bytes < 0) - throw SystemCallException("write", errno, THROW_ARGS); + THROW_SYSCALL("write"); return bytes; } @@ -81,7 +81,7 @@ size_t FileDescriptorBasedStream::tryWrite(const void *ptr, size_t size) void FileDescriptorBasedStream::sync() { if (fsync(fd) < 0) - throw SystemCallException("fsync", errno, THROW_ARGS); + THROW_SYSCALL("fsync"); } } // namespace LOFAR diff --git a/LCS/Stream/src/FileStream.cc b/LCS/Stream/src/FileStream.cc index bc7d4f6df6b..66133f11ad9 100644 --- a/LCS/Stream/src/FileStream.cc +++ b/LCS/Stream/src/FileStream.cc @@ -36,21 +36,21 @@ namespace LOFAR { FileStream::FileStream(const std::string &name) { if ((fd = open(name.c_str(), O_RDONLY)) < 0) - throw SystemCallException(std::string("open ") + name, errno, THROW_ARGS); + THROW_SYSCALL(std::string("open ") + name); } FileStream::FileStream(const std::string &name, int mode) { if ((fd = open(name.c_str(), O_RDWR | O_CREAT | O_TRUNC, mode)) < 0) - throw SystemCallException(std::string("open ") + name, errno, THROW_ARGS); + THROW_SYSCALL(std::string("open ") + name); } FileStream::FileStream(const std::string &name, int flags, int mode) { if ((fd = open(name.c_str(), flags, mode)) < 0) - throw SystemCallException(std::string("open ") + name, errno, THROW_ARGS); + THROW_SYSCALL(std::string("open ") + name); } FileStream::~FileStream() @@ -65,7 +65,7 @@ void FileStream::skip(size_t bytes) errno = 0; if (lseek(fd, bytes, SEEK_CUR) == (off_t)-1 && errno) - throw SystemCallException("lseek", errno, THROW_ARGS); + THROW_SYSCALL("lseek"); } size_t FileStream::size() @@ -73,7 +73,7 @@ size_t FileStream::size() struct stat st; if (::fstat(fd, &st) != 0) - throw SystemCallException("fstat", errno, THROW_ARGS); + THROW_SYSCALL("fstat"); return (size_t)st.st_size; } diff --git a/LCS/Stream/src/NamedPipeStream.cc b/LCS/Stream/src/NamedPipeStream.cc index a3b3dffea44..d5fb1ccdedc 100644 --- a/LCS/Stream/src/NamedPipeStream.cc +++ b/LCS/Stream/src/NamedPipeStream.cc @@ -43,10 +43,10 @@ NamedPipeStream::NamedPipeStream(const char *name, bool serverSide) { try { if (mknod(itsReadName.c_str(), 0600 | S_IFIFO, 0) < 0 && errno != EEXIST) - throw SystemCallException(std::string("mknod ") + itsReadName, errno, THROW_ARGS); + THROW_SYSCALL(std::string("mknod ") + itsReadName); if (mknod(itsWriteName.c_str(), 0600 | S_IFIFO, 0) < 0 && errno != EEXIST) - throw SystemCallException(std::string("mknod ") + itsWriteName, errno, THROW_ARGS); + THROW_SYSCALL(std::string("mknod ") + itsWriteName); itsReadStream = new FileStream(itsReadName.c_str(), O_RDWR, 0600); // strange; O_RDONLY hangs ??? itsWriteStream = new FileStream(itsWriteName.c_str(), O_RDWR, 0600); diff --git a/LCS/Stream/src/SocketStream.cc b/LCS/Stream/src/SocketStream.cc index 49781f28e3b..7da18c7c18d 100644 --- a/LCS/Stream/src/SocketStream.cc +++ b/LCS/Stream/src/SocketStream.cc @@ -106,7 +106,7 @@ SocketStream::SocketStream(const std::string &hostname, uint16 _port, Protocol p snprintf(portStr, sizeof portStr, "%hu", port); if ((retval = getaddrinfo(hostname.c_str(), portStr, &hints, &result)) != 0) - throw SystemCallException("getaddrinfo", retval, THROW_ARGS); + throw SystemCallException("getaddrinfo", retval, THROW_ARGS); // TODO: getaddrinfo does not return errno; needs gai_strerror() to stringify // make sure result will be freed struct D { @@ -121,7 +121,7 @@ SocketStream::SocketStream(const std::string &hostname, uint16 _port, Protocol p // result is a linked list of resolved addresses, we only use the first if ((fd = socket(result->ai_family, result->ai_socktype, result->ai_protocol)) < 0) - throw SystemCallException("socket", errno, THROW_ARGS); + THROW_SYSCALL("socket"); if (mode == Client) { while (connect(fd, result->ai_addr, result->ai_addrlen) < 0) @@ -133,18 +133,18 @@ SocketStream::SocketStream(const std::string &hostname, uint16 _port, Protocol p // interrupted by a signal handler -- abort to allow this thread to // be forced to continue after receiving a SIGINT, as with any other // system call in this constructor - throw SystemCallException("sleep", errno, THROW_ARGS); + THROW_SYSCALL("sleep"); } } else - throw SystemCallException("connect", errno, THROW_ARGS); + THROW_SYSCALL("connect"); } else { int on = 1; if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof on) < 0) - throw SystemCallException("setsockopt(SO_REUSEADDR)", errno, THROW_ARGS); + THROW_SYSCALL("setsockopt(SO_REUSEADDR)"); if (bind(fd, result->ai_addr, result->ai_addrlen) < 0) - throw SystemCallException("bind", errno, THROW_ARGS); + THROW_SYSCALL("bind"); if (protocol == TCP) { listen_sk = fd; @@ -152,7 +152,7 @@ SocketStream::SocketStream(const std::string &hostname, uint16 _port, Protocol p int listenBacklog = 15; if (listen(listen_sk, listenBacklog) < 0) - throw SystemCallException("listen", errno, THROW_ARGS); + THROW_SYSCALL("listen"); if (doAccept) accept(deadline); @@ -192,7 +192,7 @@ SocketStream::~SocketStream() // backtrace if available, and the proper representation // of exceptions in general. try { - throw SystemCallException("close listen_sk", errno, THROW_ARGS); + THROW_SYSCALL("close listen_sk"); } catch (Exception &ex) { LOG_ERROR_STR("Exception in destructor: " << ex); } @@ -217,7 +217,7 @@ void SocketStream::reaccept(time_t deadline) ASSERT( mode == Server ); if (fd >= 0 && close(fd) < 0) - throw SystemCallException("close", errno, THROW_ARGS); + THROW_SYSCALL("close"); accept(deadline); } @@ -263,14 +263,14 @@ void SocketStream::accept(time_t deadline) timeval.tv_usec = 0; switch (select(listen_sk + 1, &fds, 0, 0, &timeval)) { - case -1 : throw SystemCallException("select", errno, THROW_ARGS); + case -1 : THROW_SYSCALL("select"); case 0 : THROW(TimeOutException, "server socket"); } } if ((fd = ::accept(listen_sk, 0, 0)) < 0) - throw SystemCallException("accept", errno, THROW_ARGS); + THROW_SYSCALL("accept"); } @@ -287,13 +287,13 @@ void SocketStream::syncNFS() DIR *dir = opendir("."); if (!dir) - throw SystemCallException("opendir", errno, THROW_ARGS); + THROW_SYSCALL("opendir"); if (!readdir(dir)) - throw SystemCallException("readdir", errno, THROW_ARGS); + THROW_SYSCALL("readdir"); if (closedir(dir) != 0) - throw SystemCallException("closedir", errno, THROW_ARGS); + THROW_SYSCALL("closedir"); } @@ -319,7 +319,7 @@ std::string SocketStream::readkey(const std::string &nfskey, time_t deadline) // interrupted by a signal handler -- abort to allow this thread to // be forced to continue after receiving a SIGINT, as with any other // system call - throw SystemCallException("sleep", errno, THROW_ARGS); + THROW_SYSCALL("sleep"); } } } @@ -332,7 +332,7 @@ void SocketStream::writekey(const std::string &nfskey, uint16 port) // Symlinks can be atomically created over NFS if (symlink(portStr, nfskey.c_str()) < 0) - throw SystemCallException("symlink", errno, THROW_ARGS); + THROW_SYSCALL("symlink"); } void SocketStream::deletekey(const std::string &nfskey) @@ -340,7 +340,7 @@ void SocketStream::deletekey(const std::string &nfskey) syncNFS(); if (unlink(nfskey.c_str()) < 0) - throw SystemCallException("unlink", errno, THROW_ARGS); + THROW_SYSCALL("unlink"); } } // namespace LOFAR diff --git a/RTCP/Cobalt/GPUProc/src/Storage/StorageProcess.cc b/RTCP/Cobalt/GPUProc/src/Storage/StorageProcess.cc index bf8bbc1202c..2c038a2190a 100644 --- a/RTCP/Cobalt/GPUProc/src/Storage/StorageProcess.cc +++ b/RTCP/Cobalt/GPUProc/src/Storage/StorageProcess.cc @@ -122,7 +122,7 @@ namespace LOFAR char cwd[1024]; if (getcwd(cwd, sizeof cwd) == 0) - throw SystemCallException("getcwd", errno, THROW_ARGS); + THROW_SYSCALL("getcwd"); std::string commandLine = str(boost::format("cd %s && %s%s %u %d %u") % cwd diff --git a/RTCP/Cobalt/GPUProc/src/Storage/StorageProcesses.cc b/RTCP/Cobalt/GPUProc/src/Storage/StorageProcesses.cc index 769471cdb99..8b8548eabbe 100644 --- a/RTCP/Cobalt/GPUProc/src/Storage/StorageProcesses.cc +++ b/RTCP/Cobalt/GPUProc/src/Storage/StorageProcesses.cc @@ -109,7 +109,7 @@ namespace LOFAR char cwd[1024]; if (getcwd(cwd, sizeof cwd) == 0) - throw SystemCallException("getcwd", errno, THROW_ARGS); + THROW_SYSCALL("getcwd"); std::string commandLine = str(boost::format("cd %s && %s %d 2>&1") % cwd diff --git a/RTCP/Cobalt/GPUProc/src/cuda/gpu_utils.cc b/RTCP/Cobalt/GPUProc/src/cuda/gpu_utils.cc index bd079a13b52..e1a203f10c1 100644 --- a/RTCP/Cobalt/GPUProc/src/cuda/gpu_utils.cc +++ b/RTCP/Cobalt/GPUProc/src/cuda/gpu_utils.cc @@ -249,9 +249,8 @@ namespace LOFAR string ptx; char buffer [1024]; FILE * stream = popen(cmd.c_str(), "r"); - if (!stream) { - throw SystemCallException("popen", errno, THROW_ARGS); + THROW_SYSCALL("popen"); } while (!feof(stream)) { // NOTE: We do not get stderr if (fgets(buffer, sizeof buffer, stream) != NULL) { diff --git a/RTCP/Cobalt/InputProc/src/Buffer/SharedMemory.cc b/RTCP/Cobalt/InputProc/src/Buffer/SharedMemory.cc index 10547096b8b..5baf246a697 100644 --- a/RTCP/Cobalt/InputProc/src/Buffer/SharedMemory.cc +++ b/RTCP/Cobalt/InputProc/src/Buffer/SharedMemory.cc @@ -123,7 +123,7 @@ namespace LOFAR throw TimeOutException("shared memory", THROW_ARGS); if (usleep(999999) < 0) - throw SystemCallException("sleep", errno, THROW_ARGS); + THROW_SYSCALL("usleep"); } } @@ -137,14 +137,13 @@ namespace LOFAR preexisting = (shmget(key, 0, 0) >= 0 || errno != ENOENT); shmid = shmget( key, itsSize, open_flags ); - if (shmid == -1) { // No timeout means we're not keeping silent about ENOENT/ENOEXIST if (!timeout) - throw SystemCallException("shmget", errno, THROW_ARGS); + THROW_SYSCALL("shmget"); if (errno != ENOENT && errno != EEXIST) - throw SystemCallException("shmget", errno, THROW_ARGS); + THROW_SYSCALL("shmget"); } else { // attach to segment itsBegin = shmat( shmid, NULL, attach_flags ); @@ -152,15 +151,13 @@ namespace LOFAR if (itsBegin != (void*)-1) return true; // success! - int saved_errno = errno; - if (!preexisting) { // we created the buffer, so erase it before continuing if (shmctl(shmid, IPC_RMID, NULL) < 0) - throw SystemCallException("shmctl", errno, THROW_ARGS); + THROW_SYSCALL("shmctl"); } - throw SystemCallException("shmat", saved_errno, THROW_ARGS); + THROW_SYSCALL("shmat"); } return false; @@ -204,7 +201,7 @@ namespace LOFAR // so getting EINVAL is a possibility. if (shmctl(shmid, IPC_RMID, NULL) < 0 && errno != EINVAL) // failed to remove SHM - throw SystemCallException("shmctl", errno, THROW_ARGS); + THROW_SYSCALL("shmctl"); // key existed, SHM removed } @@ -215,12 +212,12 @@ namespace LOFAR try { // detach if (shmdt(itsBegin) < 0) - throw SystemCallException("shmdt", errno, THROW_ARGS); + THROW_SYSCALL("shmdt"); // destroy if (!preexisting && (mode == CREATE || mode == CREATE_EXCL)) if (shmctl(shmid, IPC_RMID, NULL) < 0) - throw SystemCallException("shmctl", errno, THROW_ARGS); + THROW_SYSCALL("shmctl"); } catch (Exception &ex) { LOG_ERROR_STR("Exception in destructor: " << ex); diff --git a/RTCP/Cobalt/InputProc/src/OMPThread.h b/RTCP/Cobalt/InputProc/src/OMPThread.h index 7890b678587..d3e1899b286 100644 --- a/RTCP/Cobalt/InputProc/src/OMPThread.h +++ b/RTCP/Cobalt/InputProc/src/OMPThread.h @@ -77,9 +77,11 @@ namespace LOFAR // once it has been set. pthread_t oldid = id; - if (oldid > 0) - if (pthread_kill(oldid, SIGHUP) < 0) - throw SystemCallException("pthread_kill", errno, THROW_ARGS); + if (oldid > 0) { + int error = pthread_kill(oldid, SIGHUP); + if (error != 0) + throw SystemCallException("pthread_kill", error, THROW_ARGS); + } // sleep for 100ms - do NOT let us get killed here, // because we're maintaining integrity diff --git a/RTCP/Cobalt/InputProc/src/obsolete/Poll.h b/RTCP/Cobalt/InputProc/src/obsolete/Poll.h index fa06bd90b92..18cc537bde4 100644 --- a/RTCP/Cobalt/InputProc/src/obsolete/Poll.h +++ b/RTCP/Cobalt/InputProc/src/obsolete/Poll.h @@ -51,7 +51,7 @@ Poll::Poll() fd = epoll_create1(EPOLL_CLOEXEC); if( fd == -1 ) - throw SystemCallException("epoll_create1", errno, THROW_ARGS); + THROW_SYSCALL("epoll_create1"); } void Poll::add( FileDescriptorBasedStream *s, bool reading, bool writing ) @@ -63,7 +63,7 @@ void Poll::add( FileDescriptorBasedStream *s, bool reading, bool writing ) ev.data.ptr = s; if (epoll_ctl(fd, EPOLL_CTL_ADD, s->fd, &ev) == -1) - throw SystemCallException("epoll_ctl", errno, THROW_ARGS); + THROW_SYSCALL("epoll_ctl"); } void Poll::remove( FileDescriptorBasedStream *s ) @@ -73,7 +73,7 @@ void Poll::remove( FileDescriptorBasedStream *s ) struct epoll_event ev; if (epoll_ctl(fd, EPOLL_CTL_DEL, s->fd, &ev) == -1) - throw SystemCallException("epoll_ctl", errno, THROW_ARGS); + THROW_SYSCALL("epoll_ctl"); } std::vector<FileDescriptorBasedStream *> Poll::poll( int timeout_ms, size_t maxevents ) @@ -87,7 +87,7 @@ std::vector<FileDescriptorBasedStream *> Poll::poll( int timeout_ms, size_t maxe nfds = epoll_wait(fd, &events[0], events.size(), timeout_ms ); if (nfds == -1) - throw SystemCallException("epoll_wait", errno, THROW_ARGS); + THROW_SYSCALL("epoll_wait"); std::vector<FileDescriptorBasedStream *> result(nfds, 0); diff --git a/RTCP/Cobalt/OutputProc/src/ExitOnClosedStdin.cc b/RTCP/Cobalt/OutputProc/src/ExitOnClosedStdin.cc index ac8e9d17394..24c80204ce3 100644 --- a/RTCP/Cobalt/OutputProc/src/ExitOnClosedStdin.cc +++ b/RTCP/Cobalt/OutputProc/src/ExitOnClosedStdin.cc @@ -65,7 +65,7 @@ namespace LOFAR timeval.tv_usec = 0; switch (select(1, &fds, 0, 0, &timeval)) { - case -1: throw SystemCallException("select", errno, THROW_ARGS); + case -1: THROW_SYSCALL("select"); case 0: continue; } @@ -79,7 +79,7 @@ namespace LOFAR } else { // slow down reading data (IONProc will be spamming us with /dev/zero) if (usleep(999999) < 0) - throw SystemCallException("usleep", errno, THROW_ARGS); + THROW_SYSCALL("usleep"); } } } diff --git a/RTCP/Cobalt/OutputProc/src/FastFileStream.cc b/RTCP/Cobalt/OutputProc/src/FastFileStream.cc index 74441847dbc..7398ee58ea4 100644 --- a/RTCP/Cobalt/OutputProc/src/FastFileStream.cc +++ b/RTCP/Cobalt/OutputProc/src/FastFileStream.cc @@ -64,12 +64,12 @@ namespace LOFAR // lseek can return -1 as a valid file position, so check errno as well if (curlen == (off_t)-1 && errno) - throw SystemCallException("lseek", errno, THROW_ARGS); + THROW_SYSCALL("lseek"); writeRemainder(); if (ftruncate(fd, curlen + origremainder) < 0) - throw SystemCallException("ftruncate", errno, THROW_ARGS); + THROW_SYSCALL("ftruncate"); } catch (Exception &ex) { LOG_ERROR_STR("Exception in destructor: " << ex); } @@ -211,7 +211,7 @@ namespace LOFAR // lseek can return -1 as a valid file position, so check errno as well if (curlen == (off_t)-1 && errno) - throw SystemCallException("lseek", errno, THROW_ARGS); + THROW_SYSCALL("lseek"); return curlen + remainder; } diff --git a/RTCP/Cobalt/OutputProc/src/OutputThread.cc b/RTCP/Cobalt/OutputProc/src/OutputThread.cc index c12de780ff2..66f291dba4c 100644 --- a/RTCP/Cobalt/OutputProc/src/OutputThread.cc +++ b/RTCP/Cobalt/OutputProc/src/OutputThread.cc @@ -71,13 +71,11 @@ namespace LOFAR LOG_DEBUG_STR(logPrefix << "Creating directory " << dirname); if (mkdir(dirname.c_str(), 0777) != 0 && errno != EEXIST) { - unsigned savedErrno = errno; // first argument below clears errno - throw SystemCallException(string("mkdir ") + dirname, savedErrno, THROW_ARGS); + THROW_SYSCALL(string("mkdir ") + dirname); } } else { // something else went wrong - unsigned savedErrno = errno; // first argument below clears errno - throw SystemCallException(string("stat ") + dirname, savedErrno, THROW_ARGS); + THROW_SYSCALL(string("stat ") + dirname); } } diff --git a/RTCP/Cobalt/OutputProc/src/TBB_Writer.cc b/RTCP/Cobalt/OutputProc/src/TBB_Writer.cc index 0b4aa17c59a..8b43fb0f266 100644 --- a/RTCP/Cobalt/OutputProc/src/TBB_Writer.cc +++ b/RTCP/Cobalt/OutputProc/src/TBB_Writer.cc @@ -96,7 +96,7 @@ namespace LOFAR { ssize_t bytes = ::pwrite(fd, ptr, size, offset); if (bytes < 0) - throw SystemCallException("pwrite", errno, THROW_ARGS); + THROW_SYSCALL("pwrite"); return bytes; } diff --git a/RTCP/Cobalt/OutputProc/src/TBB_Writer_main.cc b/RTCP/Cobalt/OutputProc/src/TBB_Writer_main.cc index 324b10ad1cb..cbe19a0b467 100644 --- a/RTCP/Cobalt/OutputProc/src/TBB_Writer_main.cc +++ b/RTCP/Cobalt/OutputProc/src/TBB_Writer_main.cc @@ -295,7 +295,7 @@ static int doTBB_Run(const vector<string>& inputStreamNames, const LOFAR::Cobalt */ struct itimerval timer = {args.timeoutVal, args.timeoutVal}; if (setitimer(ITIMER_REAL, &timer, NULL) != 0) { - throw LOFAR::SystemCallException("setitimer", errno, THROW_ARGS); + THROW_SYSCALL("setitimer"); } bool anyFrameReceived = false; // don't quit if there is no data immediately after starting diff --git a/RTCP/IONProc/src/StorageProcesses.cc b/RTCP/IONProc/src/StorageProcesses.cc index e85af02ead8..c496d2beec1 100644 --- a/RTCP/IONProc/src/StorageProcesses.cc +++ b/RTCP/IONProc/src/StorageProcesses.cc @@ -61,7 +61,7 @@ void StorageProcess::start() char cwd[1024]; if (getcwd(cwd, sizeof cwd) == 0) - throw SystemCallException("getcwd", errno, THROW_ARGS); + THROW_SYSCALL("getcwd"); std::string commandLine = str(boost::format("cd %s && %s%s %u %d %u 2>&1") % cwd @@ -221,7 +221,7 @@ void StorageProcesses::finalMetaDataThread() char cwd[1024]; if (getcwd(cwd, sizeof cwd) == 0) - throw SystemCallException("getcwd", errno, THROW_ARGS); + THROW_SYSCALL("getcwd"); std::string commandLine = str(boost::format("cd %s && %s %d 2>&1") % cwd diff --git a/RTCP/Storage/src/ExitOnClosedStdin.cc b/RTCP/Storage/src/ExitOnClosedStdin.cc index f6d8027de96..6c29df95638 100644 --- a/RTCP/Storage/src/ExitOnClosedStdin.cc +++ b/RTCP/Storage/src/ExitOnClosedStdin.cc @@ -38,7 +38,7 @@ void ExitOnClosedStdin::mainLoop() timeval.tv_usec = 0; switch (select(1, &fds, 0, 0, &timeval)) { - case -1 : throw SystemCallException("select", errno, THROW_ARGS); + case -1 : THROW_SYSCALL("select"); case 0 : continue; } @@ -52,7 +52,7 @@ void ExitOnClosedStdin::mainLoop() } else { // slow down reading data (IONProc will be spamming us with /dev/zero) if (usleep(999999) < 0) - throw SystemCallException("usleep", errno, THROW_ARGS); + THROW_SYSCALL("usleep"); } } } diff --git a/RTCP/Storage/src/FastFileStream.cc b/RTCP/Storage/src/FastFileStream.cc index 690cf3a660b..36ef93a7988 100644 --- a/RTCP/Storage/src/FastFileStream.cc +++ b/RTCP/Storage/src/FastFileStream.cc @@ -64,12 +64,12 @@ FastFileStream::~FastFileStream() // lseek can return -1 as a valid file position, so check errno as well if (curlen == (off_t)-1 && errno) - throw SystemCallException("lseek", errno, THROW_ARGS); + THROW_SYSCALL("lseek"); writeRemainder(); if (ftruncate(fd, curlen + origremainder) < 0) - throw SystemCallException("ftruncate", errno, THROW_ARGS); + THROW_SYSCALL("ftruncate"); } catch (Exception &ex) { LOG_ERROR_STR("Exception in destructor: " << ex); } @@ -211,7 +211,7 @@ size_t FastFileStream::size() // lseek can return -1 as a valid file position, so check errno as well if (curlen == (off_t)-1 && errno) - throw SystemCallException("lseek", errno, THROW_ARGS); + THROW_SYSCALL("lseek"); return curlen + remainder; } diff --git a/RTCP/Storage/src/OutputThread.cc b/RTCP/Storage/src/OutputThread.cc index c348e5b5b23..a45c982c463 100644 --- a/RTCP/Storage/src/OutputThread.cc +++ b/RTCP/Storage/src/OutputThread.cc @@ -68,13 +68,11 @@ static void makeDir(const string &dirname, const string &logPrefix) LOG_DEBUG_STR(logPrefix << "Creating directory " << dirname); if (mkdir(dirname.c_str(), 0777) != 0 && errno != EEXIST) { - unsigned savedErrno = errno; // first argument below clears errno - throw SystemCallException(string("mkdir ") + dirname, savedErrno, THROW_ARGS); + THROW_SYSCALL(string("mkdir ") + dirname); } } else { // something else went wrong - unsigned savedErrno = errno; // first argument below clears errno - throw SystemCallException(string("stat ") + dirname, savedErrno, THROW_ARGS); + THROW_SYSCALL(string("stat ") + dirname); } } diff --git a/RTCP/Storage/src/TBB_Writer.cc b/RTCP/Storage/src/TBB_Writer.cc index 3627d97a98f..95227d4f335 100644 --- a/RTCP/Storage/src/TBB_Writer.cc +++ b/RTCP/Storage/src/TBB_Writer.cc @@ -93,7 +93,7 @@ static string formatFilenameTimestamp(const struct timeval& tv, const char* outp static size_t tryPWrite(int fd, const void *ptr, size_t size, off_t offset) { ssize_t bytes = ::pwrite(fd, ptr, size, offset); if (bytes < 0) - throw SystemCallException("pwrite", errno, THROW_ARGS); + THROW_SYSCALL("pwrite"); return bytes; } diff --git a/RTCP/Storage/src/TBB_Writer_main.cc b/RTCP/Storage/src/TBB_Writer_main.cc index 2776fb3fd57..1eb69712a44 100644 --- a/RTCP/Storage/src/TBB_Writer_main.cc +++ b/RTCP/Storage/src/TBB_Writer_main.cc @@ -282,7 +282,7 @@ static int doTBB_Run(const vector<string>& inputStreamNames, const LOFAR::RTCP:: */ struct itimerval timer = {args.timeoutVal, args.timeoutVal}; if (setitimer(ITIMER_REAL, &timer, NULL) != 0) { - throw LOFAR::SystemCallException("setitimer", errno, THROW_ARGS); + THROW_SYSCALL("setitimer"); } bool anyFrameReceived = false; // don't quit if there is no data immediately after starting -- GitLab