From b38bd6e2fed6ef37565a43849e12cb09f79d7468 Mon Sep 17 00:00:00 2001 From: Timothy Stack Date: Wed, 9 Jun 2021 22:43:55 -0700 Subject: [PATCH] [tailer] send the uname of the remote host back --- src/file_collection.cc | 2 +- src/file_collection.hh | 12 +++++++++++- src/files_sub_source.cc | 5 +++-- src/lnav.cc | 7 ++++--- src/tailer/drive_tailer.cc | 2 ++ src/tailer/tailer.h | 1 + src/tailer/tailer.looper.cc | 23 +++++++++++++++++++++++ src/tailer/tailer.main.c | 24 ++++++++++++++++++++++++ src/tailer/tailerpp.cc | 6 ++++++ src/tailer/tailerpp.hh | 18 +++++++++++++++--- 10 files changed, 90 insertions(+), 10 deletions(-) diff --git a/src/file_collection.cc b/src/file_collection.cc index 018fb715..be4f4d26 100644 --- a/src/file_collection.cc +++ b/src/file_collection.cc @@ -251,7 +251,7 @@ file_collection::watch_logfile(const std::string &filename, switch (ff) { case file_format_t::FF_SQLITE_DB: - retval.fc_other_files[filename] = ff; + retval.fc_other_files[filename].ofd_format = ff; break; case file_format_t::FF_ARCHIVE: { diff --git a/src/file_collection.hh b/src/file_collection.hh index e92cef1c..cf264d34 100644 --- a/src/file_collection.hh +++ b/src/file_collection.hh @@ -36,6 +36,7 @@ #include #include #include +#include #include "safe/safe.h" @@ -56,6 +57,15 @@ struct scan_progress { using safe_scan_progress = safe::Safe; +struct other_file_descriptor { + file_format_t ofd_format; + std::string ofd_description; + + other_file_descriptor(file_format_t format = file_format_t::FF_UNKNOWN, + std::string description = "") + : ofd_format(format), ofd_description(std::move(description)) {} +}; + struct file_collection { bool fc_recursive{false}; bool fc_rotated{false}; @@ -67,7 +77,7 @@ struct file_collection { std::vector, std::string>> fc_renamed_files; std::set fc_closed_files; - std::map fc_other_files; + std::map fc_other_files; std::set fc_synced_files; std::shared_ptr fc_progress; std::vector fc_new_stats; diff --git a/src/files_sub_source.cc b/src/files_sub_source.cc index 8c95e795..361b2a2c 100644 --- a/src/files_sub_source.cc +++ b/src/files_sub_source.cc @@ -192,8 +192,9 @@ void files_sub_source::text_value_for_line(textview_curses &tc, int line, truncate_to(fn, filename_width); value_out = fmt::format( - FMT_STRING(" {:<{}} {}"), - fn, filename_width, iter->second); + FMT_STRING(" {:<{}} {: >16} {}"), + fn, filename_width, iter->second.ofd_format, + iter->second.ofd_description); return; } diff --git a/src/lnav.cc b/src/lnav.cc index 5bb42314..f21c140b 100644 --- a/src/lnav.cc +++ b/src/lnav.cc @@ -893,7 +893,7 @@ bool update_active_files(const file_collection& new_files) lnav_data.ld_text_source.push_back(lf); } for (const auto& other_pair : new_files.fc_other_files) { - switch (other_pair.second) { + switch (other_pair.second.ofd_format) { case file_format_t::FF_SQLITE_DB: attach_sqlite_db(lnav_data.ld_db.in(), other_pair.first); break; @@ -925,7 +925,7 @@ bool rescan_files(bool req) mlooper.get_port().process_for(delay); if (lnav_data.ld_flags & LNF_HEADLESS) { for (const auto& pair : lnav_data.ld_active_files.fc_other_files) { - if (pair.second != file_format_t::FF_REMOTE) { + if (pair.second.ofd_format != file_format_t::FF_REMOTE) { continue; } @@ -1792,7 +1792,8 @@ static void looper() std::any_of(lnav_data.ld_active_files.fc_other_files.begin(), lnav_data.ld_active_files.fc_other_files.end(), [](const auto& pair) { - return pair.second == file_format_t::FF_SQLITE_DB; + return pair.second.ofd_format == + file_format_t::FF_SQLITE_DB; })) { ensure_view(&lnav_data.ld_views[LNV_SCHEMA]); } diff --git a/src/tailer/drive_tailer.cc b/src/tailer/drive_tailer.cc index f257e008..42f84d1b 100644 --- a/src/tailer/drive_tailer.cc +++ b/src/tailer/drive_tailer.cc @@ -162,6 +162,8 @@ int main(int argc, char *const *argv) printf("all done!\n"); done = true; }, + [&](const tailer::packet_announce &pa) { + }, [&](const tailer::packet_log &te) { printf("log: %s\n", te.pl_msg.c_str()); }, diff --git a/src/tailer/tailer.h b/src/tailer/tailer.h index b2cf4b7c..b8641372 100644 --- a/src/tailer/tailer.h +++ b/src/tailer/tailer.h @@ -58,6 +58,7 @@ typedef enum { TPT_PREVIEW_DATA, TPT_COMPLETE_PATH, TPT_POSSIBLE_PATH, + TPT_ANNOUNCE, } tailer_packet_type_t; #ifdef __cplusplus diff --git a/src/tailer/tailer.looper.cc b/src/tailer/tailer.looper.cc index 9bfb346e..af370ef2 100644 --- a/src/tailer/tailer.looper.cc +++ b/src/tailer/tailer.looper.cc @@ -534,6 +534,29 @@ void tailer::looper::host_tailer::loop_body() return state_v{disconnected()}; }, + [&](const tailer::packet_announce &pa) { + std::vector paths; + + for (const auto& des_pair : conn.c_desired_paths) { + paths.emplace_back(fmt::format( + "{}{}", this->ht_netloc, des_pair.first)); + } + isc::to() + .send([paths, pa](auto& mlooper) { + auto& fc = lnav_data.ld_active_files; + + for (const auto& path : paths) { + auto iter = fc.fc_other_files.find(path); + + if (iter == fc.fc_other_files.end()) { + continue; + } + + iter->second.ofd_description = pa.pa_uname; + } + }); + return std::move(this->ht_state); + }, [&](const tailer::packet_log &pl) { log_debug("%s\n", pl.pl_msg.c_str()); return std::move(this->ht_state); diff --git a/src/tailer/tailer.main.c b/src/tailer/tailer.main.c index 59637000..5588ec87 100644 --- a/src/tailer/tailer.main.c +++ b/src/tailer/tailer.main.c @@ -41,6 +41,7 @@ #include #include #include +#include #endif #include "sha-256.h" @@ -856,6 +857,29 @@ int main(int argc, char *argv[]) list_init(&client_path_list); + { + char buffer[1024]; + struct utsname un; + + if (uname(&un) != 0) { + strcpy(un.machine, "unknown"); + strcpy(un.version, "unknown"); + strcpy(un.release, "unknown"); + strcpy(un.sysname, "unknown"); + strcpy(un.nodename, "unknown"); + } + snprintf(buffer, sizeof(buffer), + "%s %s %s %s", + un.sysname, + un.release, + un.version, + un.machine); + send_packet(STDOUT_FILENO, + TPT_ANNOUNCE, + TPPT_STRING, buffer, + TPPT_DONE); + } + while (!done) { struct pollfd pfds[1]; diff --git a/src/tailer/tailerpp.cc b/src/tailer/tailerpp.cc index 0952fcfa..de42a7e1 100644 --- a/src/tailer/tailerpp.cc +++ b/src/tailer/tailerpp.cc @@ -73,6 +73,12 @@ Result read_packet(int fd) TRY(read_payloads_into(fd, pe.pe_path, pe.pe_msg)); return Ok(packet{pe}); } + case TPT_ANNOUNCE: { + packet_announce pa; + + TRY(read_payloads_into(fd, pa.pa_uname)); + return Ok(packet{pa}); + } case TPT_OFFER_BLOCK: { packet_offer_block pob; diff --git a/src/tailer/tailerpp.hh b/src/tailer/tailerpp.hh index b4c48c97..72b819f1 100644 --- a/src/tailer/tailerpp.hh +++ b/src/tailer/tailerpp.hh @@ -50,6 +50,10 @@ struct packet_error { std::string pe_msg; }; +struct packet_announce { + std::string pa_uname; +}; + struct hash_frag { uint8_t thf_hash[SHA_256_HASH_SIZE]; @@ -107,9 +111,17 @@ struct packet_possible_path { }; using packet = mapbox::util::variant< - packet_eof, packet_error, packet_offer_block, packet_tail_block, - packet_link, packet_preview_error, packet_preview_data, - packet_possible_path, packet_synced>; + packet_eof, + packet_announce, + packet_error, + packet_offer_block, + packet_tail_block, + packet_link, + packet_preview_error, + packet_preview_data, + packet_possible_path, + packet_synced +>; struct recv_payload_type {}; struct recv_payload_length {};