From d5cfa3b94e065c3e3d8c3418a4581fe407e95097 Mon Sep 17 00:00:00 2001 From: Oliver Giles Date: Mon, 15 Jun 2020 12:31:42 +1200 Subject: [PATCH] connect stdin to /dev/null laminard is a daemon process and does not read from stdin. Usually we can rely on the process mananger to do this for us, but if not (e.g. laminard is run interactively), we need this so that child processes (job runs) will not be able to block on stdin. resolves #125 --- src/main.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 05b4138..8b37e26 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,5 @@ /// -/// Copyright 2015-2016 Oliver Giles +/// Copyright 2015-2020 Oliver Giles /// /// This file is part of Laminar /// @@ -20,9 +20,12 @@ #include "leader.h" #include "server.h" #include "log.h" -#include +#include #include #include +#include +#include +#include static Laminar* laminar; static Server* server; @@ -51,6 +54,14 @@ int main(int argc, char** argv) { } } + // The parent process hopefully connected stdin to /dev/null, but + // do it again here just in case. This is important because stdin + // is inherited to job runs via the leader process, and some + // processes misbehave if they can successfully block on reading + // from stdin. + close(STDIN_FILENO); + LASSERT(open("/dev/null", O_RDONLY) == STDIN_FILENO); + auto ioContext = kj::setupAsyncIo(); Settings settings;