From patchwork Tue May 17 15:00:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jo-Philipp Wich X-Patchwork-Id: 623148 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2001:1868:205::9]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3r8LFf6hwLz9ssP for ; Wed, 18 May 2016 01:04:06 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1b2gWG-0003DL-Hi; Tue, 17 May 2016 15:02:48 +0000 Received: from mxout01.bytecamp.net ([212.204.60.217]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1b2gWB-00035k-3A for lede-dev@lists.infradead.org; Tue, 17 May 2016 15:02:47 +0000 Received: by mxout01.bytecamp.net (Postfix, from userid 1001) id 2A70F30FE4A; Tue, 17 May 2016 17:01:09 +0200 (CEST) Received: from mail.bytecamp.net (mailstore.bytecamp.net [212.204.60.20]) by mxout01.bytecamp.net (Postfix) with ESMTP id A506430FE4C for ; Tue, 17 May 2016 17:01:08 +0200 (CEST) Received: (qmail 36619 invoked by uid 89); 17 May 2016 17:01:07 +0200 Received: from unknown (HELO localhost.localdomain) (jo%wwsnet.net@213.61.250.148) by mail.bytecamp.net with AES128-SHA encrypted SMTP; 17 May 2016 17:01:07 +0200 From: Jo-Philipp Wich To: lede-dev@lists.infradead.org Date: Tue, 17 May 2016 17:00:44 +0200 Message-Id: X-Mailer: git-send-email 2.1.4 In-Reply-To: References: In-Reply-To: References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160517_080243_337067_0387FC28 X-CRM114-Status: UNSURE ( 8.66 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [212.204.60.217 listed in list.dnswl.org] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Subject: [LEDE-DEV] [PATCH 2/5] initd: use patch_stdio() for early console setup X-BeenThere: lede-dev@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jo-Philipp Wich , john@phrozen.org MIME-Version: 1.0 Sender: "Lede-dev" Errors-To: lede-dev-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Signed-off-by: Jo-Philipp Wich --- initd/early.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/initd/early.c b/initd/early.c index 4343516..accfc1d 100644 --- a/initd/early.c +++ b/initd/early.c @@ -21,6 +21,7 @@ #include #include +#include "../utils/utils.h" #include "init.h" #include "../libc-compat.h" @@ -35,25 +36,16 @@ static void early_console(const char *dev) { struct stat s; - int dd; if (stat(dev, &s)) { ERROR("Failed to stat %s\n", dev); return; } - dd = open(dev, O_RDWR); - if (dd < 0) - dd = open("/dev/null", O_RDWR); - - dup2(dd, STDIN_FILENO); - dup2(dd, STDOUT_FILENO); - dup2(dd, STDERR_FILENO); - - if (dd != STDIN_FILENO && - dd != STDOUT_FILENO && - dd != STDERR_FILENO) - close(dd); + if (patch_stdio(dev)) { + ERROR("Failed to setup i/o redirection\n"); + return; + } fcntl(STDERR_FILENO, F_SETFL, fcntl(STDERR_FILENO, F_GETFL) | O_NONBLOCK); }