summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Smith <jsmith@resonatingmedia.com>2018-02-20 19:18:58 -0400
committerJesse Smith <jsmith@resonatingmedia.com>2018-02-20 19:18:58 -0400
commit6e3e87bf32664aaf996d5b7b1eef3b9441ba19ac (patch)
tree3558e6c752651535e4342d3b476fc504e79eddb0
parente80878c555d2477997f487dcf8378b57518bdc14 (diff)
downloadsysvinit-6e3e87bf32664aaf996d5b7b1eef3b9441ba19ac.tar.gz
Patch to automatically spawn agetty on kernel consoles
The feature is useful for developers and admins that occasionally need to boot with e.g. console=ttyS0. The built in default can be overridden via inittab for each device. An entry like "S0::off:" turns off the getty on ttyS0.
-rw-r--r--src/init.c74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/init.c b/src/init.c
index 20c2ecb..da715d1 100644
--- a/src/init.c
+++ b/src/init.c
@@ -1291,6 +1291,76 @@ void startup(CHILD *ch)
}
}
+#ifdef __linux__
+static
+void check_kernel_console()
+{
+ FILE* fp;
+ char buf[4096];
+ if ((fp = fopen("/proc/cmdline", "r")) == 0) {
+ return;
+ }
+ if (fgets(buf, sizeof(buf), fp)) {
+ char* p = buf;
+ while ((p = strstr(p, "console="))) {
+ char* e;
+ p += strlen("console=");
+ for (e = p; *e; ++e) {
+ switch (*e) {
+ case '-' ... '9':
+ case 'A' ... 'Z':
+ case '_':
+ case 'a' ... 'z':
+ continue;
+ }
+ break;
+ }
+ if (p != e) {
+ CHILD* old;
+ int dup = 0;
+ char id[8] = {0};
+ char dev[32] = {0};
+ strncpy(dev, p, MIN(sizeof(dev), (unsigned)(e-p)));
+ if (!strncmp(dev, "tty", 3))
+ strncpy(id, dev+3, sizeof(id));
+ else
+ strncpy(id, dev, sizeof(id));
+
+ for(old = newFamily; old; old = old->next) {
+ if (!strcmp(old->id, id)) {
+ dup = 1;
+ }
+ }
+ if (!dup) {
+ CHILD* ch = imalloc(sizeof(CHILD));
+ ch->action = RESPAWN;
+ strcpy(ch->id, id);
+ strcpy(ch->rlevel, "2345");
+ sprintf(ch->process, "/sbin/agetty -L -s 115200,38400,9600 %s vt102", dev);
+ ch->next = NULL;
+ for(old = family; old; old = old->next) {
+ if (strcmp(old->id, ch->id) == 0) {
+ old->new = ch;
+ break;
+ }
+ }
+ /* add to end */
+ for(old = newFamily; old; old = old->next) {
+ if (!old->next) {
+ old->next = ch;
+ break;
+ }
+ }
+
+ initlog(L_VB, "added agetty on %s with id %s", dev, id);
+ }
+ }
+ }
+ }
+ fclose(fp);
+ return;
+}
+#endif
/*
* Read the inittab file.
@@ -1503,6 +1573,10 @@ void read_inittab(void)
*/
if (fp) fclose(fp);
+#ifdef __linux__
+ check_kernel_console();
+#endif
+
/*
* Loop through the list of children, and see if they need to
* be killed.