mirror of
https://github.com/paulscherrerinstitute/sf_daq_buffer.git
synced 2026-05-13 07:05:38 +02:00
Merge buffer and writer utils
This commit is contained in:
@@ -9,7 +9,6 @@
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "BufferUtils.hpp"
|
||||
#include "WriterUtils.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -81,7 +80,7 @@ void BufferBinaryWriter::open_file(const std::string& filename)
|
||||
{
|
||||
close_current_file();
|
||||
|
||||
WriterUtils::create_destination_folder(filename);
|
||||
BufferUtils::create_destination_folder(filename);
|
||||
|
||||
output_file_fd_ = ::open(filename.c_str(), O_WRONLY | O_CREAT,
|
||||
S_IRWXU | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
#include <iostream>
|
||||
#include <unistd.h>
|
||||
#include <filesystem>
|
||||
|
||||
#include "WriterUtils.hpp"
|
||||
#include "date.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
void WriterUtils::set_process_effective_id(int user_id)
|
||||
{
|
||||
|
||||
// TODO: use setfsuid and setfsgid
|
||||
|
||||
if (setegid(user_id)) {
|
||||
stringstream err_msg;
|
||||
|
||||
using namespace date;
|
||||
using namespace chrono;
|
||||
err_msg << "[" << system_clock::now() << "]";
|
||||
err_msg << "[WriterUtils::set_process_effective_id]";
|
||||
err_msg << " Cannot set group_id to " << user_id << endl;
|
||||
|
||||
throw runtime_error(err_msg.str());
|
||||
}
|
||||
|
||||
if (seteuid(user_id)) {
|
||||
stringstream err_msg;
|
||||
|
||||
using namespace date;
|
||||
using namespace chrono;
|
||||
err_msg << "[" << system_clock::now() << "]";
|
||||
err_msg << "[WriterUtils::set_process_effective_id]";
|
||||
err_msg << " Cannot set user_id to " << user_id << endl;
|
||||
|
||||
throw runtime_error(err_msg.str());
|
||||
}
|
||||
}
|
||||
|
||||
void WriterUtils::create_destination_folder(const string& output_file)
|
||||
{
|
||||
auto file_separator_index = output_file.rfind('/');
|
||||
|
||||
if (file_separator_index != string::npos) {
|
||||
|
||||
string output_folder(output_file.substr(0, file_separator_index));
|
||||
|
||||
// TODO: filesystem::create_directories(output_folder)
|
||||
string create_folder_command("mkdir -p " + output_folder);
|
||||
system(create_folder_command.c_str());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user