mirror of
https://github.com/troglobit/finit.git
synced 2026-10-27 12:20:54 +00:00
Add support for specifying TTYs and console TTY in finit.conf
This commit adds support for specifying TTY and console to be used
for starting a getty to login to the system
Add the following to your finit.conf to use this feature:
tty ttyS0
tty ttyUSB0
console ttyS0
Signed-off-by: Mattias Walström <lazzer@gmail.com>
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
89675403d8
commit
3bcefd2160
3 files changed
+44
-44
No files matched your search
@@ -143,8 +143,7 @@ void parse_finit_conf(char *file)
|
|||||||
|
|
||||||
if (MATCH_CMD(line, "tty ", x)) {
|
if (MATCH_CMD(line, "tty ", x)) {
|
||||||
char *tty = build_cmd(NULL, x, CMD_SIZE);
|
char *tty = build_cmd(NULL, x, CMD_SIZE);
|
||||||
int baud = 115200; /* TODO: Read from config file. */
|
int baud = 115200; /* XXX - Read from config file */
|
||||||
|
|
||||||
tty_add(tty, baud);
|
tty_add(tty, baud);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,14 +35,14 @@
|
|||||||
#include "sig.h"
|
#include "sig.h"
|
||||||
#include "lite.h"
|
#include "lite.h"
|
||||||
|
|
||||||
int debug = 0;
|
int debug = 0;
|
||||||
int verbose = 1;
|
int verbose = 1;
|
||||||
char *sdown = NULL;
|
char *sdown = NULL;
|
||||||
char *network = NULL;
|
char *network = NULL;
|
||||||
char *username = NULL;
|
char *username = NULL;
|
||||||
char *hostname = NULL;
|
char *hostname = NULL;
|
||||||
char *rcsd = NULL;
|
char *rcsd = NULL;
|
||||||
char *console = NULL;
|
char *console = NULL;
|
||||||
|
|
||||||
static void parse_kernel_cmdline(void)
|
static void parse_kernel_cmdline(void)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -21,7 +21,6 @@
|
|||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <sys/inotify.h>
|
#include <sys/inotify.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <sys/prctl.h>
|
#include <sys/prctl.h>
|
||||||
@@ -77,6 +76,7 @@ static void tty_startstop_one(finit_tty_t *tty, uint32_t mask)
|
|||||||
/* Kill the spawned child, and recollect it. */
|
/* Kill the spawned child, and recollect it. */
|
||||||
if ((mask & IN_DELETE) && tty->pid) {
|
if ((mask & IN_DELETE) && tty->pid) {
|
||||||
int status = 0;
|
int status = 0;
|
||||||
|
|
||||||
_d("Stopping %s", tty->name);
|
_d("Stopping %s", tty->name);
|
||||||
kill(tty->pid, SIGKILL);
|
kill(tty->pid, SIGKILL);
|
||||||
waitpid(tty->pid, &status, 0);
|
waitpid(tty->pid, &status, 0);
|
||||||
@@ -84,49 +84,50 @@ static void tty_startstop_one(finit_tty_t *tty, uint32_t mask)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void tty_watcher(node_t *entry)
|
||||||
|
{
|
||||||
|
int fd = inotify_init();
|
||||||
|
|
||||||
|
prctl(PR_SET_NAME, "tty-watcher", 0, 0, 0);
|
||||||
|
|
||||||
|
if (-1 == fd || inotify_add_watch(fd, "/dev", IN_CREATE | IN_DELETE) < 0) {
|
||||||
|
fprintf(stderr, "finit: Failed starting TTY watcher: %s\n", strerror(errno));
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
int len = 0;
|
||||||
|
char buf[EVENT_SIZE];
|
||||||
|
struct inotify_event *notified = (struct inotify_event *)buf;
|
||||||
|
|
||||||
|
while ((len = read(fd, buf, EVENT_SIZE))) {
|
||||||
|
if (len == -1) {
|
||||||
|
if (errno == EAGAIN || errno == EINTR)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
LIST_FOREACH(entry, &node_list, link) {
|
||||||
|
if (strcmp(notified->name, entry->data.name) == 0)
|
||||||
|
tty_startstop_one(&entry->data, notified->mask);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void tty_start(void)
|
void tty_start(void)
|
||||||
{
|
{
|
||||||
int fd = -1;
|
|
||||||
node_t *entry;
|
node_t *entry;
|
||||||
|
|
||||||
/* Start all TTYs that already exist in the system. */
|
/* Start all TTYs that already exist in the system */
|
||||||
LIST_FOREACH(entry, &node_list, link) {
|
LIST_FOREACH(entry, &node_list, link) {
|
||||||
chdir("/dev");
|
chdir("/dev");
|
||||||
if (fexist (entry->data.name))
|
if (fexist (entry->data.name))
|
||||||
tty_startstop_one(&entry->data, IN_CREATE);
|
tty_startstop_one(&entry->data, IN_CREATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Start a inotify watcher to catch new TTYs that is discovered (USB for example) */
|
/* Start a watcher to catch new TTYs that is discovered, e.g., USB */
|
||||||
if (!fork()) {
|
if (!fork())
|
||||||
fd = inotify_init();
|
tty_watcher(entry);
|
||||||
|
|
||||||
prctl(PR_SET_NAME, "tty_watcher", 0, 0, 0);
|
|
||||||
if (inotify_add_watch(fd, "/dev", IN_CREATE | IN_DELETE) < 0) {
|
|
||||||
fprintf(stderr, "Failed to add watcher, errno %s\n", strerror(errno));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (1) {
|
|
||||||
int len = 0;;
|
|
||||||
char buf[EVENT_SIZE];
|
|
||||||
struct inotify_event *notified;
|
|
||||||
|
|
||||||
while ((len = read(fd, buf, EVENT_SIZE))) {
|
|
||||||
if (len == -1) {
|
|
||||||
if (errno == EAGAIN || errno == EINTR)
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
notified = (struct inotify_event *) &buf[0];
|
|
||||||
LIST_FOREACH(entry, &node_list, link) {
|
|
||||||
if (strcmp(notified->name, entry->data.name) == 0) {
|
|
||||||
tty_startstop_one(&entry->data, notified->mask);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in new issue
Block a user