[tailer] send the uname of the remote host back

pull/884/head
Timothy Stack 3 years ago
parent 796a02aa15
commit b38bd6e2fe

@ -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: {

@ -36,6 +36,7 @@
#include <set>
#include <list>
#include <string>
#include <utility>
#include "safe/safe.h"
@ -56,6 +57,15 @@ struct scan_progress {
using safe_scan_progress = safe::Safe<scan_progress>;
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::pair<std::shared_ptr<logfile>, std::string>>
fc_renamed_files;
std::set<std::string> fc_closed_files;
std::map<std::string, file_format_t> fc_other_files;
std::map<std::string, other_file_descriptor> fc_other_files;
std::set<std::string> fc_synced_files;
std::shared_ptr<safe_scan_progress> fc_progress;
std::vector<struct stat> fc_new_stats;

@ -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;
}

@ -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]);
}

@ -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());
},

@ -58,6 +58,7 @@ typedef enum {
TPT_PREVIEW_DATA,
TPT_COMPLETE_PATH,
TPT_POSSIBLE_PATH,
TPT_ANNOUNCE,
} tailer_packet_type_t;
#ifdef __cplusplus

@ -534,6 +534,29 @@ void tailer::looper::host_tailer::loop_body()
return state_v{disconnected()};
},
[&](const tailer::packet_announce &pa) {
std::vector<std::string> paths;
for (const auto& des_pair : conn.c_desired_paths) {
paths.emplace_back(fmt::format(
"{}{}", this->ht_netloc, des_pair.first));
}
isc::to<main_looper&, services::main_t>()
.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);

@ -41,6 +41,7 @@
#include <sys/stat.h>
#include <sys/fcntl.h>
#include <unistd.h>
#include <sys/utsname.h>
#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];

@ -73,6 +73,12 @@ Result<packet, std::string> 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;

@ -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 {};

Loading…
Cancel
Save