return std::error_code(errnum, errno_category());
}
+/** Create an `error_code` from `errno` (and clear it) */
+inline
+std::error_code errno_code()
+{
+ int errnum = errno;
+ errno = 0;
+ return errno_code(errnum);
+}
+
/** Create a `system_error` from an `errno` value
*
* This is expected to to whatever is right to create a
return std::system_error(errno_code(errnum), what);
}
+/** Create a `system_code` from `errno` (and clear it) */
+inline
+std::system_error errno_error()
+{
+ return std::system_error(errno_code());
+}
+
+inline
+std::system_error errno_error(const char* what)
+{
+ return std::system_error(errno_code(), what);
+}
+
}
}
sigemptyset(&set);
sigaddset(&set, SIGCHLD);
if (sigprocmask(SIG_BLOCK, &set, nullptr) == -1)
- throw simgrid::xbt::errno_error(errno);
+ throw simgrid::xbt::errno_error();
sigset_t full_set;
sigfillset(&full_set);
int signal_fd = signalfd(-1, &set, 0);
if (signal_fd == -1)
- throw simgrid::xbt::errno_error(errno);
+ throw simgrid::xbt::errno_error();
struct pollfd* signalfd_pollfd = &fds_[SIGNAL_FD_INDEX];
signalfd_pollfd->fd = signal_fd;
{
int res = process.getChannel().send(MC_MESSAGE_CONTINUE);
if (res)
- throw simgrid::xbt::errno_error(res);
+ throw simgrid::xbt::errno_error();
process.clear_cache();
}
socklen_t errlen = sizeof(error);
if (getsockopt(fd, SOL_SOCKET, SO_ERROR, (void *)&error, &errlen) == -1)
error = errno;
- throw simgrid::xbt::errno_error(errno);
+ throw simgrid::xbt::errno_error();
}
static void MC_report_crash(int status)
case EINTR:
continue;
default:
- throw simgrid::xbt::errno_error(errno);
+ throw simgrid::xbt::errno_error();
}
}
if (socket_pollfd->revents & POLLIN) {
ssize_t size = process_->getChannel().receive(buffer, sizeof(buffer), false);
if (size == -1 && errno != EAGAIN)
- throw simgrid::xbt::errno_error(errno);
+ throw simgrid::xbt::errno_error();
return handle_message(buffer, size);
}
if (socket_pollfd->revents & POLLERR)
if (errno == EINTR)
continue;
else
- throw simgrid::xbt::errno_error(errno);
+ throw simgrid::xbt::errno_error();
} 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 simgrid::xbt::errno_error(errno);
+ throw simgrid::xbt::errno_error();
}
}
sigset_t mask;
sigemptyset (&mask);
if (sigprocmask(SIG_SETMASK, &mask, nullptr) < 0)
- throw simgrid::xbt::errno_error(errno, "Could not unblock signals");
+ throw simgrid::xbt::errno_error("Could not unblock signals");
if (prctl(PR_SET_PDEATHSIG, SIGHUP) != 0)
- throw simgrid::xbt::errno_error(errno, "Could not PR_SET_PDEATHSIG");
+ throw simgrid::xbt::errno_error("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 || fcntl(socket, F_SETFD, fdflags & ~FD_CLOEXEC) == -1)
- throw simgrid::xbt::errno_error(errno, "Could not remove CLOEXEC for socket");
+ throw simgrid::xbt::errno_error("Could not remove CLOEXEC for socket");
// Set environment:
setenv(MC_ENV_VARIABLE, "1", 1);
{
pid_t pid = fork();
if (pid < 0)
- throw simgrid::xbt::errno_error(errno, "Could not fork model-checked process");
+ throw simgrid::xbt::errno_error("Could not fork model-checked process");
if (pid != 0)
return pid;
int sockets[2];
res = socketpair(AF_LOCAL, SOCK_DGRAM | SOCK_CLOEXEC, 0, sockets);
if (res == -1)
- throw simgrid::xbt::errno_error(errno, "Could not create socketpair");
+ throw simgrid::xbt::errno_error("Could not create socketpair");
pid_t pid = do_fork([&] {
::close(sockets[1]);