--- /dev/null
+/* Copyright (c) 2016. The SimGrid Team.
+ * All rights reserved. */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+#include <cerrno>
+
+#include <system_error>
+
+namespace simgrid {
+namespace xbt {
+
+inline
+const std::error_category& errno_category() noexcept
+{
+ return std::generic_category();
+}
+
+inline
+std::system_error errno_error(int errnum) noexcept
+{
+ return std::system_error(errnum, errno_category());
+}
+
+inline
+std::system_error errno_error(int errno, const char* what)
+{
+ return std::system_error(errnum, errno_category(), what);
+}
+
+}
+}
#include <xbt/log.h>
#include <xbt/automaton.h>
#include <xbt/automaton.hpp>
+#include <xbt/system_error.hpp>
#include "simgrid/sg_config.h"
sigemptyset(&set);
sigaddset(&set, SIGCHLD);
if (sigprocmask(SIG_BLOCK, &set, nullptr) == -1)
- throw std::system_error(errno, std::system_category());
+ throw simgrid::xbt::errno_error(errno);
sigset_t full_set;
sigfillset(&full_set);
int signal_fd = signalfd(-1, &set, 0);
if (signal_fd == -1)
- throw std::system_error(errno, std::system_category());
+ throw simgrid::xbt::errno_error(errno);
struct pollfd* signalfd_pollfd = &fds_[SIGNAL_FD_INDEX];
signalfd_pollfd->fd = signal_fd;
{
int res = process.send_message(MC_MESSAGE_CONTINUE);
if (res)
- throw std::system_error(res, std::system_category());
+ throw simgrid::xbt::errno_error(res);
process.cache_flags = (mc_process_cache_flags_t) 0;
}
socklen_t errlen = sizeof(error);
if (getsockopt(fd, SOL_SOCKET, SO_ERROR, (void *)&error, &errlen) == -1)
error = errno;
- throw std::system_error(error, std::system_category());
+ throw simgrid::xbt::errno_error(errno);
}
bool ModelChecker::handle_message(char* buffer, ssize_t size)
case EINTR:
continue;
default:
- throw std::system_error(errno, std::system_category());
+ throw simgrid::mc::errno_error(errno);
}
}
if (socket_pollfd->revents & POLLIN) {
ssize_t size = MC_receive_message(socket_pollfd->fd, buffer, sizeof(buffer), MSG_DONTWAIT);
if (size == -1 && errno != EAGAIN)
- throw std::system_error(errno, std::system_category());
+ throw simgrid::mc::errno_error(errno);
return handle_message(buffer, size);
}
if (socket_pollfd->revents & POLLERR) {
if (errno == EINTR)
continue;
else
- throw std::system_error(errno, std::system_category());
+ throw simgrid::mc::errno_error(errno);
} else if (size != sizeof(info))
return throw std::runtime_error(
"Bad communication with model-checked application");
break;
} else {
XBT_ERROR("Could not wait for pid");
- throw std::system_error(errno, std::system_category());
+ throw simgrid::mc::errno_error(errno);
}
}
{
pid_t pid = fork();
if (pid < 0)
- throw new std::system_error(errno, std::generic_category());
+ throw simgrid::mc::errno_error(errno, "Could not fork model-checked process");
if (pid != 0)
return pid;
sigset_t mask;
sigemptyset (&mask);
if (sigprocmask(SIG_SETMASK, &mask, nullptr) < 0)
- throw new std::system_error(errno, std::generic_category(), "sigprocmask");
+ throw simgrid::mc::errno_error(errno, "Could not unblock signals");
if (prctl(PR_SET_PDEATHSIG, SIGHUP) != 0)
- throw new std::system_error(errno, std::generic_category(), "PR_SET_PDEATHSIG");
+ throw simgrid::mc::errno_error(errno, "Could not PR_SET_PDEATHSIG");
#endif
int res;
// Remove CLOEXEC in order to pass the socket to the exec-ed program:
int fdflags = fcntl(socket, F_GETFD, 0);
- if (fdflags == -1)
- throw new std::system_error(errno, std::generic_category(), "F_GETFD");
- if (fcntl(socket, F_SETFD, fdflags & ~FD_CLOEXEC) == -1)
- throw new std::system_error(errno, std::generic_category(), "Remove FD_CLOEXEC");
+ if (fdflags == -1 || fcntl(socket, F_SETFD, fdflags & ~FD_CLOEXEC) == -1)
+ throw simgrid::xbt::system_error(errno, "Could not remove CLOEXEC for socket");
// Set environment:
setenv(MC_ENV_VARIABLE, "1", 1);
int sockets[2];
res = socketpair(AF_LOCAL, SOCK_DGRAM | SOCK_CLOEXEC, 0, sockets);
if (res == -1)
- throw new std::system_error(errno, std::generic_category(), "socketpair");
+ throw simgrid::xbt::system_error(errno, "Could not create socketpair");
pid_t pid = do_fork([&] {
close(sockets[1]);