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.
Jesse Smith
6 years ago
1290 | 1290 | } |
1291 | 1291 | } |
1292 | 1292 | |
1293 | #ifdef __linux__ | |
1294 | static | |
1295 | void check_kernel_console() | |
1296 | { | |
1297 | FILE* fp; | |
1298 | char buf[4096]; | |
1299 | if ((fp = fopen("/proc/cmdline", "r")) == 0) { | |
1300 | return; | |
1301 | } | |
1302 | if (fgets(buf, sizeof(buf), fp)) { | |
1303 | char* p = buf; | |
1304 | while ((p = strstr(p, "console="))) { | |
1305 | char* e; | |
1306 | p += strlen("console="); | |
1307 | for (e = p; *e; ++e) { | |
1308 | switch (*e) { | |
1309 | case '-' ... '9': | |
1310 | case 'A' ... 'Z': | |
1311 | case '_': | |
1312 | case 'a' ... 'z': | |
1313 | continue; | |
1314 | } | |
1315 | break; | |
1316 | } | |
1317 | if (p != e) { | |
1318 | CHILD* old; | |
1319 | int dup = 0; | |
1320 | char id[8] = {0}; | |
1321 | char dev[32] = {0}; | |
1322 | strncpy(dev, p, MIN(sizeof(dev), (unsigned)(e-p))); | |
1323 | if (!strncmp(dev, "tty", 3)) | |
1324 | strncpy(id, dev+3, sizeof(id)); | |
1325 | else | |
1326 | strncpy(id, dev, sizeof(id)); | |
1327 | ||
1328 | for(old = newFamily; old; old = old->next) { | |
1329 | if (!strcmp(old->id, id)) { | |
1330 | dup = 1; | |
1331 | } | |
1332 | } | |
1333 | if (!dup) { | |
1334 | CHILD* ch = imalloc(sizeof(CHILD)); | |
1335 | ch->action = RESPAWN; | |
1336 | strcpy(ch->id, id); | |
1337 | strcpy(ch->rlevel, "2345"); | |
1338 | sprintf(ch->process, "/sbin/agetty -L -s 115200,38400,9600 %s vt102", dev); | |
1339 | ch->next = NULL; | |
1340 | for(old = family; old; old = old->next) { | |
1341 | if (strcmp(old->id, ch->id) == 0) { | |
1342 | old->new = ch; | |
1343 | break; | |
1344 | } | |
1345 | } | |
1346 | /* add to end */ | |
1347 | for(old = newFamily; old; old = old->next) { | |
1348 | if (!old->next) { | |
1349 | old->next = ch; | |
1350 | break; | |
1351 | } | |
1352 | } | |
1353 | ||
1354 | initlog(L_VB, "added agetty on %s with id %s", dev, id); | |
1355 | } | |
1356 | } | |
1357 | } | |
1358 | } | |
1359 | fclose(fp); | |
1360 | return; | |
1361 | } | |
1362 | #endif | |
1293 | 1363 | |
1294 | 1364 | /* |
1295 | 1365 | * Read the inittab file. |
1501 | 1571 | * We're done. |
1502 | 1572 | */ |
1503 | 1573 | if (fp) fclose(fp); |
1574 | ||
1575 | #ifdef __linux__ | |
1576 | check_kernel_console(); | |
1577 | #endif | |
1504 | 1578 | |
1505 | 1579 | /* |
1506 | 1580 | * Loop through the list of children, and see if they need to |