From 663c8e6eb9bea01b2b85dc3e0b53d58b3ae70d46 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Fri, 9 Sep 2016 17:09:12 +0200 Subject: init: check /dev/null in addition to /dev/console When booting as an initramfs, the kernel creates /dev/console so the detection method fails and no attempt is made at mounting a devtmpfs. Thus we now also check for /dev/null. --- init/init.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/init/init.c b/init/init.c index e1666b4..be7dd5e 100644 --- a/init/init.c +++ b/init/init.c @@ -248,6 +248,7 @@ static const char __attribute__ ((__section__(STR_SECT),__aligned__(1))) var_dir static const char __attribute__ ((__section__(STR_SECT),__aligned__(1))) cfg_fname[] = "/.preinit"; /* configuration file */ static const char __attribute__ ((__section__(STR_SECT),__aligned__(1))) msg_err_console[] = "Command ignored, input already bound to console !\n"; static const char __attribute__ ((__section__(STR_SECT),__aligned__(1))) dev_console[] = "dev/console"; +static const char __attribute__ ((__section__(STR_SECT),__aligned__(1))) dev_null[] = "dev/null"; static const char __attribute__ ((__section__(STR_SECT),__aligned__(1))) str_rebuild[] = "rebuild"; static const char __attribute__ ((__section__(STR_SECT),__aligned__(1))) var_tmp[] = "/var/tmp"; static const char __attribute__ ((__section__(STR_SECT),__aligned__(1))) var_run[] = "/var/run"; @@ -863,6 +864,18 @@ static inline int mknod_chown(mode_t mode, uid_t uid, gid_t gid, uchar major, uc return error; } +/* return 0 if at least one entry is missing */ +static int is_dev_populated() { + struct stat statf; + int i; + + if (stat(dev_console, &statf) == -1) + return 0; + if (stat(dev_null, &statf) == -1) + return 0; + return 1; +} + /* breaks a 3-fields, comma-separated string into 3 fields */ static inline int varstr_break(char *str, char *type, char **set, uchar *scale) { int state; @@ -1312,7 +1325,7 @@ int main(int argc, char **argv, char **envp) { * we don't test the presence of /dev/console. */ #ifndef I_AM_REALLY_DEBUGGING - if (linuxrc || stat(dev_console, &statf) == -1) { + if (linuxrc || !is_dev_populated()) { print("init/info: /dev/console not found, rebuilding /dev.\n"); if (mount(dev_name, dev_name, devtmpfs_fs, MS_MGC_VAL, dev_options) == -1 && mount(dev_name, dev_name, tmpfs_fs, MS_MGC_VAL, dev_options) == -1) -- 1.7.12.1