All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Jate Sujjavanich" <jatedev@gmail.com>
To: openembedded-core@lists.openembedded.org
Cc: Jate Sujjavanich <jatedev@gmail.com>
Subject: [PATCH] sysvinit: Add bootlogd patch restoring console detection
Date: Tue,  1 Dec 2020 15:40:16 +0000	[thread overview]
Message-ID: <20201201154016.487-1-jatedev@gmail.com> (raw)

The bootlogd program will skip any non-standard serial ports specified
in the kernel parameters, so restore the detection of the device
underlying /dev/console. This allows the serial console on some embedded
systems to work again.

Signed-off-by: Jate Sujjavanich <jatedev@gmail.com>
---
 ...ogd-c--Restore-dev-console-detection.patch | 101 ++++++++++++++++++
 meta/recipes-core/sysvinit/sysvinit_2.97.bb   |   1 +
 2 files changed, 102 insertions(+)
 create mode 100644 meta/recipes-core/sysvinit/sysvinit/0001-bootlogd-c--Restore-dev-console-detection.patch

diff --git a/meta/recipes-core/sysvinit/sysvinit/0001-bootlogd-c--Restore-dev-console-detection.patch b/meta/recipes-core/sysvinit/sysvinit/0001-bootlogd-c--Restore-dev-console-detection.patch
new file mode 100644
index 0000000000..14b5d84c78
--- /dev/null
+++ b/meta/recipes-core/sysvinit/sysvinit/0001-bootlogd-c--Restore-dev-console-detection.patch
@@ -0,0 +1,101 @@
+From: Jate Sujjavanich <jatedev@gmail.com>
+Date: Thu, 29 Oct 2020 12:31:43 -0400
+Subject: [PATCH] bootlogd.c: Restore /dev/console detection
+
+Restore function that detected /dev/console's underlying tty device. This
+causes bootlogd to add the kernel's choice for /dev/console to its output list.
+
+This also helps if the kernel's default console is not in the defcons list and
+bootlogd ignores console= definition in kernel parameters. This is frequently
+the case for embedded systems which have their own names for serial drivers.
+
+Upstream-status: Inappropriate, embedded
+
+Signed-off-by: Jate Sujjavanich <jatedev@gmail.com>
+---
+ src/bootlogd.c | 29 ++++++++++++++++++++---------
+ 1 file changed, 20 insertions(+), 9 deletions(-)
+
+diff --git a/src/bootlogd.c b/src/bootlogd.c
+index 8b07903..909d3e5 100644
+--- a/src/bootlogd.c
++++ b/src/bootlogd.c
+@@ -110,10 +110,6 @@ void handler(int sig)
+ /*
+  *	Scan /dev and find the device name.
+  */
+-/*
+-This function does not appear to be called anymore. Commenting it
+-out for now, can probably be removed entirely in the future.
+-
+ static int findtty(char *res, const char *startdir, int rlen, dev_t dev)
+ {
+ 	DIR		*dir;
+@@ -169,8 +165,6 @@ static int findtty(char *res, const char *startdir, int rlen, dev_t dev)
+ 	chdir(olddir);
+ 	return r;
+ }
+-*/
+-
+ 
+ 
+ /*
+@@ -250,7 +244,7 @@ int isconsole(char *s, char *res, int rlen)
+ int consolenames(struct real_cons *cons, int max_consoles)
+ {
+ #ifdef TIOCGDEV
+-	/* This appears to be unused.  unsigned int	kdev; */
++	unsigned int	kdev;
+ #endif
+ 	struct stat	st, st2;
+ 	char		buf[KERNEL_COMMAND_LENGTH];
+@@ -260,6 +254,23 @@ int consolenames(struct real_cons *cons, int max_consoles)
+ 	int		fd;
+ 	int		considx, num_consoles = 0;
+ 
++#ifdef TIOCGDEV
++# ifndef  ENOIOCTLCMD
++#  define ENOIOCTLCMD	515
++# endif
++	if (ioctl(0, TIOCGDEV, &kdev) == 0) {
++		int r = findtty(cons[0].name, "/dev", sizeof(cons[0].name), (dev_t)kdev);
++		if (0 != r)
++			fprintf(stderr, "bootlogd: cannot find console device "
++				"%d:%d under /dev\n", major(kdev), minor(kdev));
++		else {
++			num_consoles++; fprintf(stderr, "bootlogd: %s", cons[0].name);
++		}
++	} else
++		if (errno != ENOIOCTLCMD)
++			fprintf(stderr, "bootlogd: ioctl of /dev/console error\n");
++#endif
++
+ #ifdef __linux__
+ 	/*
+ 	 *	Read /proc/cmdline.
+@@ -311,12 +322,12 @@ int consolenames(struct real_cons *cons, int max_consoles)
+ 						goto dontuse;
+ 					}
+ 				}
+-			
+ 			num_consoles++;
+ 			if (num_consoles >= max_consoles) {
+ 				break;
+ 			}
+ 		}
++		
+ dontuse:
+ 		p--;
+ 	}
+@@ -329,7 +340,7 @@ dontuse:
+ 	 *	guess the default console.
+ 	 */
+ 	for (n = 0; defcons[n]; n++)
+-		if (isconsole(defcons[n], cons[0].name, sizeof(cons[0].name))) 
++		if (isconsole(defcons[n], cons[0].name, sizeof(cons[0].name)))
+ 			return 1;
+ 
+ 	fprintf(stderr, "bootlogd: cannot deduce real console device\n");
+-- 
+2.7.4
+
diff --git a/meta/recipes-core/sysvinit/sysvinit_2.97.bb b/meta/recipes-core/sysvinit/sysvinit_2.97.bb
index 98916f7f19..6187295405 100644
--- a/meta/recipes-core/sysvinit/sysvinit_2.97.bb
+++ b/meta/recipes-core/sysvinit/sysvinit_2.97.bb
@@ -20,6 +20,7 @@ SRC_URI = "${SAVANNAH_GNU_MIRROR}/sysvinit/sysvinit-${PV}.tar.xz \
            file://rcS \
            file://bootlogd.init \
            file://01_bootlogd \
+           file://0001-bootlogd-c--Restore-dev-console-detection.patch \
            "
 SRC_URI[sha256sum] = "2d5996857519bfd8634d2e1debabb3238fb38440f65fbfdc46420ee8bdf25110"
 
-- 
2.25.1


                 reply	other threads:[~2020-12-01 15:40 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201201154016.487-1-jatedev@gmail.com \
    --to=jatedev@gmail.com \
    --cc=openembedded-core@lists.openembedded.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.