diff --git a/LCS/Common/include/Common/Exception.h b/LCS/Common/include/Common/Exception.h index 89eeda3e9df6606ac50fdc2de63f284f7ca5da52..7a0cd139f5c482666d677df449fa194f657281cc 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 6d034915924431e266892c946819ad77e7920d8c..f2b2593dc02a17af8a63e7caf916d8316d01be19 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 3cb183c1cccab86cc85cd017e4c818edbf9de45b..6f7e3bff851519fa70cd0a2ccd2715332fb8001b 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 aedf554753aee8e81a23a2ae575f1b8cfa7b74d2..bc2be0eab03807fe17e8572af14b2ee7aca6a2c7 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 bc7d4f6df6beb1001b82a1d47bf46310b45d9295..66133f11ad9eed2c3da8db89de004ce184c2dce8 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 a3b3dffea4483b9a3475fbc148c431beb3ffca26..d5fb1ccdedc4d9e7ed519cb1d1e19aafc7717633 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 49781f28e3bb4d2aeb03a4031c77ddd1c8c059b8..7da18c7c18d7066344e4321b16b47e39cb07a020 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 bf8bbc1202c6251370eda90daa50311edae2129b..2c038a2190a1919fca88a2b70084e250e742b339 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 769471cdb995202999c3056db86aef3d09ff889c..8b8548eabbeb89047bdc3f76b8959444b447a73b 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 bd079a13b52765012fb5a327a9ab9b6c517c83cc..e1a203f10c198856e39a46a55b500fc17266a119 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 10547096b8b50c973c97cb584b5a30fba6189f0d..5baf246a697b64a39fdbc66fc98467355469e3cc 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 7890b6785879075b8abc5d5c3b69ed00526ee81a..d3e1899b2866cb6043baf2db3c20a818ff7ed82f 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 fa06bd90b92b8bc6505372127842c46d1cd83d9a..18cc537bde48ec91120089e787eefad0f05965d6 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 ac8e9d173949803d7fecd21a6721821c99a1e782..24c80204ce3115f8c9ee81517f5c9a883db3fd87 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 74441847dbce674d93ce86b161a0c945acf79ff2..7398ee58ea452dec9c0ca05edb70b0cb894bb501 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 c12de780ff21fbfaaec12aee22760c0bcb7da262..66f291dba4ce7c594daa1864004609b65c9d5004 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 0b4aa17c59af7461e8d41430c9e92d0bdb291006..8b43fb0f266cc612ef8d3e8ac63cd2fadacf2d65 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 324b10ad1cb9e326b0dcbb5f499ab8edf7d68d3f..cbe19a0b467bf067892dd717536c998eaa204e3c 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 e85af02ead8c0b98b90923f7dc7881a844e04b4f..c496d2beec1d558e106b48f519dedbfb58dd2003 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 f6d8027de96b6d8035bae32833bfb27ba4a08dd9..6c29df95638f73d3c0bdb54db95150d5bc711cc4 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 690cf3a660b3ec792f97589a0903fd38a872f725..36ef93a798833afec691c97227cb6a5c21c5618f 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 c348e5b5b23b0426accd1beaa6c762d3b8e76541..a45c982c46363b5c64b641eaf181af87d4334541 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 3627d97a98f1bdaeb961e25051039afb4eb4a332..95227d4f335340f4e6474abad82eb247d97f4b3a 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 2776fb3fd5721c410483e808d6467019a008617c..1eb69712a4484bae18b7e049a5cd30d5aeb7a6cc 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