}
}
-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) {
connection->send(request.createErrorMessage(e.className(), e.what()));
} catch (std::exception& e) {
try {
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);