From 14a37fb407420d4bf5518b215bfd20b9ca9edd84 Mon Sep 17 00:00:00 2001 From: Aleksa Sarai Date: Tue, 4 Apr 2017 20:04:03 +1000 Subject: [PATCH] conmon: use pipes rather than socketpairs for !terminal While pipes have their downsides, it turns out that socketpair(2) will break any program that tries to open /dev/std{out,err} for writing (because they're symlinked to /proc/1/fd/{1,2} which will cause lots of fun issues with sockets). Signed-off-by: Mrunal Patel Signed-off-by: Aleksa Sarai --- conmon/conmon.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/conmon/conmon.c b/conmon/conmon.c index 87ca14ab..4889bb28 100644 --- a/conmon/conmon.c +++ b/conmon/conmon.c @@ -212,10 +212,12 @@ int main(int argc, char *argv[]) * both cases. The runtime_mfd will be closed after we dup over * everything. * - * TODO: Maybe this should be done with pipe(2)s? + * We use pipes here because open(/dev/std{out,err}) will fail if we + * used anything else (and it wouldn't be a good idea to create a new + * pty pair in the host). */ - if (socketpair(AF_LOCAL, SOCK_STREAM, 0, fds) < 0) - pexit("Failed to create runtime_mfd socketpair"); + if (pipe(fds) < 0) + pexit("Failed to create runtime_mfd pipes"); mfd = fds[0]; runtime_mfd = fds[1];