Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1143566ybl; Thu, 12 Dec 2019 10:16:49 -0800 (PST) X-Google-Smtp-Source: APXvYqy6GTWfFEWccV3T5M1lhRm9I3DvB9C71GhHqDk91SrqE++2z1/pwRwnV38MpchtF10rgWlG X-Received: by 2002:a9d:7094:: with SMTP id l20mr9806367otj.190.1576174608948; Thu, 12 Dec 2019 10:16:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576174608; cv=none; d=google.com; s=arc-20160816; b=zgnubOvkfq2YYJuuN4jY+xSnYlBSic1ERwK0N2O2sMkoxYhd1vOjqnSTszJa2K8/q0 eI+ruQqGhg41OkXYwTqJIrrPU9QqMTkwUOwcb/KWHs4gZXHA1eTgOIEsR97VoV1eHfnr dmDYOiAMKbq+9jtRwOPC/+mSQxkIsAulyv1NeJWdmsaNbucGtRrSC7EBEXvIsEgs+IOo 9RcDVGlCfN+jT158pvKe4MQ5WD2A2UKuEnq7+MMlz8aCTGVXb5JxfF/bK5nfGWaG4Bs+ 2EcvO7XkinxXKNOWNXwPfAtm8rSrXoFjpQX5g+6qYLTerJc9FkP7maizrWxDXHxophTk 9UuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=5VUMdoCkPxgKcVGubg8rbhEFWtAEyfsFlSQuPPJWDhg=; b=oDpbglZ4F9jRiveeBIn+jZLARFdjagFbLNn6fQl/xMNaI29IODxv/2xKCH5rvWABfH JpTd1NwdEZK3rM3a/p6Ft1HL3ctWZdl6inC7q2F+8aS6OgnyhxBe6Hcg72dO/rbmXdPc y4DgTulAx61KvE3l7ofsmL2fQh2ur2g2g/Yn9w67cLHxhlPSb0RYbS8nuaLlNYZJU4yU 0rHm2cdpbdw9hQrl1xMKOMDpWlkUTD3fyAHhkcu6s80R0ECQahuYiobchhWaBeCgPyT1 bxEj/n6ypNNLyYAnqYign2SbU7lsGHdDqIBuxwhTmMazYVnQ4WgSswp01Ujrmp9klxAx x9Xg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p26si3764612oto.240.2019.12.12.10.16.35; Thu, 12 Dec 2019 10:16:48 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730353AbfLLSOh (ORCPT + 99 others); Thu, 12 Dec 2019 13:14:37 -0500 Received: from isilmar-4.linta.de ([136.243.71.142]:56768 "EHLO isilmar-4.linta.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730320AbfLLSOf (ORCPT ); Thu, 12 Dec 2019 13:14:35 -0500 X-isilmar-external: YES X-isilmar-external: YES X-isilmar-external: YES X-isilmar-external: YES X-isilmar-external: YES X-isilmar-external: YES X-isilmar-external: YES Received: from light.dominikbrodowski.net (brodo.linta [10.1.0.102]) by isilmar-4.linta.de (Postfix) with ESMTPSA id D572F200A83; Thu, 12 Dec 2019 18:14:33 +0000 (UTC) Received: by light.dominikbrodowski.net (Postfix, from userid 1000) id D5CE020B72; Thu, 12 Dec 2019 19:14:30 +0100 (CET) From: Dominik Brodowski To: Alexander Viro , Linus Torvalds Cc: Greg Kroah-Hartman , "Rafael J . Wysocki" , Andrew Morton , Ingo Molnar , linux-kernel@vger.kernel.org Subject: [PATCH 4/5] init: unify opening /dev/console as stdin/stdout/stderr Date: Thu, 12 Dec 2019 19:14:21 +0100 Message-Id: <20191212181422.31033-5-linux@dominikbrodowski.net> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191212181422.31033-1-linux@dominikbrodowski.net> References: <20191212181422.31033-1-linux@dominikbrodowski.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Merge the two instances where /dev/console is opened as stdin/stdout/stderr. Signed-off-by: Dominik Brodowski --- include/linux/initrd.h | 2 ++ init/do_mounts_initrd.c | 5 +---- init/main.c | 17 ++++++++++++----- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/include/linux/initrd.h b/include/linux/initrd.h index d77fe34fb00a..aa5914355728 100644 --- a/include/linux/initrd.h +++ b/include/linux/initrd.h @@ -28,3 +28,5 @@ extern unsigned int real_root_dev; extern char __initramfs_start[]; extern unsigned long __initramfs_size; + +void console_on_rootfs(void); diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c index 3bf7b74153ab..dab8b1151b56 100644 --- a/init/do_mounts_initrd.c +++ b/init/do_mounts_initrd.c @@ -48,10 +48,7 @@ early_param("initrd", early_initrd); static int init_linuxrc(struct subprocess_info *info, struct cred *new) { ksys_unshare(CLONE_FS | CLONE_FILES); - /* stdin/stdout/stderr for /linuxrc */ - ksys_open("/dev/console", O_RDWR, 0); - ksys_dup(0); - ksys_dup(0); + console_on_rootfs(); /* move initrd over / and chdir/chroot in initrd root */ ksys_chdir("/root"); do_mount(".", "/", NULL, MS_MOVE, NULL); diff --git a/init/main.c b/init/main.c index 91f6ebb30ef0..2cd736059416 100644 --- a/init/main.c +++ b/init/main.c @@ -1155,6 +1155,17 @@ static int __ref kernel_init(void *unused) "See Linux Documentation/admin-guide/init.rst for guidance."); } +void console_on_rootfs(void) +{ + /* Open the /dev/console as stdin, this should never fail */ + if (ksys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0) + pr_err("Warning: unable to open an initial console.\n"); + + /* create stdout/stderr */ + (void) ksys_dup(0); + (void) ksys_dup(0); +} + static noinline void __init kernel_init_freeable(void) { /* @@ -1190,12 +1201,8 @@ static noinline void __init kernel_init_freeable(void) do_basic_setup(); - /* Open the /dev/console on the rootfs, this should never fail */ - if (ksys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0) - pr_err("Warning: unable to open an initial console.\n"); + console_on_rootfs(); - (void) ksys_dup(0); - (void) ksys_dup(0); /* * check if there is an early userspace init. If yes, let it do all * the work -- 2.24.1