diff options
Diffstat (limited to '')
-rw-r--r-- | src/base/piper.file.hh (renamed from src/piper_proc.hh) | 78 |
1 files changed, 34 insertions, 44 deletions
diff --git a/src/piper_proc.hh b/src/base/piper.file.hh index 0caf29e..7a263ea 100644 --- a/src/piper_proc.hh +++ b/src/base/piper.file.hh @@ -1,5 +1,5 @@ /** - * Copyright (c) 2007-2012, Timothy Stack + * Copyright (c) 2023, Timothy Stack * * All rights reserved. * @@ -25,62 +25,52 @@ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * @file piper_proc.hh */ -#ifndef piper_proc_hh -#define piper_proc_hh +#ifndef lnav_piper_file_hh +#define lnav_piper_file_hh +#include <map> #include <string> -#include <sys/types.h> +#include <sys/time.h> -#include "base/auto_fd.hh" +#include "auto_mem.hh" +#include "ghc/filesystem.hpp" +#include "optional.hpp" +#include "time_util.hh" -/** - * Creates a subprocess that reads data from a pipe and writes it to a file so - * lnav can treat it like any other file and do preads. - * - * TODO: Add support for gzipped files. - */ -class piper_proc { -public: - class error : public std::exception { - public: - error(int err) : e_err(err) {} +namespace lnav { +namespace piper { - int e_err; - }; +struct header { + timeval h_ctime{}; + std::string h_name; + std::string h_cwd; + std::map<std::string, std::string> h_env; - /** - * Forks a subprocess that will read data from the given file descriptor - * and write it to a temporary file. - * - * @param pipefd The file descriptor to read the file contents from. - * @param timestamp True if an ISO 8601 timestamp should be prepended onto - * the lines read from pipefd. - * @param filefd The descriptor for the backing file. - */ - piper_proc(auto_fd pipefd, bool timestamp, auto_fd filefd); + bool operator<(const header& rhs) const + { + if (this->h_ctime < rhs.h_ctime) { + return true; + } - bool has_exited(); + if (this->h_ctime == rhs.h_ctime) { + return this->h_name < rhs.h_name; + } - /** - * Terminates the child process. - */ - virtual ~piper_proc(); + return false; + } +}; - /** @return The file descriptor for the temporary file. */ - auto_fd get_fd() { return this->pp_fd.dup(); } +const ghc::filesystem::path& storage_path(); - pid_t get_child_pid() const { return this->pp_child; } +constexpr size_t HEADER_SIZE = 8; +extern const char HEADER_MAGIC[4]; -private: - /** A file descriptor that refers to the temporary file. */ - auto_fd pp_fd; +nonstd::optional<auto_buffer> read_header(int fd, const char* first8); + +} // namespace piper +} // namespace lnav - /** The child process' pid. */ - pid_t pp_child; -}; #endif |