From d4cef26393cbcae344a665e028684b6b561e9e3a Mon Sep 17 00:00:00 2001 From: Yingchi Long Date: Wed, 17 Apr 2024 21:31:36 +0800 Subject: [PATCH] nixd: add non null getters for `StreamProc` --- nixd/include/nixd/Support/StreamProc.h | 12 ++++++++++++ nixd/lib/Eval/AttrSetClient.cpp | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/nixd/include/nixd/Support/StreamProc.h b/nixd/include/nixd/Support/StreamProc.h index bbe66e6ab..bfba46b3d 100644 --- a/nixd/include/nixd/Support/StreamProc.h +++ b/nixd/include/nixd/Support/StreamProc.h @@ -8,15 +8,27 @@ namespace nixd { struct StreamProc { +private: std::unique_ptr Proc; std::unique_ptr Stream; +public: /// \brief Launch a streamed process with \p Action. /// /// The value returned by \p Action will be interpreted as process's exit /// value. StreamProc(const std::function &Action); + [[nodiscard]] llvm::raw_fd_ostream &stream() const { + assert(Stream); + return *Stream; + } + + [[nodiscard]] util::PipedProc &proc() const { + assert(Proc); + return *Proc; + } + [[nodiscard]] std::unique_ptr mkIn() const; [[nodiscard]] std::unique_ptr mkOut() const; diff --git a/nixd/lib/Eval/AttrSetClient.cpp b/nixd/lib/Eval/AttrSetClient.cpp index cf35e6162..239ee0e2c 100644 --- a/nixd/lib/Eval/AttrSetClient.cpp +++ b/nixd/lib/Eval/AttrSetClient.cpp @@ -34,7 +34,7 @@ AttrSetClientProc::AttrSetClientProc(const std::function &Action) Input([this]() { Client.run(); }) {} AttrSetClient *AttrSetClientProc::client() { - if (!kill(Proc.Proc->PID, 0)) + if (!kill(Proc.proc().PID, 0)) return &Client; return nullptr; }