[remote] fix handling of absolute symlinks

pull/1031/head v0.11.0-beta1
Tim Stack 2 years ago
parent f73e71cf30
commit 270d44c6b4

@ -56,7 +56,18 @@ service_base::run()
this->s_port.process_for(timeout);
this->s_children.cleanup_children();
this->loop_body();
try {
this->loop_body();
} catch (const std::exception& e) {
log_error("%s: loop_body() failed with -- %s",
this->s_name.c_str(),
e.what());
this->s_looping = false;
} catch (...) {
log_error("%s: loop_body() failed with non-standard exception",
this->s_name.c_str());
this->s_looping = false;
}
}
if (!this->s_children.empty()) {
log_debug("stopping children of service: %s", this->s_name.c_str());

@ -109,10 +109,7 @@ struct supervisor {
~supervisor();
bool empty() const
{
return this->s_service_list.empty();
}
bool empty() const { return this->s_service_list.empty(); }
void add_child_service(std::shared_ptr<service_base> new_service);
@ -134,15 +131,9 @@ public:
virtual ~service_base() = default;
bool is_looping() const
{
return this->s_looping;
}
bool is_looping() const { return this->s_looping; }
msg_port& get_port()
{
return this->s_port;
}
msg_port& get_port() { return this->s_port; }
friend supervisor;
@ -153,16 +144,16 @@ private:
protected:
virtual void* run();
virtual void loop_body(){};
virtual void child_finished(std::shared_ptr<service_base> child){};
virtual void stopped(){};
virtual void loop_body() {}
virtual void child_finished(std::shared_ptr<service_base> child) {}
virtual void stopped() {}
virtual std::chrono::milliseconds compute_timeout(
mstime_t current_time) const
{
using namespace std::literals::chrono_literals;
return 1s;
};
}
const std::string s_name;
bool s_started{false};

@ -31,6 +31,7 @@
#include "tailer.looper.hh"
#include "base/fs_util.hh"
#include "base/humanize.network.hh"
#include "base/lnav_log.hh"
#include "base/paths.hh"
@ -702,7 +703,8 @@ tailer::looper::host_tailer::loop_body()
ghc::filesystem::path(pob.pob_path))
.relative_path();
auto local_path = this->ht_local_path / remote_path;
auto fd = auto_fd(::open(local_path.c_str(), O_RDONLY));
auto open_res
= lnav::filesystem::open_file(local_path, O_RDONLY);
if (this->ht_active_files.count(local_path) == 0) {
this->ht_active_files.insert(local_path);
@ -744,8 +746,9 @@ tailer::looper::host_tailer::loop_body()
});
}
if (fd == -1) {
log_debug("file not found, sending need block");
if (open_res.isErr()) {
log_debug("file not found (%s), sending need block",
open_res.unwrapErr().c_str());
send_packet(conn.ht_to_child.get(),
TPT_NEED_BLOCK,
TPPT_STRING,
@ -754,6 +757,7 @@ tailer::looper::host_tailer::loop_body()
return std::move(this->ht_state);
}
auto fd = open_res.unwrap();
struct stat st;
if (fstat(fd, &st) == -1 || !S_ISREG(st.st_mode)) {
@ -848,12 +852,13 @@ tailer::looper::host_tailer::loop_body()
ptb.ptb_bits.size(),
local_path.c_str());
ghc::filesystem::create_directories(local_path.parent_path());
auto fd = auto_fd(::open(
local_path.c_str(), O_WRONLY | O_APPEND | O_CREAT, 0600));
auto create_res = lnav::filesystem::create_file(
local_path, O_WRONLY | O_APPEND | O_CREAT, 0600);
if (fd == -1) {
log_error("open: %s", strerror(errno));
if (create_res.isErr()) {
log_error("open: %s", create_res.unwrapErr().c_str());
} else {
auto fd = create_res.unwrap();
ftruncate(fd, ptb.ptb_offset);
pwrite(fd,
ptb.ptb_bits.data(),
@ -932,7 +937,7 @@ tailer::looper::host_tailer::loop_body()
auto remote_link_path = ghc::filesystem::path(pl.pl_link_value);
std::string link_path;
if (remote_path.is_absolute()) {
if (remote_link_path.is_absolute()) {
auto local_link_path = this->ht_local_path
/ remote_link_path.relative_path();

Loading…
Cancel
Save