void start();
void stop();
- void subscribe(const int fd, const runtime::Mainloop::Event events, runtime::Mainloop::Callback&& callback);
+ void subscribe(const int fd, const klay::Mainloop::Event events, klay::Mainloop::Callback&& callback);
void unsubscribe(const int fd);
private:
- runtime::Mainloop mainloop;
+ klay::Mainloop mainloop;
std::thread dispatcher;
};
Mutex mutex;
int pollFd;
std::atomic<bool> stopped;
- runtime::EventFD wakeupSignal;
+ klay::EventFD wakeupSignal;
void prepare();
};
private:
std::string address;
std::shared_ptr<Connection> connection;
- runtime::Mainloop mainloop;
+ klay::Mainloop mainloop;
std::thread dispatcher;
};
{
try {
disconnect();
- } catch (runtime::Exception& e) {}
+ } catch (klay::Exception& e) {}
}
template <typename ExceptionModel>
request.packParameters(name);
connection->send(request);
- runtime::FileDescriptor response;
+ klay::FileDescriptor response;
Message reply = connection->dispatch();
if (reply.isError()) {
std::string klass;
std::shared_ptr<Socket> transport = std::make_shared<Socket>(id);
- auto callback = [handler, transport, this](int fd, runtime::Mainloop::Event event) {
+ auto callback = [handler, transport, this](int fd, klay::Mainloop::Event event) {
if ((event & EPOLLHUP) || (event & EPOLLRDHUP)) {
mainloop.removeEventSource(fd);
return;
MessageSignature signature;
MessageComposer buffer;
- std::deque<runtime::FileDescriptor> fileDescriptors;
+ std::deque<klay::FileDescriptor> fileDescriptors;
static std::atomic<unsigned int> sequence;
};
template<typename DataType>
void Message::enclose(DataType&& data)
{
- runtime::Serializer<MessageComposer> serializer(buffer);
- runtime::SerializableArgument<DataType> arg(std::forward<DataType>(data));
+ klay::Serializer<MessageComposer> serializer(buffer);
+ klay::SerializableArgument<DataType> arg(std::forward<DataType>(data));
arg.accept(serializer);
}
template<typename DataType>
void Message::disclose(DataType& data)
{
- runtime::Deserializer<MessageComposer> deserializer(buffer);
- runtime::DeserializableArgument<DataType> arg(data);
+ klay::Deserializer<MessageComposer> deserializer(buffer);
+ klay::DeserializableArgument<DataType> arg(data);
arg.accept(deserializer);
}
device.write(buffer.begin(), header.length);
int i = 0, fds[fileDescriptors.size()];
- for (const runtime::FileDescriptor& fd : fileDescriptors) {
+ for (const klay::FileDescriptor& fd : fileDescriptors) {
fds[i++] = fd.fileDescriptor;
}
device.receiveFileDescriptors(fds, header.ancillary);
for (unsigned int i = 0; i < header.ancillary; i++) {
- fileDescriptors.emplace_back(runtime::FileDescriptor(fds[i]));
+ fileDescriptors.emplace_back(klay::FileDescriptor(fds[i]));
}
disclose(signature);
}
-template<> void Message::enclose(runtime::FileDescriptor&& fd);
-template<> void Message::disclose(runtime::FileDescriptor& fd);
+template<> void Message::enclose(klay::FileDescriptor&& fd);
+template<> void Message::disclose(klay::FileDescriptor& fd);
} // namespae rmi
} // namespae klay
for (const std::shared_ptr<Socket>& subscriber : subscribers) {
try {
msg.encode(*subscriber);
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
ERROR(KSINK, e.what());
}
}
return processingContext.credentials.gid;
}
- runtime::Mainloop mainloop;
+ klay::Mainloop mainloop;
private:
struct ProcessingContext {
std::string address;
- runtime::ThreadPool workqueue;
+ klay::ThreadPool workqueue;
std::mutex stateLock;
std::mutex notificationLock;
std::mutex methodRegistryLock;
std::lock_guard<std::mutex> lock(methodRegistryLock);
if (methodRegistry.count(method)) {
- throw runtime::Exception("Method handler already registered");
+ throw klay::Exception("Method handler already registered");
}
methodRegistry[method] = std::make_shared<MethodContext>(privilege, dispatchMethod);
namespace klay {
namespace rmi {
-class KLAY_EXPORT SocketException: public runtime::Exception {
+class KLAY_EXPORT SocketException: public klay::Exception {
public:
- SocketException(const std::string& msg) : runtime::Exception(msg) {}
+ SocketException(const std::string& msg) : klay::Exception(msg) {}
};
struct KLAY_EXPORT Credentials {
}
}
-void AuditTrail::subscribe(const int fd, const runtime::Mainloop::Event events, runtime::Mainloop::Callback&& callback)
+void AuditTrail::subscribe(const int fd, const klay::Mainloop::Event events, klay::Mainloop::Callback&& callback)
{
mainloop.addEventSource(fd, events, std::move(callback));
}
ret = ::getgrnam_r(group.c_str(), &grp, buf.get(), bufsize, &result);
if (result == NULL) {
if (ret == 0)
- throw runtime::Exception("Group doesn't exist");
+ throw klay::Exception("Group doesn't exist");
else
- throw runtime::Exception(runtime::GetSystemErrorMessage(ret));
+ throw klay::Exception(klay::GetSystemErrorMessage(ret));
}
name = result->gr_name;
ret = ::getgrgid_r(group, &grp, buf.get(), bufsize, &result);
if (result == NULL) {
if (ret == 0)
- throw runtime::Exception("Group doesn't exist");
+ throw klay::Exception("Group doesn't exist");
else
- throw runtime::Exception(runtime::GetSystemErrorMessage(ret));
+ throw klay::Exception(klay::GetSystemErrorMessage(ret));
}
name = result->gr_name;
ret = ::getpwnam_r(user.c_str(), &pwd, buf.get(), bufsize, &result);
if (result == NULL) {
if (ret == 0)
- throw runtime::Exception("User " + user + " doesn't exist");
+ throw klay::Exception("User " + user + " doesn't exist");
else
- throw runtime::Exception(runtime::GetSystemErrorMessage(ret));
+ throw klay::Exception(klay::GetSystemErrorMessage(ret));
}
name = result->pw_name;
ret = ::getpwuid_r(user, &pwd, buf.get(), bufsize, &result);
if (result == NULL) {
if (ret == 0)
- throw runtime::Exception("User " + std::to_string(user) + "doesn't exist");
+ throw klay::Exception("User " + std::to_string(user) + "doesn't exist");
else
- throw runtime::Exception(runtime::GetSystemErrorMessage(ret));
+ throw klay::Exception(klay::GetSystemErrorMessage(ret));
}
name = result->pw_name;
return false;
}
} catch (std::runtime_error &e) {
- throw runtime::Exception("Unexpected regex error");
+ throw klay::Exception("Unexpected regex error");
}
- runtime::File dir("/sys/fs/cgroup/" + name);
+ klay::File dir("/sys/fs/cgroup/" + name);
if (dir.exists()) {
if (dir.isDirectory()) {
return true;
}
- throw runtime::Exception("Invalid subsystem name");
+ throw klay::Exception("Invalid subsystem name");
}
return false;
{
try {
if (!std::regex_match(name, std::regex(NAME_PATTERN))) {
- throw runtime::Exception("Invalid subsystem name");
+ throw klay::Exception("Invalid subsystem name");
}
} catch (std::runtime_error &e) {
- throw runtime::Exception("Unexpected regex error");
+ throw klay::Exception("Unexpected regex error");
}
if (existSubsystem(name)) {
return;
}
- runtime::File subsystem("/sys/fs/cgroup/" + name);
+ klay::File subsystem("/sys/fs/cgroup/" + name);
if (::mount(NULL, "/sys/fs/cgroup/", NULL, MS_REMOUNT |
MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_STRICTATIME,
"mode=755")) {
- throw runtime::Exception("Failed to remount cgroupfs as the writable");
+ throw klay::Exception("Failed to remount cgroupfs as the writable");
}
if (!subsystem.exists()) {
"cgroup", MS_NODEV | MS_NOSUID | MS_NOEXEC,
("none,name=" + name).c_str())) {
subsystem.remove(false);
- throw runtime::Exception("Failed to mount cgroup subsystem");
+ throw klay::Exception("Failed to mount cgroup subsystem");
}
if (::mount(NULL, "/sys/fs/cgroup/", NULL, MS_REMOUNT | MS_RDONLY |
MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_STRICTATIME,
"mode=755")) {
- throw runtime::Exception("Failed to remount cgroupfs as the read-only");
+ throw klay::Exception("Failed to remount cgroupfs as the read-only");
}
}
void Cgroup::destroySubsystem(const std::string& name)
{
if (!existSubsystem(name)) {
- throw runtime::Exception("No such subsystem");
+ throw klay::Exception("No such subsystem");
}
if (::mount(NULL, "/sys/fs/cgroup/", NULL, MS_REMOUNT |
MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_STRICTATIME,
"mode=755")) {
- throw runtime::Exception("Failed to remount cgroupfs as the writable");
+ throw klay::Exception("Failed to remount cgroupfs as the writable");
}
- runtime::File subsystem("/sys/fs/cgroup/" + name);
+ klay::File subsystem("/sys/fs/cgroup/" + name);
::umount2(subsystem.getPath().c_str(), MNT_EXPIRE);
subsystem.remove(false);
if (::mount(NULL, "/sys/fs/cgroup/", NULL, MS_REMOUNT | MS_RDONLY |
MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_STRICTATIME,
"mode=755")) {
- throw runtime::Exception("Failed to remount cgroupfs as the read-only");
+ throw klay::Exception("Failed to remount cgroupfs as the read-only");
}
}
return false;
}
} catch (std::runtime_error &e) {
- throw runtime::Exception("Unexpected regex error");
+ throw klay::Exception("Unexpected regex error");
}
- runtime::File dir("/sys/fs/cgroup/" + subsystem + "/" + path);
+ klay::File dir("/sys/fs/cgroup/" + subsystem + "/" + path);
if (dir.exists()) {
if (dir.isDirectory()) {
return true;
}
- throw runtime::Exception("Invalid path");
+ throw klay::Exception("Invalid path");
}
return false;
{
try {
if (!std::regex_match(path, std::regex(PATH_PATTERN))) {
- throw runtime::Exception("Invalid path");
+ throw klay::Exception("Invalid path");
}
} catch (std::runtime_error &e) {
- throw runtime::Exception("Unexpected regex error");
+ throw klay::Exception("Unexpected regex error");
}
if (exist(subsystem, path)) {
return;
}
- runtime::File dir("/sys/fs/cgroup/" + subsystem + "/" + path);
+ klay::File dir("/sys/fs/cgroup/" + subsystem + "/" + path);
dir.makeDirectory(true);
}
void Cgroup::destroy(const std::string& subsystem, const std::string& path)
{
if (!exist(subsystem, path)) {
- throw runtime::Exception("No such path in subsystem");
+ throw klay::Exception("No such path in subsystem");
}
- runtime::File dir("/sys/fs/cgroup/" + subsystem + "/" + path);
+ klay::File dir("/sys/fs/cgroup/" + subsystem + "/" + path);
dir.remove(false);
}
void Cgroup::addProcess(const std::string& subsystem, const std::string& path, const pid_t pid)
{
if (!exist(subsystem, path)) {
- throw runtime::Exception("No such path in subsystem");
+ throw klay::Exception("No such path in subsystem");
}
std::ofstream ofs("/sys/fs/cgroup/" + subsystem + "/" + path +
handle(nullptr), filename(name)
{
if (::sqlite3_open_v2(filename.c_str(), &handle, flags, NULL)) {
- throw runtime::Exception(getErrorMessage());
+ throw klay::Exception(getErrorMessage());
}
if (integrityCheck) {
if (!verified) {
::sqlite3_close(handle);
- throw runtime::Exception("Malformed database");
+ throw klay::Exception("Malformed database");
}
}
}
int Connection::exec(const std::string& query)
{
if (::sqlite3_exec(handle, query.c_str(), NULL, NULL, NULL) != SQLITE_OK) {
- throw runtime::Exception(getErrorMessage());
+ throw klay::Exception(getErrorMessage());
}
return ::sqlite3_changes(handle);
query.size(),
&statement,
NULL)) {
- throw runtime::Exception(db.getErrorMessage());
+ throw klay::Exception(db.getErrorMessage());
}
columnCount = sqlite3_column_count(statement);
void Statement::reset()
{
if (::sqlite3_reset(statement) != SQLITE_OK) {
- throw runtime::Exception(getErrorMessage());
+ throw klay::Exception(getErrorMessage());
}
}
void Statement::clearBindings()
{
if (::sqlite3_clear_bindings(statement) != SQLITE_OK) {
- throw runtime::Exception(getErrorMessage());
+ throw klay::Exception(getErrorMessage());
}
}
Column Statement::getColumn(const int index)
{
if (!validRow || (index >= columnCount)) {
- throw runtime::Exception(getErrorMessage(SQLITE_RANGE));
+ throw klay::Exception(getErrorMessage(SQLITE_RANGE));
}
return Column(*this, index);
bool Statement::isNullColumn(const int index) const
{
if (!validRow || (index >= columnCount)) {
- throw runtime::Exception(getErrorMessage(SQLITE_RANGE));
+ throw klay::Exception(getErrorMessage(SQLITE_RANGE));
}
return (SQLITE_NULL == sqlite3_column_type(statement, index));
std::string Statement::getColumnName(const int index) const
{
if (index >= columnCount) {
- throw runtime::Exception(getErrorMessage(SQLITE_RANGE));
+ throw klay::Exception(getErrorMessage(SQLITE_RANGE));
}
return sqlite3_column_name(statement, index);
void Statement::bind(const int index, const int& value)
{
if (SQLITE_OK != ::sqlite3_bind_int(statement, index, value)) {
- throw runtime::Exception(getErrorMessage());
+ throw klay::Exception(getErrorMessage());
}
}
void Statement::bind(const int index, const sqlite3_int64& value)
{
if (SQLITE_OK != ::sqlite3_bind_int64(statement, index, value)) {
- throw runtime::Exception(getErrorMessage());
+ throw klay::Exception(getErrorMessage());
}
}
void Statement::bind(const int index, const double& value)
{
if (SQLITE_OK != ::sqlite3_bind_double(statement, index, value)) {
- throw runtime::Exception(getErrorMessage());
+ throw klay::Exception(getErrorMessage());
}
}
void Statement::bind(const int index, const char* value)
{
if (SQLITE_OK != ::sqlite3_bind_text(statement, index, value, -1, SQLITE_TRANSIENT)) {
- throw runtime::Exception(getErrorMessage());
+ throw klay::Exception(getErrorMessage());
}
}
{
if (SQLITE_OK != ::sqlite3_bind_text(statement, index, value.c_str(),
static_cast<int>(value.size()), SQLITE_TRANSIENT)) {
- throw runtime::Exception(getErrorMessage());
+ throw klay::Exception(getErrorMessage());
}
}
void Statement::bind(const int index, const void* value, const int size)
{
if (SQLITE_OK != ::sqlite3_bind_blob(statement, index, value, size, SQLITE_TRANSIENT)) {
- throw runtime::Exception(getErrorMessage());
+ throw klay::Exception(getErrorMessage());
}
}
void Statement::bind(const int index)
{
if (SQLITE_OK != ::sqlite3_bind_null(statement, index)) {
- throw runtime::Exception(getErrorMessage());
+ throw klay::Exception(getErrorMessage());
}
}
{
int index = sqlite3_bind_parameter_index(statement, name.c_str());
if (SQLITE_OK != sqlite3_bind_int(statement, index, value)) {
- throw runtime::Exception(getErrorMessage());
+ throw klay::Exception(getErrorMessage());
}
}
{
int index = sqlite3_bind_parameter_index(statement, name.c_str());
if (SQLITE_OK != ::sqlite3_bind_int64(statement, index, value)) {
- throw runtime::Exception(getErrorMessage());
+ throw klay::Exception(getErrorMessage());
}
}
{
int index = sqlite3_bind_parameter_index(statement, name.c_str());
if (SQLITE_OK != ::sqlite3_bind_double(statement, index, value)) {
- throw runtime::Exception(getErrorMessage());
+ throw klay::Exception(getErrorMessage());
}
}
int index = sqlite3_bind_parameter_index(statement, name.c_str());
if (SQLITE_OK != ::sqlite3_bind_text(statement, index, value.c_str(),
static_cast<int>(value.size()), SQLITE_TRANSIENT)) {
- throw runtime::Exception(getErrorMessage());
+ throw klay::Exception(getErrorMessage());
}
}
{
int index = sqlite3_bind_parameter_index(statement, name.c_str());
if (SQLITE_OK != ::sqlite3_bind_text(statement, index, value, -1, SQLITE_TRANSIENT)) {
- throw runtime::Exception(getErrorMessage());
+ throw klay::Exception(getErrorMessage());
}
}
{
int index = sqlite3_bind_parameter_index(statement, name.c_str());
if (SQLITE_OK != ::sqlite3_bind_blob(statement, index, value, size, SQLITE_TRANSIENT)) {
- throw runtime::Exception(getErrorMessage());
+ throw klay::Exception(getErrorMessage());
}
}
{
int index = sqlite3_bind_parameter_index(statement, name.c_str());
if (SQLITE_OK != ::sqlite3_bind_null(statement, index)) {
- throw runtime::Exception(getErrorMessage());
+ throw klay::Exception(getErrorMessage());
}
}
connection = g_dbus_connection_new_for_address_sync(address.c_str(), flags, NULL, NULL, &error);
if (error) {
ERROR(KSINK, error->message);
- throw runtime::Exception(error->message);
+ throw klay::Exception(error->message);
}
}
if (error) {
ERROR(KSINK, error->message);
- throw runtime::Exception(error->message);
+ throw klay::Exception(error->message);
}
return result;
&error);
if (error) {
ERROR(KSINK, error->message);
- throw runtime::Exception(error->message);
+ throw klay::Exception(error->message);
}
}
}
if (error) {
- throw runtime::Exception(error->message);
+ throw klay::Exception(error->message);
}
GDBusInterfaceInfo* inf = node->interfaces[0];
g_dbus_node_info_unref(node);
if (error) {
ERROR(KSINK, error->message);
- throw runtime::Exception(error->message);
+ throw klay::Exception(error->message);
}
return id;
try {
Variant variant = callbackSet.methodcall(objectPath, interface, method, Variant(parameters));
g_dbus_method_invocation_return_value(invocation, &variant);
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
ERROR(KSINK, "Error on metod handling");
g_dbus_method_invocation_return_dbus_error(invocation, (interface + std::string(".Error")).c_str(), e.what());
}
BusNode Introspection::getBusNode(const std::string &xmlData)
{
if (xmlData.empty())
- throw runtime::Exception("Invalid argument.");
+ throw klay::Exception("Invalid argument.");
dbus::Error error;
auto busNode = ::g_dbus_node_info_new_for_xml(xmlData.c_str(), &error);
if (busNode == nullptr || error)
- throw runtime::Exception("Failed to get BusNode.");
+ throw klay::Exception("Failed to get BusNode.");
return busNode;
}
Interface Introspection::getInterface(const std::string &name) const
{
if (name.empty())
- throw runtime::Exception("Invalid argument.");
+ throw klay::Exception("Invalid argument.");
return ::g_dbus_node_info_lookup_interface(busNode, name.c_str());
}
{
auto interface = getInterface(interfaceName);
if (interface == nullptr || methodName.empty())
- throw runtime::Exception("Invalid argument.");
+ throw klay::Exception("Invalid argument.");
return ::g_dbus_interface_info_lookup_method(interface, methodName.c_str());
}
{
auto interface = getInterface(interfaceName);
if (interface == nullptr || signalName.empty())
- throw runtime::Exception("Invalid argument.");
+ throw klay::Exception("Invalid argument.");
return ::g_dbus_interface_info_lookup_signal(interface, signalName.c_str());
}
{
auto interface = getInterface(interfaceName);
if (interface == nullptr || propertyName.empty())
- throw runtime::Exception("Invalid argument.");
+ throw klay::Exception("Invalid argument.");
return ::g_dbus_interface_info_lookup_property(interface, propertyName.c_str());
}
::g_string_free(ptr, TRUE);
});
if (buf == nullptr)
- throw runtime::Exception("Out of memory.");
+ throw klay::Exception("Out of memory.");
::g_dbus_node_info_generate_xml(busNode, indent, buf.get());
return std::string(buf->str);
std::string Introspection::createXmlDataFromFile(const std::string &path)
{
- runtime::File manifest(path);
+ klay::File manifest(path);
if (!manifest.exists()) {
manifest.create(0644);
manifest.lock();
void Introspection::writeXmlDataToFile(const std::string &path,
const std::string &xmlData)
{
- runtime::File manifest(path);
+ klay::File manifest(path);
manifest.open(O_WRONLY | O_TRUNC);
manifest.lock();
manifest.write(xmlData.c_str(), xmlData.length());
void Introspection::addInterface(const std::string &name)
{
if (getInterface(name) != nullptr)
- throw runtime::Exception("Interface is already exist:" + name);
+ throw klay::Exception("Interface is already exist:" + name);
std::size_t offset = xmlData.find("</node>");
if (offset == std::string::npos)
- throw runtime::Exception("Failed to find </node>.");
+ throw klay::Exception("Failed to find </node>.");
XmlProperties properties;
properties.emplace_back(std::make_pair("name", name));
void Introspection::checkDataFormat(const std::string &data) const
{
if (data.empty() || data.length() < 3)
- throw runtime::Exception("Invalid argument.");
+ throw klay::Exception("Invalid argument.");
const std::string beginChar = "<";
if (data.compare(0, beginChar.length(), beginChar) != 0)
- throw runtime::Exception("Xml data should be begin as: " + beginChar);
+ throw klay::Exception("Xml data should be begin as: " + beginChar);
const std::string endChar = "/>";
if (data.compare(data.length() - endChar.length(), endChar.length(), endChar) != 0 &&
data.find("/") == std::string::npos)
- throw runtime::Exception("Xml data should be contain '/' or end as: " + endChar);
+ throw klay::Exception("Xml data should be contain '/' or end as: " + endChar);
}
void Introspection::addMethod(const std::string &interfaceName,
std::string iTemplate = getXmlBeginTag(INTERFACE_NODE, properties);
std::size_t offset = xmlData.find(iTemplate);
if (offset == std::string::npos)
- throw runtime::Exception("Failed to find interface xml node: " + interfaceName);
+ throw klay::Exception("Failed to find interface xml node: " + interfaceName);
xmlData.insert(offset + iTemplate.length() + 1, data);
update();
{
fd = ::eventfd(initval, flags);
if (fd == -1) {
- throw runtime::Exception(runtime::GetSystemErrorMessage());
+ throw klay::Exception(klay::GetSystemErrorMessage());
}
}
{
const std::uint64_t val = 1;
if (::write(fd, &val, sizeof(val)) == -1) {
- throw runtime::Exception(runtime::GetSystemErrorMessage());
+ throw klay::Exception(klay::GetSystemErrorMessage());
}
}
{
std::uint64_t val;
if (::read(fd, &val, sizeof(val)) == -1) {
- throw runtime::Exception(runtime::GetSystemErrorMessage());
+ throw klay::Exception(klay::GetSystemErrorMessage());
}
}
try {
File file(filePath);
- for (runtime::DirectoryIterator iter(path), end; iter != end;) {
+ for (klay::DirectoryIterator iter(path), end; iter != end;) {
File cur(File((++iter)->getPath()).readlink());
try {
if ((cur.getInode() == file.getInode() || isMount) &&
cur.getDevice() == file.getDevice()) {
return true;
}
- } catch (runtime::Exception &e) {}
+ } catch (klay::Exception &e) {}
}
- } catch (runtime::Exception &e) {}
+ } catch (klay::Exception &e) {}
return false;
}
}
}
}
- } catch (runtime::Exception &e) {}
+ } catch (klay::Exception &e) {}
return false;
}
cwd.getDevice() == file.getDevice()) {
return true;
}
- } catch (runtime::Exception &e) {}
+ } catch (klay::Exception &e) {}
return false;
}
root.getDevice() == file.getDevice()) {
return true;
}
- } catch (runtime::Exception &e) {}
+ } catch (klay::Exception &e) {}
return false;
}
pid_t currentPid = ::getpid();
std::vector<pid_t> list;
- for (runtime::DirectoryIterator iter("/proc"), end; iter != end;) {
+ for (klay::DirectoryIterator iter("/proc"), end; iter != end;) {
const std::string name = iter->getName();
if (!std::isdigit(name[0])) {
++iter;
{
struct stat st;
if (::lstat(path.c_str(), &st) != 0) {
- throw runtime::Exception(runtime::GetSystemErrorMessage());
+ throw klay::Exception(klay::GetSystemErrorMessage());
}
return S_ISLNK(st.st_mode);
{
struct stat st;
if (::lstat(path.c_str(), &st) != 0) {
- throw runtime::Exception(runtime::GetSystemErrorMessage());
+ throw klay::Exception(klay::GetSystemErrorMessage());
}
return S_ISREG(st.st_mode);
{
struct stat st;
if (::lstat(path.c_str(), &st) != 0) {
- throw runtime::Exception(runtime::GetSystemErrorMessage());
+ throw klay::Exception(klay::GetSystemErrorMessage());
}
return S_ISDIR(st.st_mode);
{
struct stat st;
if (::lstat(path.c_str(), &st) != 0) {
- throw runtime::Exception(runtime::GetSystemErrorMessage());
+ throw klay::Exception(klay::GetSystemErrorMessage());
}
return (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode));
{
struct stat st;
if (::lstat(path.c_str(), &st) != 0) {
- throw runtime::Exception(runtime::GetSystemErrorMessage());
+ throw klay::Exception(klay::GetSystemErrorMessage());
}
return st.st_mode;
{
struct stat st;
if (::lstat(path.c_str(), &st) != 0) {
- throw runtime::Exception(runtime::GetSystemErrorMessage());
+ throw klay::Exception(klay::GetSystemErrorMessage());
}
return st.st_uid;
{
struct stat st;
if (::lstat(path.c_str(), &st) != 0) {
- throw runtime::Exception(runtime::GetSystemErrorMessage());
+ throw klay::Exception(klay::GetSystemErrorMessage());
}
return st.st_gid;
{
struct stat st;
if (::lstat(path.c_str(), &st) != 0) {
- throw runtime::Exception(runtime::GetSystemErrorMessage());
+ throw klay::Exception(klay::GetSystemErrorMessage());
}
return st.st_ino;
{
struct stat st;
if (::lstat(path.c_str(), &st) != 0) {
- throw runtime::Exception(runtime::GetSystemErrorMessage());
+ throw klay::Exception(klay::GetSystemErrorMessage());
}
return st.st_dev;
{
struct stat st;
if (::lstat(path.c_str(), &st) != 0) {
- throw runtime::Exception(runtime::GetSystemErrorMessage());
+ throw klay::Exception(klay::GetSystemErrorMessage());
}
return st.st_size;
if (errno == EINTR) {
continue;
}
- throw runtime::Exception(runtime::GetSystemErrorMessage());
+ throw klay::Exception(klay::GetSystemErrorMessage());
}
return;
}
if (errno == EINTR) {
continue;
}
- throw runtime::Exception(runtime::GetSystemErrorMessage());
+ throw klay::Exception(klay::GetSystemErrorMessage());
}
return;
}
if (errno == EINTR) {
continue;
}
- throw runtime::Exception(runtime::GetSystemErrorMessage());
+ throw klay::Exception(klay::GetSystemErrorMessage());
}
return;
}
} else if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) {
continue;
} else {
- throw runtime::Exception(runtime::GetSystemErrorMessage());
+ throw klay::Exception(klay::GetSystemErrorMessage());
}
}
}
} else if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) {
continue;
} else {
- throw runtime::Exception(runtime::GetSystemErrorMessage());
+ throw klay::Exception(klay::GetSystemErrorMessage());
}
}
}
void File::lseek(off_t offset, int whence) const
{
if (::lseek(descriptor, offset, whence) == -1) {
- throw runtime::Exception(runtime::GetSystemErrorMessage());
+ throw klay::Exception(klay::GetSystemErrorMessage());
}
}
ssize_t ret;
ret = ::sendfile(destFile.descriptor, descriptor, &s, size() - s);
if (ret < 0) {
- throw runtime::Exception(runtime::GetSystemErrorMessage());
+ throw klay::Exception(klay::GetSystemErrorMessage());
}
}
destFile.close();
}
}
if (::rmdir(path.c_str()) != 0) {
- throw runtime::Exception(runtime::GetSystemErrorMessage());
+ throw klay::Exception(klay::GetSystemErrorMessage());
}
} else {
if (::unlink(path.c_str()) != 0) {
- throw runtime::Exception(runtime::GetSystemErrorMessage());
+ throw klay::Exception(klay::GetSystemErrorMessage());
}
}
}
} else if (ret == 0) {
if ((uid | gid) != 0) {
if (::chown(substr.c_str(), uid, gid) == -1) {
- throw runtime::Exception(runtime::GetSystemErrorMessage());
+ throw klay::Exception(klay::GetSystemErrorMessage());
}
}
} else {
- throw runtime::Exception(runtime::GetSystemErrorMessage());
+ throw klay::Exception(klay::GetSystemErrorMessage());
}
}
}
}
if (::mkdir(path.c_str(), 0777) == -1) {
- throw runtime::Exception("mkdir failed in makeDirectory: " + path);
+ throw klay::Exception("mkdir failed in makeDirectory: " + path);
}
if ((uid | gid) != 0) {
void File::chown(uid_t uid, gid_t gid, bool recursive)
{
if (::chown(path.c_str(), uid, gid) != 0) {
- throw runtime::Exception(runtime::GetSystemErrorMessage());
+ throw klay::Exception(klay::GetSystemErrorMessage());
}
if (recursive && isDirectory()) {
void File::chmod(mode_t mode, bool recursive)
{
if (::chmod(path.c_str(), mode) != 0) {
- throw runtime::Exception(runtime::GetSystemErrorMessage());
+ throw klay::Exception(klay::GetSystemErrorMessage());
}
if (recursive && isDirectory()) {
char buf[PATH_MAX + 1];
ssize_t ret = ::readlink(path.c_str(), buf, PATH_MAX);
if (ret == -1) {
- throw runtime::Exception(runtime::GetSystemErrorMessage());
+ throw klay::Exception(klay::GetSystemErrorMessage());
}
buf[ret] = '\0';
void File::lock() const
{
if (::flock(descriptor, LOCK_EX) == -1) {
- throw runtime::Exception(runtime::GetSystemErrorMessage());
+ throw klay::Exception(klay::GetSystemErrorMessage());
}
}
void File::unlock() const
{
if (::flock(descriptor, LOCK_UN) == -1) {
- throw runtime::Exception(runtime::GetSystemErrorMessage());
+ throw klay::Exception(klay::GetSystemErrorMessage());
}
}
basename = dir;
directoryHandle = ::opendir(basename.c_str());
if (directoryHandle == nullptr) {
- throw runtime::Exception(runtime::GetSystemErrorMessage());
+ throw klay::Exception(klay::GetSystemErrorMessage());
}
next();
}
if (ret) {
- throw runtime::Exception("failed to mount " + src + " on " + dest);
+ throw klay::Exception("failed to mount " + src + " on " + dest);
}
}
}
if (fd == -1) {
if (errno != ENOENT) {
- throw runtime::Exception("Failed to open namesapce: " + nspath);
+ throw klay::Exception("Failed to open namesapce: " + nspath);
}
} else {
if (::setns(fd, ns.second)) {
::close(fd);
- throw runtime::Exception("Failed to set namespace: " + nspath);
+ throw klay::Exception("Failed to set namespace: " + nspath);
}
::close(fd);
}
void Namespace::unshare(int flags)
{
if (::unshare(flags)) {
- throw runtime::Exception("Failed to unshare namespace");
+ throw klay::Exception("Failed to unshare namespace");
}
if (flags & CLONE_NEWNS &&
::mount(NULL, "/", NULL, MS_SLAVE | MS_REC, NULL) == -1) {
- throw runtime::Exception("Failed to mount root filesystem");
+ throw klay::Exception("Failed to mount root filesystem");
}
}
{
fd = ::socket(PF_NETLINK, SOCK_RAW, protocol);
if (fd < 0) {
- throw runtime::Exception(runtime::GetSystemErrorMessage());
+ throw klay::Exception(klay::GetSystemErrorMessage());
}
if (::fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) {
::close(fd);
- throw runtime::Exception(runtime::GetSystemErrorMessage());
+ throw klay::Exception(klay::GetSystemErrorMessage());
}
}
} while (ret < 0 && errno == EINTR);
if (ret < 0) {
- throw runtime::Exception("Failed to send a netlink message");
+ throw klay::Exception("Failed to send a netlink message");
}
if (recv(MSG_PEEK).first == NLMSG_ERROR) {
auto reply = recv().second;
auto err = (struct nlmsgerr*)reply.data();
if (err->error)
- throw runtime::Exception("Netlink error: " +
+ throw klay::Exception("Netlink error: " +
std::to_string(err->error));
} else {
WARN("Missing ack of netlink message");
} while (ret < 0 && errno == EINTR);
if (ret < 0) {
- throw runtime::Exception("Failed to get the size of netlink message");
+ throw klay::Exception("Failed to get the size of netlink message");
}
struct sockaddr_nl nladdr;
::memcpy(msg.second.data(), NLMSG_DATA(buf), msg.second.size());
if (ret < 0) {
- throw runtime::Exception("Failed to receive audit packet");
+ throw klay::Exception("Failed to receive audit packet");
}
if (nladdrlen != sizeof(nladdr)) {
- throw runtime::Exception("Bad address size in netlink socket");
+ throw klay::Exception("Bad address size in netlink socket");
}
if (nladdr.nl_pid) {
- throw runtime::Exception("Spoofed packet received on netlink socket");
+ throw klay::Exception("Spoofed packet received on netlink socket");
}
return msg;
}
-} // namespace runtime
+} // namespace klay
} // namespace klay
int error = ::pam_start(service.c_str(), user.c_str(), &pamc, &pamh);
if (error != PAM_SUCCESS) {
- throw runtime::Exception("PAM Error");
+ throw klay::Exception("PAM Error");
}
}
{
int error = ::pam_end(pamh, PAM_SUCCESS);
if (error != PAM_SUCCESS) {
- throw runtime::Exception("PAM Error");
+ throw klay::Exception("PAM Error");
}
}
{
int error = ::pam_set_data(pamh, name.c_str(), data, cleanup);
if (error != PAM_SUCCESS) {
- throw runtime::Exception("PAM Error");
+ throw klay::Exception("PAM Error");
}
}
const void* ret;
int error = ::pam_get_data(pamh, name.c_str(), &ret);
if (error != PAM_SUCCESS) {
- throw runtime::Exception("PAM Error");
+ throw klay::Exception("PAM Error");
}
return ret;
}
{
int error = ::pam_set_item(pamh, item, data);
if (error != PAM_SUCCESS) {
- throw runtime::Exception("PAM Error");
+ throw klay::Exception("PAM Error");
}
}
const void* ret;
int error = ::pam_get_item(pamh, item, &ret);
if (error != PAM_SUCCESS) {
- throw runtime::Exception("PAM Error");
+ throw klay::Exception("PAM Error");
}
return ret;
}
const char* user;
int error = ::pam_get_user(pamh, &user, prompt.c_str());
if (error != PAM_SUCCESS) {
- throw runtime::Exception("PAM Error");
+ throw klay::Exception("PAM Error");
}
return std::string(user);
}
{
int error = ::pam_putenv(pamh, name_value.c_str());
if (error != PAM_SUCCESS) {
- throw runtime::Exception("PAM Error");
+ throw klay::Exception("PAM Error");
}
}
{
const char* value = ::pam_getenv(pamh, name.c_str());
if (value == NULL) {
- throw runtime::Exception("PAM Error");
+ throw klay::Exception("PAM Error");
}
return value;
}
std::vector<std::string> ret;
char** array = ::pam_getenvlist(pamh);
if (array == NULL) {
- throw runtime::Exception("PAM Error");
+ throw klay::Exception("PAM Error");
}
for (int i = 0; array[i] != NULL; i++) {
ret.push_back(array[i]);
{
int error = ::pam_open_session(pamh, flags);
if (error != PAM_SUCCESS) {
- throw runtime::Exception("PAM Error");
+ throw klay::Exception("PAM Error");
}
}
{
int error = ::pam_close_session(pamh, flags);
if (error != PAM_SUCCESS) {
- throw runtime::Exception("PAM Error");
+ throw klay::Exception("PAM Error");
}
}
void Process::kill()
{
if (::kill(pid, SIGKILL) == -1) {
- throw runtime::Exception(runtime::GetSystemErrorMessage());
+ throw klay::Exception(klay::GetSystemErrorMessage());
}
}
void Process::terminate()
{
if (::kill(pid, SIGINT) == -1) {
- throw runtime::Exception(runtime::GetSystemErrorMessage());
+ throw klay::Exception(klay::GetSystemErrorMessage());
}
}
void DefaultExceptionModel::raise(const std::string& target, const std::string& msg)
{
if (target == "InvalidArgumentException")
- throw runtime::InvalidArgumentException(msg);
+ throw klay::InvalidArgumentException(msg);
else if (target == "NotImplementedException")
- throw runtime::InvalidArgumentException(msg);
+ throw klay::InvalidArgumentException(msg);
else if (target == "RangeException")
- throw runtime::RangeException(msg);
+ throw klay::RangeException(msg);
else if (target == "NotFoundException")
- throw runtime::NotFoundException(msg);
+ throw klay::NotFoundException(msg);
else if (target == "UnsupportedException")
- throw runtime::UnsupportedException(msg);
+ throw klay::UnsupportedException(msg);
else if (target == "NoPermissionException")
- throw runtime::NoPermissionException(msg);
+ throw klay::NoPermissionException(msg);
else if (target == "IOException")
- throw runtime::IOException(msg);
+ throw klay::IOException(msg);
else if (target == "OutOfMemoryException")
- throw runtime::OutOfMemoryException(msg);
+ throw klay::OutOfMemoryException(msg);
else
- throw runtime::Exception(msg);
+ throw klay::Exception(msg);
}
} // namespace rmi
return error;
}
-template<> void Message::enclose(runtime::FileDescriptor&& fd)
+template<> void Message::enclose(klay::FileDescriptor&& fd)
{
if (fd.fileDescriptor == -1) {
- throw runtime::Exception("Invalid file descriptor");
+ throw klay::Exception("Invalid file descriptor");
}
fileDescriptors.push_back(std::move(fd));
}
-template<> void Message::disclose(runtime::FileDescriptor& fd)
+template<> void Message::disclose(klay::FileDescriptor& fd)
{
if (!fileDescriptors.empty()) {
fd.fileDescriptor = std::move(fileDescriptors.front()).fileDescriptor;
{
int fds[2] = {-1, -1};
if (::socketpair(AF_UNIX, SOCK_STREAM, 0, fds) == -1) {
- throw runtime::Exception("Failed to create socket pair");
+ throw klay::Exception("Failed to create socket pair");
}
std::lock_guard<std::mutex> lock(subscriberLock);
void Service::prepare(bool activation)
{
socket.reset(new Socket(Socket::create(address, activation)));
- auto accept = [&](int fd, runtime::Mainloop::Event event) {
+ auto accept = [&](int fd, klay::Mainloop::Event event) {
onNewConnection(std::make_shared<Connection>(socket->accept()));
};
void Service::setNewConnectionCallback(const ConnectionCallback& connectionCallback)
{
auto callback = [connectionCallback, this](const std::shared_ptr<Connection>& connection) {
- auto handle = [&](int fd, runtime::Mainloop::Event event) {
+ auto handle = [&](int fd, klay::Mainloop::Event event) {
std::lock_guard<std::mutex> lock(stateLock);
auto iter = getConnectionIterator(fd);
std::lock_guard<std::mutex> lock(notificationLock);
if (notificationRegistry.count(name)) {
- throw runtime::Exception("Notification already registered");
+ throw klay::Exception("Notification already registered");
}
notificationRegistry.emplace(name, Notification(name));
int Service::subscribeNotification(const std::string& name)
{
- auto closeHandler = [&, name, this](int fd, runtime::Mainloop::Event event) {
+ auto closeHandler = [&, name, this](int fd, klay::Mainloop::Event event) {
if ((event & EPOLLHUP) || (event & EPOLLRDHUP)) {
unsubscribeNotification(name, fd);
return;
SubscriptionId slot = notification.createSubscriber();
mainloop.addEventSource(slot.first, EPOLLHUP | EPOLLRDHUP, closeHandler);
return slot.second;
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
ERROR(KSINK, e.what());
return -1;
}
auto process = [&, connection](Message& request) {
try {
if (!methodRegistry.count(request.target()))
- throw runtime::NotFoundException("Method not found");
+ throw klay::NotFoundException("Method not found");
std::shared_ptr<MethodContext> methodContext = methodRegistry.at(request.target());
bool allowed = onPrivilegeCheck(processingContext.credentials, methodContext->privilege);
onAuditTrail(processingContext.credentials, request.target(), allowed);
if (!allowed) {
- throw runtime::NoPermissionException("Permission denied");
+ throw klay::NoPermissionException("Permission denied");
}
connection->send(methodContext->dispatcher(request));
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
try {
// Forward the exception to the peer
connection->send(request.createErrorMessage(e.className(), e.what()));
void setCloseOnExec(int fd)
{
if (::fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) {
- throw SocketException(runtime::GetSystemErrorMessage());
+ throw SocketException(klay::GetSystemErrorMessage());
}
}
struct ucred cred;
socklen_t credsz = sizeof(cred);
if (::getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &cred, &credsz)) {
- throw SocketException(runtime::GetSystemErrorMessage());
+ throw SocketException(klay::GetSystemErrorMessage());
}
if (::getsockopt(fd, SOL_SOCKET, SO_PEERSEC, buf, &length)) {
- throw SocketException(runtime::GetSystemErrorMessage());
+ throw SocketException(klay::GetSystemErrorMessage());
}
return {cred.pid, cred.uid, cred.gid, buf};
{
int sockfd = ::accept(socketFd, nullptr, nullptr);
if (sockfd == -1) {
- throw SocketException(runtime::GetSystemErrorMessage());
+ throw SocketException(klay::GetSystemErrorMessage());
}
setCloseOnExec(sockfd);
} else if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) {
continue;
} else {
- throw SocketException(runtime::GetSystemErrorMessage());
+ throw SocketException(klay::GetSystemErrorMessage());
}
}
}
} else if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) {
continue;
} else {
- throw SocketException(runtime::GetSystemErrorMessage());
+ throw SocketException(klay::GetSystemErrorMessage());
}
}
}
if (ret >= 0) {
written += ret;
} else if ((errno != EAGAIN) && (errno != EWOULDBLOCK) && (errno != EINTR)) {
- throw SocketException(runtime::GetSystemErrorMessage());
+ throw SocketException(klay::GetSystemErrorMessage());
}
}
}
bytes += ret;
} else {
if ((errno != EAGAIN) && (errno != EWOULDBLOCK) && (errno != EINTR)) {
- throw SocketException(runtime::GetSystemErrorMessage());
+ throw SocketException(klay::GetSystemErrorMessage());
}
}
}
int Socket::createRegularSocket(const std::string& path)
{
if (path.size() >= sizeof(sockaddr_un::sun_path)) {
- throw SocketException(runtime::GetSystemErrorMessage(ENAMETOOLONG));
+ throw SocketException(klay::GetSystemErrorMessage(ENAMETOOLONG));
}
int sockfd = ::socket(AF_UNIX, SOCK_STREAM, 0);
if (sockfd == -1) {
- throw SocketException(runtime::GetSystemErrorMessage());
+ throw SocketException(klay::GetSystemErrorMessage());
}
setCloseOnExec(sockfd);
if (::bind(sockfd, reinterpret_cast<struct sockaddr *>(&addr), sizeof(struct sockaddr_un)) == -1) {
::close(sockfd);
- throw SocketException(runtime::GetSystemErrorMessage());
+ throw SocketException(klay::GetSystemErrorMessage());
}
int optval = 1;
if (::setsockopt(sockfd, SOL_SOCKET, SO_PASSCRED, &optval, sizeof(optval)) == -1) {
::close(sockfd);
- throw SocketException(runtime::GetSystemErrorMessage());
+ throw SocketException(klay::GetSystemErrorMessage());
}
if (::listen(sockfd, MAX_BACKLOG_SIZE) == -1) {
::close(sockfd);
- throw SocketException(runtime::GetSystemErrorMessage());
+ throw SocketException(klay::GetSystemErrorMessage());
}
return sockfd;
Socket Socket::connect(const std::string& path)
{
if (path.size() >= sizeof(sockaddr_un::sun_path)) {
- throw SocketException(runtime::GetSystemErrorMessage(ENAMETOOLONG));
+ throw SocketException(klay::GetSystemErrorMessage(ENAMETOOLONG));
}
int fd = ::socket(AF_UNIX, SOCK_STREAM, 0);
if (fd == -1) {
- throw SocketException(runtime::GetSystemErrorMessage());
+ throw SocketException(klay::GetSystemErrorMessage());
}
setCloseOnExec(fd);
if (::connect(fd, reinterpret_cast<struct sockaddr *>(&addr), sizeof(struct sockaddr_un)) == -1) {
::close(fd);
- throw SocketException(runtime::GetSystemErrorMessage());
+ throw SocketException(klay::GetSystemErrorMessage());
}
return Socket(fd);
implementation(xmlNewDoc((const xmlChar*)version.c_str()))
{
if (implementation == nullptr) {
- throw runtime::Exception("Failed to create document");
+ throw klay::Exception("Failed to create document");
}
implementation->_private = this;
Node& Document::getRootNode()
{
if (rootNode == nullptr) {
- throw runtime::Exception("Empty document");
+ throw klay::Exception("Empty document");
}
return *rootNode;
{
auto ctxt = xmlXPathNewContext(implementation);
if (ctxt == nullptr) {
- throw runtime::Exception("Failed to create XPath context for " + xpath);
+ throw klay::Exception("Failed to create XPath context for " + xpath);
}
auto result = xmlXPathEval((const xmlChar*)xpath.c_str(), ctxt);
if (result == nullptr) {
xmlXPathFreeContext(ctxt);
- throw runtime::Exception("Invalid XPath: " + xpath);
+ throw klay::Exception("Invalid XPath: " + xpath);
}
if (result ->type != XPATH_NODESET) {
xmlXPathFreeObject(result);
xmlXPathFreeContext(ctxt);
- throw runtime::Exception("Only nodeset result types are supported");
+ throw klay::Exception("Only nodeset result types are supported");
}
auto nodeset = result->nodesetval;
encoding.c_str(),
formatted);
if (result == 0) {
- throw runtime::Exception("Failed to write XML document");
+ throw klay::Exception("Failed to write XML document");
}
}
{
xmlNode* nodePtr = xmlNewNode(NULL, xmlStrdup((const xmlChar*)name.c_str()));
if (nodePtr == nullptr) {
- throw runtime::Exception("Can not create a new node");
+ throw klay::Exception("Can not create a new node");
}
xmlAddChild(implementation, nodePtr);
std::string Node::getProp(const std::string& name) const
{
if (implementation->type != XML_ELEMENT_NODE) {
- throw runtime::Exception("This node type does not have properties");
+ throw klay::Exception("This node type does not have properties");
}
xmlChar* prop = xmlGetProp(implementation, (xmlChar*)name.c_str());
void Node::setProp(const std::string& name, const std::string& val)
{
if (implementation->type != XML_ELEMENT_NODE) {
- throw runtime::Exception("Can not set properties for this node type");
+ throw klay::Exception("Can not set properties for this node type");
}
xmlSetProp(implementation, (xmlChar*)name.c_str(), (xmlChar*)val.c_str());
Document* Parser::parseContext(xmlParserCtxt* context, bool validate)
{
if (context == nullptr) {
- throw runtime::Exception("Could not create parser context");
+ throw klay::Exception("Could not create parser context");
}
KeepBlanks(false);
if (xmlParseDocument(context) < 0) {
xmlFreeParserCtxt(context);
- throw runtime::Exception("Parsing failed");
+ throw klay::Exception("Parsing failed");
}
xmlDoc* document = context->myDoc;
{
xmlParserCtxt* context = xmlCreateFileParserCtxt(filename.c_str());
if (context == nullptr) {
- throw runtime::Exception("Could not create parser context");
+ throw klay::Exception("Could not create parser context");
}
if (context->directory == nullptr) {
xmlParserCtxt* context = xmlCreateMemoryParserCtxt(xml.c_str(), xml.size() + 1);
if (context == nullptr) {
- throw runtime::Exception("Could not create parser context");
+ throw klay::Exception("Could not create parser context");
}
return parseContext(context, validate);
TESTCASE(GetGroupTest)
{
try {
- runtime::Group group("users");
- runtime::Group another(group);
- } catch (runtime::Exception& e) {
+ klay::Group group("users");
+ klay::Group another(group);
+ } catch (klay::Exception& e) {
TEST_FAIL(e.what());
}
}
TESTCASE(GetUserTest)
{
try {
- runtime::User user("root");
- runtime::User another(user);
- } catch (runtime::Exception& e) {
+ klay::User user("root");
+ klay::User another(user);
+ } catch (klay::Exception& e) {
TEST_FAIL(e.what());
}
}
TESTCASE(GetGroupNegativeTest)
{
try {
- runtime::Group group("invalid");
- } catch (runtime::Exception& e) {
+ klay::Group group("invalid");
+ } catch (klay::Exception& e) {
}
}
TESTCASE(GetGroupNegativeTest2)
{
try {
- runtime::Group group(-1);
- } catch (runtime::Exception& e) {
+ klay::Group group(-1);
+ } catch (klay::Exception& e) {
}
}
TESTCASE(GetUserNegativetest)
{
try {
- runtime::User user("invalid");
- } catch (runtime::Exception& e) {
+ klay::User user("invalid");
+ } catch (klay::Exception& e) {
}
}
TESTCASE(GetUserNegativetest2)
{
try {
- runtime::User user(-1);
- } catch (runtime::Exception& e) {
+ klay::User user(-1);
+ } catch (klay::Exception& e) {
}
}
TESTCASE(GetCurrentGroupTest)
{
try {
- runtime::Group group;
- runtime::Group another(group.getGid());
- } catch (runtime::Exception& e) {
+ klay::Group group;
+ klay::Group another(group.getGid());
+ } catch (klay::Exception& e) {
}
}
TESTCASE(GetCurrentUserTest)
{
try {
- runtime::User user;
- runtime::User another(user.getUid());
- } catch (runtime::Exception& e) {
+ klay::User user;
+ klay::User another(user.getUid());
+ } catch (klay::Exception& e) {
}
}
try {
database::Connection db(TestbenchDataSource, database::Connection::ReadWrite | database::Connection::Create);
db.exec(query);
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
TEST_FAIL(e.what());
}
}
try {
database::Connection db(TestbenchDataSource, database::Connection::ReadWrite | database::Connection::Create);
database::Statement stmt(db, "INVALID STATEMENT");
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
}
}
try {
database::Connection db(TestbenchDataSource, database::Connection::ReadWrite | database::Connection::Create);
db.exec("INVALID");
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
}
}
TEST_EXPECT(5, select.getColumnCount());
stmt.clearBindings();
stmt.reset();
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
TEST_FAIL(e.what());
}
}
stmt.bind(3, false);
stmt.bind(4, 5001);
stmt.exec();
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
TEST_FAIL(e.what());
}
}
stmt.bind(":IS_USED", true);
stmt.bind(":USER", 5001);
stmt.exec();
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
TEST_FAIL(e.what());
}
}
database::Statement stmt(db, query);
stmt.bind(":PKG");
stmt.bind(2);
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
TEST_FAIL(e.what());
}
}
stmt.bind(":IS_USED", used);
stmt.bind(":USER", user);
stmt.exec();
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
TEST_FAIL(e.what());
}
}
key.getName(); key.getText(); key.getType(); key.getBytes(); key.getBlob();
used.getName(); used.getInt(); used.getInt64(); used.getDouble(); used.getType(); used.getBytes();
}
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
TEST_FAIL(e.what());
}
}
database::Statement select(db, "SELECT * FROM CLIENT");
select.step();
database::Column column = select.getColumn(32);
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
}
}
database::Statement select(db, "SELECT * FROM CLIENT");
select.step();
select.isNullColumn(32);
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
}
}
database::Statement select(db, "SELECT * FROM CLIENT");
select.step();
select.getColumnName(32);
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
}
}
database::Statement stmt(db, query);
try {
stmt.bind(":TPK", "TEST PACKAGE");
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
}
try {
stmt.bind(":TPK", (int)10);
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
}
try {
stmt.bind(":TPK", (sqlite3_int64)10);
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
}
try {
stmt.bind(":TPK", (double)10);
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
}
try {
stmt.bind(":TPK", "invalid");
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
}
try {
stmt.bind(":TPK", std::string("invalid"));
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
}
try {
stmt.bind(":TPK", (void *)NULL, 12);
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
}
try {
stmt.bind(":TPK");
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
}
stmt.exec();
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
}
}
database::Statement stmt(db, query);
try {
stmt.bind(32, "TEST PACKAGE");
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
}
try {
stmt.bind(32, (int)10);
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
}
try {
stmt.bind(32, (sqlite3_int64)10);
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
}
try {
stmt.bind(32, (double)10);
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
}
try {
stmt.bind(32, "invalid");
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
}
try {
stmt.bind(32, std::string("invalid"));
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
}
try {
stmt.bind(32, (void *)NULL, 12);
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
}
try {
stmt.bind(32);
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
}
stmt.exec();
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
}
}
{
try {
database::Connection db("/tmp/invalid.db", database::Connection::ReadWrite);
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
}
}
{
ScopedGMainLoop mainloop;
mainloop.dispatch([&](){
- runtime::Latch nameAcquired;
+ klay::Latch nameAcquired;
auto handler = [](const std::string& objectPath,
const std::string& interface,
const std::string& methodName,
dbus::Variant parameters) {
if (objectPath != TESTSVC_OBJECT_PATH || interface != TESTSVC_INTERFACE) {
- throw runtime::Exception("Unknown Method");
+ throw klay::Exception("Unknown Method");
}
if (methodName == TESTSVC_METHOD_NOOP) {
return dbus::Variant();
TESTCASE(EventFdHandleNegative)
{
try {
- runtime::EventFD evtfd(0, -1);
- } catch (runtime::Exception& e) {
+ klay::EventFD evtfd(0, -1);
+ } catch (klay::Exception& e) {
}
}
TESTCASE(EventFdSendPositive)
{
try {
- runtime::EventFD evtfd;
+ klay::EventFD evtfd;
evtfd.send();
evtfd.receive();
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
TEST_FAIL(e.what());
}
}
TESTCASE(EventFdSendNegative)
{
try {
- runtime::EventFD evtfd;
+ klay::EventFD evtfd;
evtfd.close();
evtfd.send();
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
}
}
TESTCASE(EventFdReceiveNegative)
{
try {
- runtime::EventFD evtfd;
+ klay::EventFD evtfd;
evtfd.close();
evtfd.receive();
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
}
}
TESTCASE(DirectoryIteration)
{
- runtime::DirectoryIterator iter("/dev");
- runtime::DirectoryIterator end;
+ klay::DirectoryIterator iter("/dev");
+ klay::DirectoryIterator end;
TEST_EXPECT(false, iter == end);
TESTCASE(FileIO)
{
char testbuf[100] = "Test Data";
- runtime::File tmp("/tmp/test-file");
+ klay::File tmp("/tmp/test-file");
try {
tmp.create(0755);
tmp.lock();
tmp.lseek(10, SEEK_SET);
tmp.unlock();
tmp.close();
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
TEST_FAIL(e.what());
}
char readbuf[100];
try {
- runtime::File tmpFile("/tmp/test-file", O_RDWR);
+ klay::File tmpFile("/tmp/test-file", O_RDWR);
tmpFile.read(readbuf, ::strlen(testbuf));
tmpFile.close();
tmpFile.remove();
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
TEST_FAIL(e.what());
}
}
TESTCASE(DirOperation)
{
- runtime::File testDir("/tmp/dpm-unit-test/dir");
+ klay::File testDir("/tmp/dpm-unit-test/dir");
try {
testDir.makeDirectory(true, ::getuid(), ::getgid());
testDir.chown(::getuid(), ::getgid(), false);
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
TEST_FAIL(e.what());
}
- runtime::File dir("/tmp/dpm-unit-test");
+ klay::File dir("/tmp/dpm-unit-test");
try {
dir.chmod(777, true);
dir.remove(true);
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
TEST_FAIL(e.what());
}
}
TESTCASE(FileAttribute)
{
- runtime::File tmp("/tmp");
+ klay::File tmp("/tmp");
TEST_EXPECT(true, tmp.exists());
TEST_EXPECT(true, tmp.canRead());
TESTCASE(FileAttributeNegative)
{
try {
- runtime::File tmp("/unknown");
+ klay::File tmp("/unknown");
TEST_EXPECT(false, tmp.exists());
TEST_EXPECT(false, tmp.canRead());
try {
tmp.isLink();
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
}
try {
tmp.isFile();
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
}
try {
tmp.isDirectory();
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
}
try {
tmp.isDevice();
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
}
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
}
}
TESTCASE(FileDevice)
{
- runtime::File tmp("/dev/kmem");
+ klay::File tmp("/dev/kmem");
TEST_EXPECT(true, tmp.isDevice());
}
TESTCASE(FileSymlinkTest)
{
- runtime::File tmp("/var");
+ klay::File tmp("/var");
TEST_EXPECT(true, tmp.isLink());
}
TESTCASE(FileReferenceTest)
{
- runtime::File one("/tmp");
- runtime::File two(one);
+ klay::File one("/tmp");
+ klay::File two(one);
}
{
try {
audit::LogLevelToString((audit::LogLevel)-1);
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
}
}
TESTCASE(ErrorMessage)
{
- std::cout << "Error Message: " << runtime::GetSystemErrorMessage(EINTR) << std::endl;
+ std::cout << "Error Message: " << klay::GetSystemErrorMessage(EINTR) << std::endl;
}
"-l",
"-a"
};
- runtime::Process proc("/bin/ls > /dev/null", args);
+ klay::Process proc("/bin/ls > /dev/null", args);
TEST_EXPECT(true, proc.execute() != -1);
proc.waitForFinished();
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
}
}
TESTCASE(ProcKill)
{
try {
- runtime::Process proc("/opt/data/unittest-proc.sh");
+ klay::Process proc("/opt/data/unittest-proc.sh");
TEST_EXPECT(true, proc.execute() != -1);
if (proc.isRunning()) {
proc.kill();
proc.waitForFinished();
}
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
}
}
TESTCASE(ProcTerminate)
{
try {
- runtime::Process proc("/opt/data/unittest-proc.sh");
+ klay::Process proc("/opt/data/unittest-proc.sh");
TEST_EXPECT(true, proc.execute() != -1);
if (proc.isRunning()) {
proc.terminate();
proc.waitForFinished();
}
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
}
}
TESTCASE(ProcInvalidProcess)
{
try {
- runtime::Process proc(TEST_DATA_DIR "test-proc.sh");
+ klay::Process proc(TEST_DATA_DIR "test-proc.sh");
TEST_EXPECT(true, proc.execute() != -1);
proc.terminate();
proc.waitForFinished();
TEST_EXPECT(false, proc.isRunning());
try {
proc.kill();
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
}
try {
proc.terminate();
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
}
try {
proc.waitForFinished();
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
}
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
}
}
service->expose(this, "", (std::string)(TestServer::method3)(std::string, std::string, std::string));
service->expose(this, "", (std::string)(TestServer::method4)(std::string, std::string, std::string, std::string));
- service->expose(this, "", (runtime::FileDescriptor)(TestServer::signalProvider)(std::string));
- service->expose(this, "", (runtime::FileDescriptor)(TestServer::policyNotificationProvider)(std::string));
+ service->expose(this, "", (klay::FileDescriptor)(TestServer::signalProvider)(std::string));
+ service->expose(this, "", (klay::FileDescriptor)(TestServer::policyNotificationProvider)(std::string));
service->expose(this, "", (int)(TestServer::sendSignal)());
service->expose(this, "", (int)(TestServer::sendPolicyChangeNotification)());
return 0;
}
- runtime::FileDescriptor signalProvider(const std::string& name)
+ klay::FileDescriptor signalProvider(const std::string& name)
{
return service->subscribeNotification(name);
}
- runtime::FileDescriptor policyNotificationProvider(const std::string& name)
+ klay::FileDescriptor policyNotificationProvider(const std::string& name)
{
return service->subscribeNotification(name);
}
TestClient client;
client.connect();
client.disconnect();
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
ERROR(KSINK, e.what());
}
}
client.requestPolicyChangeNotification();
client.disconnect();
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
ERROR(KSINK, e.what());
}
}
client.requestPolicyChangeNotification();
client.disconnect();
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
ERROR(KSINK, e.what());
}
}
while (iter != nodes.end()) {
++iter;
}
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
TEST_FAIL(e.what());
}
}
while (iter != list.end()) {
++iter;
}
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
TEST_FAIL(e.what());
}
}
TEST_EXPECT("Value", node.getProp("Prop"));
doc.write("/tmp/test.xml", "UTF-8", true);
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
TEST_FAIL(e.what());
}
}
{
try {
xml::Parser::parseFile("Invalid Source");
- } catch (runtime::Exception& e) {
+ } catch (klay::Exception& e) {
}
}