[pipe-to] fix some issues when running pipe in headless mode

pull/198/head
Timothy Stack 9 years ago
parent 1e7c988d85
commit 32e96e6395

@ -3599,8 +3599,10 @@ static void gather_pipers(void)
{
for (std::list<piper_proc *>::iterator iter = lnav_data.ld_pipers.begin();
iter != lnav_data.ld_pipers.end(); ) {
if ((*iter)->has_exited()) {
delete *iter;
piper_proc *pp = *iter;
if (pp->has_exited()) {
log_info("child piper has exited -- %d", pp->get_child_pid());
delete pp;
iter = lnav_data.ld_pipers.erase(iter);
} else {
++iter;
@ -3654,7 +3656,6 @@ static void looper(void)
(void)signal(SIGTERM, sigint);
(void)signal(SIGWINCH, sigwinch);
(void)signal(SIGCHLD, sigchld);
(void)signal(SIGPIPE, SIG_IGN);
screen_curses sc;
lnav_behavior lb;
@ -4168,6 +4169,7 @@ int main(int argc, char *argv[])
const char * stdin_out = NULL;
int stdin_out_fd = -1;
(void)signal(SIGPIPE, SIG_IGN);
setlocale(LC_NUMERIC, "");
lnav_data.ld_program_name = argv[0];
@ -4622,12 +4624,15 @@ int main(int argc, char *argv[])
for (;;) {
gather_pipers();
if (lnav_data.ld_pipers.empty()) {
log_debug("all pipers finished");
break;
}
else {
usleep(10000);
rebuild_indexes(false);
}
log_debug("%d pipers still active",
lnav_data.ld_pipers.size());
}
rebuild_indexes(false);

@ -640,14 +640,14 @@ static string com_pipe_to(string cmdline, vector<string> &args)
shared_buffer_ref sbr;
lf->read_full_message(lf->message_start(lf->begin() + cl), sbr);
if (write(in_pipe.write_end(), sbr.get_data(), sbr.length()) == -1) {
return "error: Unable to write to pipe -- " + string(strerror(errno));
return "warning: Unable to write to pipe -- " + string(strerror(errno));
}
write(in_pipe.write_end(), "\n", 1);
}
else {
tc->grep_value_for_line(tc->get_top(), line);
if (write(in_pipe.write_end(), line.c_str(), line.size()) == -1) {
return "error: Unable to write to pipe -- " + string(strerror(errno));
return "warning: Unable to write to pipe -- " + string(strerror(errno));
}
write(in_pipe.write_end(), "\n", 1);
}
@ -656,12 +656,11 @@ static string com_pipe_to(string cmdline, vector<string> &args)
for (iter = bv.begin(); iter != bv.end(); iter++) {
tc->grep_value_for_line(*iter, line);
if (write(in_pipe.write_end(), line.c_str(), line.size()) == -1) {
return "error: Unable to write to pipe -- " + string(strerror(errno));
return "warning: Unable to write to pipe -- " + string(strerror(errno));
}
write(in_pipe.write_end(), "\n", 1);
}
}
in_pipe.close();
retval = "";
break;

@ -75,6 +75,8 @@ public:
/** @return The file descriptor for the temporary file. */
int get_fd() { return this->pp_fd.release(); };
pid_t get_child_pid() const { return this->pp_child; };
private:
/** A file descriptor that refers to the temporary file. */
auto_fd pp_fd;

Loading…
Cancel
Save