throw std::system_error(EEXIST, std::generic_category(),
"Subsession directory already exists");
- const auto tmp_subsession_path = fs::path(subsession_path)
- .replace_filename(".tmpnew"s + subsession_path.filename().native());
+ auto tmp_subsession_path = fs::path(subsession_path);
+ tmp_subsession_path.replace_filename(".tmpnew"s + subsession_path.filename().native());
fs::create_directory(tmp_subsession_path);
| fs::perms::group_read | fs::perms::group_exec;
for (auto const& entry : fs::recursive_directory_iterator(source_path)) {
- const auto s_path = entry.path();
+ const auto& s_path = entry.path();
/* Do string manipulation instead of `fs::relative(source_path, entry)`,
* because relative() resolves symlinks which gives different behaviour. */
std::string OS::get_home_dir_by_user_id(const int uid)
{
auto max_buf_size = static_cast<ssize_t>(sysconf(_SC_GETPW_R_SIZE_MAX));
- std::runtime_error err("Couldn't get home directory for session_uid=" + std::to_string(uid));
-
if (max_buf_size <= 0)
- throw err;
+ throw std::runtime_error("Couldn't acquire buffer size for `getpwuid_r` system call");
std::unique_ptr<char[]> str_buf(new char[max_buf_size]);
// N.B. `new` throws `std::bad_alloc` exception if it runs out of memory,
// so there's no need to check if it's successful here
- passwd pass_buf, *pass_ptr;
- getpwuid_r(uid, &pass_buf, str_buf.get(), max_buf_size, &pass_ptr);
+ passwd pass_buf;
+ passwd *pass_ptr = NULL;
+ const int ret = getpwuid_r(uid, &pass_buf, str_buf.get(), max_buf_size, &pass_ptr);
+ if (ret < 0)
+ throw std::system_error(errno, std::generic_category()
+ , "Couldn't get home directory for session_uid=" + std::to_string(uid));
if (!pass_ptr)
- throw err;
+ throw std::runtime_error("Couldn't get home directory (user does not exist) "
+ "for session_uid=" + std::to_string(uid));
return std::string(pass_ptr->pw_dir);
}
std::unique_ptr<char[]> str_grp_buf(new char[max_grp_buf_size]);
- group pass_grp_buf, *pass_grp_ptr;
- getgrnam_r(group_name.data(), &pass_grp_buf, str_grp_buf.get(), max_grp_buf_size, &pass_grp_ptr);
- if (!pass_grp_ptr)
- throw std::runtime_error("Couldn't get Unix gid for `"s
+ group pass_grp_buf;
+ group *pass_grp_ptr = NULL;
+ const int ret = getgrnam_r(group_name.data(), &pass_grp_buf, str_grp_buf.get(), max_grp_buf_size, &pass_grp_ptr);
+ if (ret < 0)
+ throw std::system_error(errno, std::generic_category()
+ ,"Couldn't get Unix gid for `"s
+ group_name.data()
+ "` group");
+
+ if (pass_grp_ptr == NULL)
+ throw std::runtime_error("Couldn't get Unix gid for `"s
+ + group_name.data()
+ + "` group - does not exist");
+
return pass_grp_ptr->gr_gid;
}