165 lines
5.5 KiB
Diff
165 lines
5.5 KiB
Diff
|
Related to bnc#892526 -- let plymouthd become a real daemon that
|
||
|
is it should use its own session with the help of the system call
|
||
|
setsid(2). Also avoid an EBUSY on ioctl TIOCCONS if a former
|
||
|
plymouthd had failed. And a crash or termination may restore not
|
||
|
only the current virtual console but also any serial console as
|
||
|
well restore the system console.
|
||
|
|
||
|
---
|
||
|
plymouth-0.9.0/src/libply-splash-core/ply-device-manager.c | 9 ++
|
||
|
plymouth-0.9.0/src/libply-splash-core/ply-device-manager.h | 1
|
||
|
plymouth-0.9.0/src/libply/ply-terminal-session.c | 7 ++
|
||
|
plymouth-0.9.0/src/libply/ply-utils.c | 2
|
||
|
plymouth-0.9.0/src/main.c | 42 +++++++------
|
||
|
5 files changed, 43 insertions(+), 18 deletions(-)
|
||
|
|
||
|
--- plymouth-0.9.0/src/libply-splash-core/ply-device-manager.c
|
||
|
+++ plymouth-0.9.0/src/libply-splash-core/ply-device-manager.c 2014-09-10 12:16:10.694235361 +0000
|
||
|
@@ -947,3 +947,12 @@ ply_device_manager_deactivate_keyboards
|
||
|
node = next_node;
|
||
|
}
|
||
|
}
|
||
|
+
|
||
|
+void
|
||
|
+ply_close_all_terminals (ply_device_manager_t *manager)
|
||
|
+{
|
||
|
+ ply_hashtable_foreach (manager->terminals,
|
||
|
+ (ply_hashtable_foreach_func_t *)
|
||
|
+ ply_terminal_close,
|
||
|
+ manager);
|
||
|
+}
|
||
|
--- plymouth-0.9.0/src/libply-splash-core/ply-device-manager.h
|
||
|
+++ plymouth-0.9.0/src/libply-splash-core/ply-device-manager.h 2014-09-10 12:16:24.826735672 +0000
|
||
|
@@ -50,6 +50,7 @@ void ply_device_manager_deactivate_keybo
|
||
|
void ply_device_manager_activate_renderers (ply_device_manager_t *manager);
|
||
|
void ply_device_manager_deactivate_renderers (ply_device_manager_t *manager);
|
||
|
ply_terminal_t *ply_device_manager_get_default_terminal (ply_device_manager_t *manager);
|
||
|
+void ply_close_all_terminals (ply_device_manager_t *manager);
|
||
|
|
||
|
#endif
|
||
|
|
||
|
--- plymouth-0.9.0/src/libply/ply-utils.c
|
||
|
+++ plymouth-0.9.0/src/libply/ply-utils.c 2014-09-10 08:53:01.886236228 +0000
|
||
|
@@ -843,6 +843,8 @@ ply_detach_daemon (ply_daemon_handle_t *
|
||
|
close (sender_fd);
|
||
|
free (handle);
|
||
|
|
||
|
+ setsid();
|
||
|
+
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
--- plymouth-0.9.0/src/libply/ply-terminal-session.c
|
||
|
+++ plymouth-0.9.0/src/libply/ply-terminal-session.c 2014-09-10 11:18:04.118735227 +0000
|
||
|
@@ -187,6 +187,13 @@ ply_terminal_session_redirect_console (p
|
||
|
|
||
|
assert (terminal_name != NULL);
|
||
|
|
||
|
+ fd = open ("/dev/console", O_RDWR | O_NOCTTY);
|
||
|
+ if (fd >= 0)
|
||
|
+ {
|
||
|
+ ioctl (fd, TIOCCONS); /* Undo any current map if any */
|
||
|
+ close (fd);
|
||
|
+ }
|
||
|
+
|
||
|
fd = open (terminal_name, O_RDWR | O_NOCTTY);
|
||
|
|
||
|
if (fd < 0)
|
||
|
--- plymouth-0.9.0/src/main.c
|
||
|
+++ plymouth-0.9.0/src/main.c 2014-09-10 13:02:23.242235200 +0000
|
||
|
@@ -1042,6 +1042,7 @@ on_seat_added (state_t *state,
|
||
|
|
||
|
}
|
||
|
|
||
|
+static ply_device_manager_t *manager;
|
||
|
static void
|
||
|
load_devices (state_t *state,
|
||
|
ply_device_manager_flags_t flags)
|
||
|
@@ -1049,6 +1050,8 @@ load_devices (state_t
|
||
|
state->device_manager = ply_device_manager_new (state->default_tty, flags);
|
||
|
state->local_console_terminal = ply_device_manager_get_default_terminal (state->device_manager);
|
||
|
|
||
|
+ manager = state->device_manager;
|
||
|
+
|
||
|
ply_device_manager_watch_seats (state->device_manager,
|
||
|
(ply_seat_added_handler_t)
|
||
|
on_seat_added,
|
||
|
@@ -1077,6 +1080,7 @@ quit_splash (state_t *state)
|
||
|
ply_trace ("Not retaining splash, so deallocating VT");
|
||
|
ply_terminal_deactivate_vt (state->local_console_terminal);
|
||
|
ply_terminal_close (state->local_console_terminal);
|
||
|
+ ply_close_all_terminals (state->device_manager);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@@ -2075,25 +2079,22 @@ dump_debug_buffer_to_file (void)
|
||
|
#include <termios.h>
|
||
|
#include <unistd.h>
|
||
|
static void
|
||
|
-on_crash (int signum)
|
||
|
+dosigaction (int signum)
|
||
|
{
|
||
|
- struct termios term_attributes;
|
||
|
int fd;
|
||
|
|
||
|
- fd = open ("/dev/tty1", O_RDWR | O_NOCTTY);
|
||
|
- if (fd < 0) fd = open ("/dev/hvc0", O_RDWR | O_NOCTTY);
|
||
|
-
|
||
|
- ioctl (fd, KDSETMODE, KD_TEXT);
|
||
|
-
|
||
|
- tcgetattr (fd, &term_attributes);
|
||
|
-
|
||
|
- term_attributes.c_iflag |= BRKINT | IGNPAR | ICRNL | IXON;
|
||
|
- term_attributes.c_oflag |= OPOST;
|
||
|
- term_attributes.c_lflag |= ECHO | ICANON | ISIG | IEXTEN;
|
||
|
-
|
||
|
- tcsetattr (fd, TCSAFLUSH, &term_attributes);
|
||
|
+ if (manager)
|
||
|
+ {
|
||
|
+ ply_device_manager_deactivate_keyboards (manager);
|
||
|
+ ply_close_all_terminals (manager);
|
||
|
+ }
|
||
|
|
||
|
- close (fd);
|
||
|
+ fd = open ("/dev/console", O_RDWR | O_NOCTTY);
|
||
|
+ if (fd >= 0)
|
||
|
+ {
|
||
|
+ ioctl (fd, TIOCCONS); /* Undo any current map if any */
|
||
|
+ close (fd);
|
||
|
+ }
|
||
|
|
||
|
if (debug_buffer != NULL)
|
||
|
{
|
||
|
@@ -2108,7 +2109,6 @@ on_crash (int signum)
|
||
|
pid_file = NULL;
|
||
|
}
|
||
|
|
||
|
- signal (signum, SIG_DFL);
|
||
|
raise(signum);
|
||
|
}
|
||
|
|
||
|
@@ -2145,6 +2145,7 @@ main (int argc,
|
||
|
char *kernel_command_line = NULL;
|
||
|
char *tty = NULL;
|
||
|
ply_device_manager_flags_t device_manager_flags = PLY_DEVICE_MANAGER_FLAGS_NONE;
|
||
|
+ struct sigaction sa;
|
||
|
|
||
|
state.start_time = ply_get_timestamp ();
|
||
|
state.command_parser = ply_command_parser_new ("plymouthd", "Splash server");
|
||
|
@@ -2256,8 +2257,13 @@ main (int argc,
|
||
|
if (debug)
|
||
|
debug_buffer = ply_buffer_new ();
|
||
|
|
||
|
- signal (SIGABRT, on_crash);
|
||
|
- signal (SIGSEGV, on_crash);
|
||
|
+ sigemptyset(&sa.sa_mask);
|
||
|
+ sa.sa_flags = SA_RESETHAND;
|
||
|
+ sa.sa_handler = dosigaction;
|
||
|
+ sigaction (SIGHUP, &sa, NULL);
|
||
|
+ sigaction (SIGTERM, &sa, NULL);
|
||
|
+ sigaction (SIGABRT, &sa, NULL);
|
||
|
+ sigaction (SIGSEGV, &sa, NULL);
|
||
|
|
||
|
/* before do anything we need to make sure we have a working
|
||
|
* environment.
|