src/relpipe-in-posixmq.cpp
branchv_0
changeset 7 12e975f807ed
parent 3 b71fc3b5e56b
--- a/src/relpipe-in-posixmq.cpp	Wed Apr 20 20:59:42 2022 +0200
+++ b/src/relpipe-in-posixmq.cpp	Sat Apr 30 23:19:08 2022 +0200
@@ -15,6 +15,7 @@
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 #include <cstdlib>
+#include <csignal>
 #include <vector>
 #include <memory>
 #include <regex>
@@ -37,6 +38,12 @@
 using namespace relpipe::writer;
 using namespace relpipe::in::posixmq;
 
+static std::shared_ptr<PosixMQCommand> command = nullptr;
+
+void finish(int sig) {
+	if (command) command->finish(sig);
+}
+
 int main(int argc, char** argv) {
 	setlocale(LC_ALL, "");
 	CLI::untieStdIO();
@@ -45,11 +52,14 @@
 	int resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR;
 
 	try {
+		signal(SIGHUP, finish);
+		signal(SIGINT, finish);
 		CLIParser cliParser;
 		Configuration configuration = cliParser.parse(cli.arguments());
-		PosixMQCommand command;
+		command.reset(new PosixMQCommand());
 		std::shared_ptr<RelationalWriter> writer(Factory::create(std::cout));
-		command.process(writer, configuration);
+		writer->setBufferingMode(BufferingMode::ENVIRONMENT, BufferingMode::RECORD);
+		command->process(writer, configuration);
 		resultCode = CLI::EXIT_CODE_SUCCESS;
 	} catch (RelpipeCLIException e) {
 		fwprintf(stderr, L"Caught CLI exception: %ls\n", e.getMessage().c_str());