LxcException(const std::string& error) : VasumException(error) {}
};
+struct KeyNotFoundException: public LxcException {
+
+ KeyNotFoundException(const std::string& error) : LxcException(error) {}
+};
} // namespace vasum
{
mLxcContainer = lxc_container_new(zoneName.c_str(), lxcPath.c_str());
if (!mLxcContainer) {
- LOGE("Could not initialize lxc zone " << zoneName << " in path " << lxcPath);
- throw LxcException("Could not initialize lxc zone");
+ const std::string msg = "Could not initialize lxc zone " + zoneName + " in path " + lxcPath;
+ LOGE(msg);
+ throw LxcException(msg);
}
}
char buffer[1024];
int len = mLxcContainer->get_config_item(mLxcContainer, key.c_str(), buffer, sizeof(buffer));
if (len < 0) {
- LOGE("Key '" << key << "' not found in zone " << getName());
- throw LxcException("Key not found");
+ const std::string msg = "Key '" + key + "' not found in zone " + getName();
+ LOGE(msg);
+ throw KeyNotFoundException(msg);
}
return buffer;
}
{
const rtattr *rta = asAttr(get(RTA_LENGTH(0)));
if (rta->rta_type == ifla) {
- LOGE("Wrong attribute type, expected: " << ifla << ", got: " << rta->rta_type);
- throw VasumException("Wrong attribute type");
+ const std::string msg = "Wrong attribute type, expected: " + std::to_string(ifla) + ", got: " + std::to_string(rta->rta_type);
+ LOGE(msg);
+ throw VasumException(msg);
}
int pos = mPosition;
seek(RTA_LENGTH(0));
{
const rtattr *rta = asAttr(get(RTA_LENGTH(len < 0 ? 0 : len)));
if (rta->rta_type != ifla) {
- LOGE("Wrong attribute type, expected:" << ifla << ", got: " << rta->rta_type);
- throw VasumException("Wrong attribute type");
+ const std::string msg = "Wrong attribute type, expected: " + std::to_string(ifla) + ", got: " + std::to_string(rta->rta_type);
+ LOGE(msg);
+ throw VasumException(msg);
}
if (len >= 0 && rta->rta_len != RTA_LENGTH(len)) {
- LOGE("Wrong attribute length, expected: " << rta->rta_len << ", got " << len);
- throw VasumException("Wrong attribute length");
+ const std::string msg = "Wrong attribute length, expected: " + std::to_string(rta->rta_len) + ", got: " + std::to_string(len);
+ LOGE(msg);
+ throw VasumException(msg);
}
return reinterpret_cast<const char*>(RTA_DATA(get(rta->rta_len)));
}
{
int ret = sendmsg(fd, msg, flags);
if (ret < 0) {
- LOGE("Can't send message: " << getSystemErrorMessage());
- throw VasumException("Can't send netlink message");
+ const std::string msg = "Can't send netlink message: " + getSystemErrorMessage();
+ LOGE(msg);
+ throw VasumException(msg);
}
}
if (bind(mFd, (struct sockaddr *)&local, sizeof(local)) < 0) {
int err = errno;
close();
- LOGE("Can't bind to socket: " << getSystemErrorMessage(err));
- throw VasumException("Can't set up netlink connection");
+ const std::string msg = "Can't bind to socket: " + getSystemErrorMessage(err);
+ LOGE(msg);
+ throw VasumException(msg);
}
}
}
}
if (lastOk == NULL) {
- LOGE("Something went terribly wrong. Check vsm_recvmsg function");
- throw VasumException("Can't receive data from system");
+ const std::string msg = "Can't receive data from the system";
+ LOGE(msg);
+ throw VasumException(msg);
}
offset += NLMSG_ALIGN(ret);
} while (lastOk->nlmsg_type != NLMSG_DONE && lastOk->nlmsg_flags & NLM_F_MULTI);
{
mFD = ::eventfd(0, EFD_SEMAPHORE | EFD_CLOEXEC);
if (mFD == -1) {
- const std::string msg = getSystemErrorMessage();
- LOGE("Error in eventfd: " << msg);
- throw UtilsException("Error in eventfd: " + msg);
+ const std::string msg = "Error in eventfd: " + getSystemErrorMessage();
+ LOGE(msg);
+ throw UtilsException(msg);
}
}
UtilsException(const std::string& error) : std::runtime_error(error) {}
};
+struct ProvisionExistsException: public UtilsException {
+
+ ProvisionExistsException(const std::string& error) : UtilsException(error) {}
+};
+
/**
* Return string describing error number
* it is wrapper for strerror_r
if (errno == EINTR) {
continue;
}
- const std::string msg = getSystemErrorMessage();
- LOGE("Error in poll: " + msg);
- throw UtilsException("Error in poll: " + msg);
+ const std::string msg = "Error in poll: " + getSystemErrorMessage();
+ LOGE(msg);
+ throw UtilsException(msg);
}
if (ret == 0) {
- LOGE("Timeout in read");
- throw UtilsException("Timeout in read");
+ const std::string msg = "Timeout in read";
+ LOGE(msg);
+ throw UtilsException(msg);
}
if (fds[0].revents & event) {
}
if (fds[0].revents & POLLHUP) {
- LOGW("Peer disconnected");
- throw UtilsException("Peer disconnected");
+ const std::string msg = "Peer disconnected";
+ LOGW(msg);
+ throw UtilsException(msg);
}
}
}
// Neglected errors
LOGD("Retrying write");
} else {
- const std::string msg = getSystemErrorMessage();
- LOGE("Error during writing: " + msg);
- throw UtilsException("Error during writing: " + msg);
+ const std::string msg = "Error during writing: " + getSystemErrorMessage();
+ LOGE(msg);
+ throw UtilsException(msg);
}
waitForEvent(fd, POLLOUT, deadline);
break;
}
if (n == 0) {
- LOGW("Peer disconnected");
- throw UtilsException("Peer disconnected");
+ const std::string msg = "Peer disconnected";
+ LOGW(msg);
+ throw UtilsException(msg);
}
} else if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) {
// Neglected errors
LOGD("Retrying read");
} else {
- const std::string msg = getSystemErrorMessage();
- LOGE("Error during reading: " + msg);
- throw UtilsException("Error during reading: " + msg);
+ const std::string msg = "Error during reading: " + getSystemErrorMessage();
+ LOGE(msg);
+ throw UtilsException(msg);
}
waitForEvent(fd, POLLIN, deadline);
{
struct rlimit rlim;
if (-1 == getrlimit(RLIMIT_NOFILE, &rlim)) {
- const std::string msg = getSystemErrorMessage();
- LOGE("Error during getrlimit: " + msg);
- throw UtilsException("Error during getrlimit: " + msg);
+ const std::string msg = "Error during getrlimit: " + getSystemErrorMessage();
+ LOGE(msg);
+ throw UtilsException(msg);
}
return rlim.rlim_cur;
}
rlim.rlim_cur = limit;
rlim.rlim_max = limit;
if (-1 == setrlimit(RLIMIT_NOFILE, &rlim)) {
- const std::string msg = getSystemErrorMessage();
- LOGE("Error during setrlimit: " + msg);
- throw UtilsException("Error during setrlimit: " + msg);
+ const std::string msg = "Error during setrlimit: " + getSystemErrorMessage();
+ LOGE(msg);
+ throw UtilsException(msg);
}
}
{
int ret = ::pthread_sigmask(how, &set, nullptr /*&oldSet*/);
if(ret != 0) {
- const std::string msg = getSystemErrorMessage(ret);
- LOGE("Error in pthread_sigmask: " << msg);
- throw UtilsException("Error in pthread_sigmask: " + msg);
+ const std::string msg = "Error in pthread_sigmask: " + getSystemErrorMessage(ret);
+ LOGE(msg);
+ throw UtilsException(msg);
}
}
void changeSignal(int how, const int sigNum) {
::sigset_t set;
if(-1 == ::sigemptyset(&set)) {
- const std::string msg = getSystemErrorMessage();
- LOGE("Error in sigfillset: " << msg);
- throw UtilsException("Error in sigfillset: " + msg);
+ const std::string msg = "Error in sigfillset: " + getSystemErrorMessage();
+ LOGE(msg);
+ throw UtilsException(msg);
}
if(-1 ==::sigaddset(&set, sigNum)) {
- const std::string msg = getSystemErrorMessage();
- LOGE("Error in sigdelset: " << msg);
- throw UtilsException("Error in sigdelset: " + msg);
+ const std::string msg = "Error in sigdelset: " + getSystemErrorMessage();
+ LOGE(msg);
+ throw UtilsException(msg);
}
setSignalMask(how, set);
::sigset_t set;
int ret = ::pthread_sigmask(0 /*ignored*/, nullptr /*get the oldset*/, &set);
if(ret != 0) {
- const std::string msg = getSystemErrorMessage(ret);
- LOGE("Error in pthread_sigmask: " << msg);
- throw UtilsException("Error in pthread_sigmask: " + msg);
+ const std::string msg = "Error in pthread_sigmask: " + getSystemErrorMessage(ret);
+ LOGE(msg);
+ throw UtilsException(msg);
}
return set;
}
int ret = ::sigismember(&set, sigNum);
if(-1 == ret) {
- const std::string msg = getSystemErrorMessage();
- LOGE("Error in sigismember: " << msg);
- throw UtilsException("Error in sigismember: " + msg);
+ const std::string msg = "Error in sigismember: " + getSystemErrorMessage();
+ LOGE(msg);
+ throw UtilsException(msg);
}
return ret == 1;
{
::sigset_t set;
if(-1 == ::sigfillset(&set)) {
- const std::string msg = getSystemErrorMessage();
- LOGE("Error in sigfillset: " << msg);
- throw UtilsException("Error in sigfillset: " + msg);
+ const std::string msg = "Error in sigfillset: " + getSystemErrorMessage();
+ LOGE(msg);
+ throw UtilsException(msg);
}
for(const int s: signals) {
if(-1 == ::sigaddset(&set, s)) {
- const std::string msg = getSystemErrorMessage();
- LOGE("Error in sigaddset: " << msg);
- throw UtilsException("Error in sigaddset: " + msg);
+ const std::string msg = "Error in sigaddset: " + getSystemErrorMessage();
+ LOGE(msg);
+ throw UtilsException(msg);
}
}
setSignalMask(SIG_BLOCK, set);
for(const int s: signals) {
if(-1 == ::sigaction(s, &act, nullptr)) {
- const std::string msg = getSystemErrorMessage();
- LOGE("Error in sigaction: " << msg);
- throw UtilsException("Error in sigaction: " + msg);
+ const std::string msg = "Error in sigaction: " + getSystemErrorMessage();
+ LOGE(msg);
+ throw UtilsException(msg);
}
}
}
mFD = ::signalfd(-1, &set, SFD_CLOEXEC);
if (mFD == -1) {
- const std::string msg = getSystemErrorMessage();
- LOGE("Error in signalfd: " << msg);
- throw UtilsException("Error in signalfd: " + msg);
+ const std::string msg = "Error in signalfd: " + getSystemErrorMessage();
+ LOGE(msg);
+ throw UtilsException(msg);
}
mEventPoll.addFD(mFD, EPOLLIN, std::bind(&SignalFD::handleInternal, this));
int error = ::signalfd(mFD, &set, SFD_CLOEXEC);
if (error != mFD) {
- const std::string msg = getSystemErrorMessage();
- LOGE("Error in signalfd: " << msg);
- throw UtilsException("Error in signalfd: " + msg);
+ const std::string msg = "Error in signalfd: " + getSystemErrorMessage();
+ LOGE(msg);
+ throw UtilsException(msg);
}
mCallbacks.insert({sigNum, callback});
: mPollFD(::epoll_create1(EPOLL_CLOEXEC))
{
if (mPollFD == -1) {
- LOGE("Failed to create epoll: " << getSystemErrorMessage());
- throw UtilsException("Could not create epoll");
+ const std::string msg = "Failed to create epoll: " + getSystemErrorMessage();
+ LOGE(msg);
+ throw UtilsException(msg);
}
}
std::lock_guard<Mutex> lock(mMutex);
if (mCallbacks.find(fd) != mCallbacks.end()) {
- LOGE("Already added fd: " << fd);
- throw UtilsException("FD already added");
+ const std::string msg = "fd " + std::to_string(fd) + " already added";
+ LOGE(msg);
+ throw UtilsException(msg);
}
if (!addFDInternal(fd, events)) {
- LOGE("Could not add fd");
- throw UtilsException("Could not add fd");
+ const std::string msg = "Could not add fd";
+ LOGE(msg);
+ throw UtilsException(msg);
}
mCallbacks.insert({fd, std::make_shared<Callback>(std::move(callback))});
{
// No need to lock and check mCallbacks map
if (!modifyFDInternal(fd, events)) {
- LOGE("Could not modify fd: " << fd);
- throw UtilsException("Could not modify fd");
+ const std::string msg = "Could not modify fd: " + std::to_string(fd);
+ LOGE(msg);
+ throw UtilsException(msg);
}
}
if (errno == EINTR) {
continue;
}
- LOGE("Failed to wait on epoll: " << getSystemErrorMessage());
- throw UtilsException("Could not wait for event");
+ const std::string msg = "Failed to wait on epoll: " + getSystemErrorMessage();
+ LOGE(msg);
+ throw UtilsException(msg);
}
// callback could be removed in the meantime, so be careful, find it inside lock
Lock lock(mStateMutex);
mEventFD.receive();
if (mRequests.empty()) {
- LOGE("Request queue is empty");
- throw IPCException("Request queue is empty");
+ const std::string msg = "Request queue is empty";
+ LOGE(msg);
+ throw IPCException(msg);
}
Request request = std::move(mRequests.front());
mRequests.pop_front();
{
// Prevent from inheriting fd by zones
if (-1 == ::fcntl(fd, F_SETFD, FD_CLOEXEC)) {
- const std::string msg = getSystemErrorMessage();
- LOGE("Error in fcntl: " + msg);
- throw IPCException("Error in fcntl: " + msg);
+ const std::string msg = "Error in fcntl: " + getSystemErrorMessage();
+ LOGE(msg);
+ throw IPCException(msg);
}
}
{
int sockfd = ::accept(mFD, nullptr, nullptr);
if (sockfd == -1) {
- const std::string msg = getSystemErrorMessage();
- LOGE("Error in accept: " << msg);
- throw IPCException("Error in accept: " + msg);
+ const std::string msg = "Error in accept: " + getSystemErrorMessage();
+ LOGE(msg);
+ throw IPCException(msg);
}
setFdOptions(sockfd);
return std::make_shared<Socket>(sockfd);
{
int n = ::sd_listen_fds(-1 /*Block further calls to sd_listen_fds*/);
if (n < 0) {
- LOGE("sd_listen_fds fails with errno: " << n);
- throw IPCException("sd_listen_fds fails with errno: " + std::to_string(n));
+ const std::string msg = "sd_listen_fds failed: " + getSystemErrorMessage(-n);
+ LOGE(msg);
+ throw IPCException(msg);
}
for (int fd = SD_LISTEN_FDS_START;
{
// Isn't the path too long?
if (path.size() >= sizeof(sockaddr_un::sun_path)) {
- LOGE("Socket's path too long");
- throw IPCException("Socket's path too long");
+ const std::string msg = "Socket's path too long";
+ LOGE(msg);
+ throw IPCException(msg);
}
int sockfd = ::socket(AF_UNIX, SOCK_STREAM, 0);
if (sockfd == -1) {
- const std::string msg = getSystemErrorMessage();
- LOGE("Error in socket: " + msg);
- throw IPCException("Error in socket: " + msg);
+ const std::string msg = "Error in socket: " + getSystemErrorMessage();
+ LOGE(msg);
+ throw IPCException(msg);
}
setFdOptions(sockfd);
if (-1 == ::bind(sockfd,
reinterpret_cast<struct sockaddr*>(&serverAddress),
sizeof(struct sockaddr_un))) {
- std::string message = getSystemErrorMessage();
utils::close(sockfd);
- LOGE("Error in bind: " << message);
- throw IPCException("Error in bind: " + message);
+ const std::string msg = "Error in bind: " + getSystemErrorMessage();
+ LOGE(msg);
+ throw IPCException(msg);
}
if (-1 == ::listen(sockfd,
MAX_QUEUE_LENGTH)) {
- std::string message = getSystemErrorMessage();
utils::close(sockfd);
- LOGE("Error in listen: " << message);
- throw IPCException("Error in listen: " + message);
+ const std::string msg = "Error in listen: " + getSystemErrorMessage();
+ LOGE(msg);
+ throw IPCException(msg);
}
return sockfd;
{
// Isn't the path too long?
if (path.size() >= sizeof(sockaddr_un::sun_path)) {
- LOGE("Socket's path too long");
- throw IPCException("Socket's path too long");
+ const std::string msg = "Socket's path too long";
+ LOGE(msg);
+ throw IPCException(msg);
}
int fd = socket(AF_UNIX, SOCK_STREAM, 0);
if (fd == -1) {
- const std::string msg = getSystemErrorMessage();
- LOGE("Error in socket: " + msg);
- throw IPCException("Error in socket: " + msg);
+ const std::string msg = "Error in socket: " + getSystemErrorMessage();
+ LOGE(msg);
+ throw IPCException(msg);
}
setFdOptions(fd);
if (-1 == connect(fd,
reinterpret_cast<struct sockaddr*>(&serverAddress),
sizeof(struct sockaddr_un))) {
- const std::string msg = getSystemErrorMessage();
utils::close(fd);
- LOGE("Error in connect: " + msg);
- throw IPCException("Error in connect: " + msg);
+ const std::string msg = "Error in connect: " + getSystemErrorMessage();
+ LOGE(msg);
+ throw IPCException(msg);
}
// Nonblock socket
int flags = fcntl(fd, F_GETFL, 0);
if (-1 == fcntl(fd, F_SETFL, flags | O_NONBLOCK)) {
- const std::string msg = getSystemErrorMessage();
utils::close(fd);
- LOGE("Error in fcntl: " + msg);
- throw IPCException("Error in fcntl: " + msg);
+ const std::string msg = "Error in fcntl: " + getSystemErrorMessage();
+ LOGE(msg);
+ throw IPCException(msg);
}
return Socket(fd);
case Namespace::NET:
return "net";
default:
- LOGE("Bad namespace passed to the function");
- throw BadArgument("Bad namespace passed to the function");
+ const std::string msg = "Bad namespace passed to the function";
+ LOGE(msg);
+ throw BadArgument(msg);
}
}
InputMonitorException(const std::string& error) : ServerException(error) {}
};
+struct TimeoutException: public InputMonitorException {
+
+ TimeoutException(const std::string& error) : InputMonitorException (error) {}
+};
}
std::bind(&HostDbusConnection::onNameLost, this));
if (!waitForName(NAME_ACQUIRED_TIMEOUT)) {
- LOGE("Could not acquire dbus name: " << api::dbus::BUS_NAME);
- throw HostConnectionException("Could not acquire dbus name: " + api::dbus::BUS_NAME);
+ const std::string msg = "Could not acquire dbus name: " + api::dbus::BUS_NAME;
+ LOGE(msg);
+ throw HostConnectionException(msg);
}
LOGT("Registering DBUS interface");
, mEventPoll(eventPoll)
{
if (mConfig.timeWindowMs > MAX_TIME_WINDOW_SEC * 1000L) {
- LOGE("Time window exceeds maximum: " << MAX_TIME_WINDOW_SEC);
- throw InputMonitorException("Time window exceeds maximum");
+ const std::string msg = "Time window exceeds maximum: " + MAX_TIME_WINDOW_SEC;
+ LOGE(msg);
+ throw TimeoutException(msg);
}
if (mConfig.numberOfEvents > MAX_NUMBER_OF_EVENTS) {
- LOGE("Number of events exceeds maximum: " << MAX_NUMBER_OF_EVENTS);
- throw InputMonitorException("Number of events exceeds maximum");
+ const std::string msg = "Number of events exceeds maximum: " + MAX_NUMBER_OF_EVENTS;
+ LOGE(msg);
+ throw InputMonitorException(msg);
}
mDevicePath = getDevicePath();
// We need NONBLOCK for FIFOs in the tests
mFd = ::open(devicePath.c_str(), O_RDONLY | O_NONBLOCK | O_CLOEXEC);
if (mFd < 0) {
- LOGE("Cannot create input monitor channel. Device file: " <<
- devicePath << " doesn't exist");
- throw InputMonitorException("Device does not exist");
+ const std::string msg = "Cannot create input monitor channel. Device file: " +
+ devicePath + " doesn't exist";
+ LOGE(msg);
+ throw InputMonitorException(msg);
}
mEventPoll.addFD(mFd, EPOLLIN, std::bind(&InputMonitor::handleInternal, this, _1, _2));
}
uint32_t getInterfaceIndex(const string& name) {
uint32_t index = if_nametoindex(name.c_str());
if (!index) {
- LOGE("Can't get " << name << " interface index (" << getSystemErrorMessage() << ")");
- throw ZoneOperationException("Can't find interface");
+ const std::string msg = "Can't get " + name + " interface index (" + getSystemErrorMessage() + ")";
+ LOGE(msg);
+ throw ZoneOperationException(msg);
}
return index;
}
uint32_t index = getInterfaceIndex(netdev);
int fd = socket(AF_LOCAL, SOCK_STREAM, 0);
if (fd < 0) {
- LOGE("Can't open socket (" << getSystemErrorMessage() << ")");
- throw ZoneOperationException("Can't attach to bridge");
+ const std::string msg = "Can't open socket (" + getSystemErrorMessage() + ")";
+ LOGE(msg);
+ throw ZoneOperationException(msg);
}
struct ifreq ifr = utils::make_clean<ifreq>();
int error = errno;
//TODO: Close can be interrupted. Move util functions from ipc
::close(fd);
- LOGE("Can't attach to bridge (" + getSystemErrorMessage(error) + ")");
- throw ZoneOperationException("Can't attach to bridge");
+ const std::string msg = "Can't attach to bridge (" + getSystemErrorMessage(error) + ")";
+ LOGE(msg);
+ throw ZoneOperationException(msg);
}
close(fd);
}
}
addr = inet_ntop(family, addr, buf, sizeof(buf));
if (addr == NULL) {
- LOGE("Can't convert ip address: " << getSystemErrorMessage());
- throw VasumException("Can't get ip address");
+ const std::string msg = "Can't convert ip address: " + getSystemErrorMessage();
+ LOGE(msg);
+ throw VasumException(msg);
}
attrs.push_back(make_tuple("ip", buf));
break;
for (const auto& addrAttr : split(params, ip, is_any_of(","))) {
size_t pos = addrAttr.find(":");
if (pos == string::npos || pos == addrAttr.length()) {
- LOGE("Wrong input data format: ill formed address attribute: " << addrAttr);
- throw VasumException("Wrong input data format: ill formed address attribute");
+ const std::string msg = "Wrong input data format: ill formed address attribute: " + addrAttr;
+ LOGE(msg);
+ throw VasumException(msg);
}
attrs.push_back(make_tuple(addrAttr.substr(0, pos), addrAttr.substr(pos + 1)));
}
uint32_t index = getInterfaceIndex(netdev, nsPid);
size_t slash = ip.find('/');
if (slash == string::npos) {
- LOGE("Wrong address format: it is not CIDR notation: can't find '/'");
- throw VasumException("Wrong address format");
+ const std::string msg = "Wrong address format: it is not CIDR notation: can't find '/'";
+ LOGE(msg);
+ throw VasumException(msg);
}
int prefixlen = 0;
try {
prefixlen = stoi(ip.substr(slash + 1));
} catch (const std::exception& ex) {
- LOGE("Wrong address format: invalid prefixlen");
- throw VasumException("Wrong address format: invalid prefixlen");
+ const std::string msg = "Wrong address format: invalid prefixlen";
+ LOGE(msg);
+ throw VasumException(msg);
}
deleteIpAddress(nsPid, index, ip.substr(0, slash), prefixlen, getIpFamily(ip));
}
LOGI("Terminating server");
int ret = ::pthread_kill(mDispatchingThread, SIGINT);
if(ret != 0) {
- const std::string msg = utils::getSystemErrorMessage(ret);
- LOGE("Error during Server termination: " << msg);
- throw ServerException("Error during Server termination: " + msg);
+ const std::string msg = "Error during Server termination: " + utils::getSystemErrorMessage(ret);
+ LOGE(msg);
+ throw ServerException(msg);
}
}
return getId(existingProvision) == id;
});
if (it != mProvisioningConfig.provisions.end()) {
- LOGE("Can't add provision. It already exists: " << id);
- throw UtilsException("Provision already exists");
+ const std::string msg = "Can't add provision. It already exists: " + id;
+ LOGE(msg);
+ throw ProvisionExistsException(msg);
}
mProvisioningConfig.provisions.push_back(std::move(provision));
saveProvisioningConfig();
return;
}
}
- LOGE("Failed to create hard link: path=host: "
- << srcHostPath
- << ", msg: Path prefix is not valid path");
- throw UtilsException("Failed to hard link: path prefix is not valid");
+ const std::string msg = "Failed to create hard link: path=host: " +
+ srcHostPath + ", msg: Path prefix is not valid path";
+ LOGE(msg);
+ throw UtilsException(msg);
}
std::string ZoneProvision::getId(const ZoneProvisioningConfig::File& file)
auto iter = findZone(zoneId);
if (iter == mZones.end()) {
- LOGE("Failed to destroy zone " << zoneId << ": no such zone");
- throw InvalidZoneIdException("No such zone");
+ const std::string msg = "Failed to destroy zone " + zoneId + ": no such zone";
+ LOGE(msg);
+ throw InvalidZoneIdException(msg);
}
get(iter).setDestroyOnExit();
candidates.erase(zone->getVT());
}
if (candidates.empty()) {
- LOGE("No free VT for zone");
- throw ZoneOperationException("No free VT for zone");
+ const std::string msg = "No free VT for zone";
+ LOGE(msg);
+ throw ZoneOperationException(msg);
}
// return the smallest
return *candidates.begin();
const std::string& templateName)
{
if (id.empty() || !isalnum(id)) {
- LOGE("Failed to add zone - invalid name.");
- throw InvalidZoneIdException("Invalid name");
+ const std::string msg = "Failed to add zone - invalid name.";
+ LOGE(msg);
+ throw InvalidZoneIdException(msg);
}
if (find(prohibitedZonesNames.begin(), prohibitedZonesNames.end(), id) != prohibitedZonesNames.end()) {
- LOGE("Cannot create " << id << " zone - name is not allowed!");
- throw InvalidZoneIdException("Zone name is not allowed");
+ const std::string msg = "Cannot create " + id + " zone - name is not allowed!";
+ LOGE(msg);
+ throw InvalidZoneIdException(msg);
}
LOGI("Creating zone " << id);
// check if zone does not exist
if (findZone(id) != mZones.end()) {
- LOGE("Cannot create " << id << " zone - already exists!");
- throw InvalidZoneIdException("Already exists");
+ const std::string msg = "Cannot create " + id + " zone - already exists!";
+ LOGE(msg);
+ throw InvalidZoneIdException(msg);
}
if (fs::exists(fs::path(mConfig.zonesPath) / id)) {
- LOGE("Cannot create " << id << " zone - file system already exists!");
- throw InvalidZoneIdException("Zone file system already exists but there is no configuration for it. "
- "Check cleanUpZonesPath in daemon.conf");
+ const std::string msg = "Cannot create " + id + " zone - file system already exists!";
+ LOGE(msg);
+ throw InvalidZoneIdException(msg);
}
const std::string zonePathStr = utils::createFilePath(mConfig.zonesPath, id, "/");
zonePathStr);
if (!utils::launchAsRoot(copyImageContentsWrapper)) {
- LOGE("Failed to copy zone image.");
- throw ZoneOperationException("Failed to copy zone image.");
+ const std::string msg = "Failed to copy zone image.";
+ LOGE(msg);
+ throw ZoneOperationException(msg);
}
}
BOOST_CHECK(lxc.isDefined());
BOOST_CHECK_EQUAL(lxc.getConfigItem("lxc.rootfs"), ZONE_PATH + ZONE_NAME + "/rootfs");
- BOOST_CHECK_EXCEPTION(lxc.getConfigItem("xxx"), LxcException, WhatEquals("Key not found"));
+ BOOST_CHECK_THROW(lxc.getConfigItem("xxx"), KeyNotFoundException);
BOOST_CHECK(lxc.destroy());
ZonesManager cm(getPoll(), TEST_CONFIG_PATH);
inputConfig.timeWindowMs = 50000;
- BOOST_REQUIRE_EXCEPTION(InputMonitor inputMonitor(getPoll(), inputConfig, &cm),
- InputMonitorException,
- WhatEquals("Time window exceeds maximum"));
+ BOOST_REQUIRE_THROW(InputMonitor inputMonitor(getPoll(), inputConfig, &cm),
+ TimeoutException);
}
BOOST_AUTO_TEST_CASE(ConfigDeviceFilePathNotExisting)
ZoneProvision zoneProvision = create({});
zoneProvision.declareMount("/fake/path1", "/fake/path2", "tmpfs", 077, "fake");
zoneProvision.declareMount("/fake/path2", "/fake/path2", "tmpfs", 077, "fake");
- BOOST_CHECK_EXCEPTION(zoneProvision.declareMount("/fake/path2", "/fake/path2", "tmpfs", 077, "fake"),
- UtilsException,
- WhatEquals("Provision already exists"));
+ BOOST_CHECK_THROW(zoneProvision.declareMount("/fake/path2", "/fake/path2", "tmpfs", 077, "fake"),
+ ProvisionExistsException);
ZoneProvisioningConfig config;
load(config);
std::bind(&DaemonConnection::onNameLost, this));
if (!waitForNameAndSetCallback(NAME_ACQUIRED_TIMEOUT, nameLostCallback)) {
- LOGE("Could not acquire dbus name: " << zone_daemon::api::BUS_NAME);
- throw ZoneDaemonException("Could not acquire dbus name: " + zone_daemon::api::BUS_NAME);
+ const std::string msg = "Could not acquire dbus name: " + zone_daemon::api::BUS_NAME;
+ LOGE(msg);
+ throw ZoneDaemonException(msg);
}
LOGD("Setting callbacks");