tty.c: Refactor, break out enabled check + stop/start

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson committed 2017-07-14 11:03:10 +02:00
1 parent 100b4c70e4
commit 62081d9525
1 file changed
+16 -20
+16 -20
View File
@@ -343,26 +343,30 @@ int tty_fallback(pid_t lost)
return 0; return 0;
} }
static void tty_action(tty_node_t *tty)
{
if (!tty_enabled(&tty->data))
tty_stop(&tty->data);
else
tty_start(&tty->data);
}
/* /*
* TTY monitor, called by service_monitor() * TTY monitor, called by service_monitor()
*/ */
int tty_respawn(pid_t pid) int tty_respawn(pid_t pid)
{ {
tty_node_t *entry = tty_find_by_pid(pid); tty_node_t *tty = tty_find_by_pid(pid);
if (!entry) if (!tty)
return tty_fallback(pid); return tty_fallback(pid);
/* Set DEAD_PROCESS UTMP entry */ /* Set DEAD_PROCESS UTMP entry */
utmp_set_dead(pid); utmp_set_dead(pid);
/* Clear PID to be able to respawn it. */ /* Clear PID to be able to respawn it. */
entry->data.pid = 0; tty->data.pid = 0;
tty_action(tty);
if (!tty_enabled(&entry->data))
tty_stop(&entry->data);
else
tty_start(&entry->data);
return 1; return 1;
} }
@@ -377,11 +381,7 @@ void tty_reload(void)
tty_sweep(); tty_sweep();
LIST_FOREACH(tty, &tty_list, link) { LIST_FOREACH(tty, &tty_list, link) {
if (!tty_enabled(&tty->data)) tty_action(tty);
tty_stop(&tty->data);
else
tty_start(&tty->data);
tty->dirty = 0; tty->dirty = 0;
} }
} }
@@ -389,14 +389,10 @@ void tty_reload(void)
/* Start all TTYs that exist in the system and are allowed at this runlevel */ /* Start all TTYs that exist in the system and are allowed at this runlevel */
void tty_runlevel(void) void tty_runlevel(void)
{ {
tty_node_t *entry; tty_node_t *tty;
LIST_FOREACH(entry, &tty_list, link) { LIST_FOREACH(tty, &tty_list, link)
if (!tty_enabled(&entry->data)) tty_action(tty);
tty_stop(&entry->data);
else
tty_start(&entry->data);
}
/* Start fallback shell if enabled && no TTYs */ /* Start fallback shell if enabled && no TTYs */
tty_fallback(tty_num_active() > 0 ? 1 : 0); tty_fallback(tty_num_active() > 0 ? 1 : 0);