2014-09-12 14:52:26 +02:00
|
|
|
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(-)
|
|
|
|
|
2016-01-13 19:15:35 +01:00
|
|
|
Index: plymouth-0.9.2/src/libply-splash-core/ply-device-manager.c
|
2014-09-25 15:21:13 +02:00
|
|
|
===================================================================
|
2016-01-13 19:15:35 +01:00
|
|
|
--- plymouth-0.9.2.orig/src/libply-splash-core/ply-device-manager.c
|
|
|
|
+++ plymouth-0.9.2/src/libply-splash-core/ply-device-manager.c
|
|
|
|
@@ -926,3 +926,12 @@ ply_device_manager_deactivate_keyboards
|
|
|
|
node = next_node;
|
|
|
|
}
|
2014-09-12 14:52:26 +02:00
|
|
|
}
|
|
|
|
+
|
|
|
|
+void
|
|
|
|
+ply_close_all_terminals (ply_device_manager_t *manager)
|
|
|
|
+{
|
|
|
|
+ ply_hashtable_foreach (manager->terminals,
|
|
|
|
+ (ply_hashtable_foreach_func_t *)
|
|
|
|
+ ply_terminal_close,
|
|
|
|
+ manager);
|
|
|
|
+}
|
2016-01-13 19:15:35 +01:00
|
|
|
Index: plymouth-0.9.2/src/libply-splash-core/ply-device-manager.h
|
2014-09-25 15:21:13 +02:00
|
|
|
===================================================================
|
2016-01-13 19:15:35 +01:00
|
|
|
--- plymouth-0.9.2.orig/src/libply-splash-core/ply-device-manager.h
|
|
|
|
+++ plymouth-0.9.2/src/libply-splash-core/ply-device-manager.h
|
|
|
|
@@ -52,6 +52,7 @@ void ply_device_manager_deactivate_keybo
|
2014-09-12 14:52:26 +02:00
|
|
|
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
|
|
|
|
|
2016-01-13 19:15:35 +01:00
|
|
|
Index: plymouth-0.9.2/src/libply/ply-utils.c
|
2014-09-25 15:21:13 +02:00
|
|
|
===================================================================
|
2016-01-13 19:15:35 +01:00
|
|
|
--- plymouth-0.9.2.orig/src/libply/ply-utils.c
|
|
|
|
+++ plymouth-0.9.2/src/libply/ply-utils.c
|
2014-09-25 15:21:13 +02:00
|
|
|
@@ -77,6 +77,7 @@
|
|
|
|
|
|
|
|
static int errno_stack[PLY_ERRNO_STACK_SIZE];
|
|
|
|
static int errno_stack_position = 0;
|
|
|
|
+static bool inChild = false;
|
|
|
|
|
2016-01-13 19:15:35 +01:00
|
|
|
bool
|
2014-09-25 15:21:13 +02:00
|
|
|
ply_open_unidirectional_pipe (int *sender_fd,
|
2016-01-13 19:15:35 +01:00
|
|
|
@@ -771,6 +772,7 @@ ply_create_daemon (void)
|
|
|
|
if (!ply_read (receiver_fd, &byte, sizeof(uint8_t))) {
|
|
|
|
int read_error = errno;
|
|
|
|
int status;
|
|
|
|
+ inChild = true;
|
|
|
|
|
|
|
|
if (waitpid (pid, &status, WNOHANG) <= 0)
|
|
|
|
ply_error ("failed to read status from child immediately after starting to daemonize: %s", strerror (read_error));
|
|
|
|
@@ -811,6 +813,9 @@ ply_detach_daemon (ply_daemon_handle_t *
|
|
|
|
close (sender_fd);
|
|
|
|
free (handle);
|
|
|
|
|
|
|
|
+ if (inChild)
|
|
|
|
+ setsid();
|
2014-09-12 14:52:26 +02:00
|
|
|
+
|
2016-01-13 19:15:35 +01:00
|
|
|
return true;
|
2014-09-12 14:52:26 +02:00
|
|
|
}
|
|
|
|
|
2016-01-13 19:15:35 +01:00
|
|
|
Index: plymouth-0.9.2/src/libply/ply-terminal-session.c
|
2014-09-25 15:21:13 +02:00
|
|
|
===================================================================
|
2016-01-13 19:15:35 +01:00
|
|
|
--- plymouth-0.9.2.orig/src/libply/ply-terminal-session.c
|
|
|
|
+++ plymouth-0.9.2/src/libply/ply-terminal-session.c
|
|
|
|
@@ -187,6 +187,12 @@ 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);
|
|
|
|
+ }
|
2014-09-12 14:52:26 +02:00
|
|
|
+
|
2016-01-13 19:15:35 +01:00
|
|
|
fd = open (terminal_name, O_RDWR | O_NOCTTY);
|
2014-09-12 14:52:26 +02:00
|
|
|
|
2016-01-13 19:15:35 +01:00
|
|
|
if (fd < 0)
|
|
|
|
Index: plymouth-0.9.2/src/main.c
|
2014-09-25 15:21:13 +02:00
|
|
|
===================================================================
|
2016-01-13 19:15:35 +01:00
|
|
|
--- plymouth-0.9.2.orig/src/main.c
|
|
|
|
+++ plymouth-0.9.2/src/main.c
|
|
|
|
@@ -1026,6 +1026,7 @@ on_seat_added (state_t *state,
|
|
|
|
on_enter, state);
|
2014-09-12 14:52:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
+static ply_device_manager_t *manager;
|
|
|
|
static void
|
2016-01-13 19:15:35 +01:00
|
|
|
load_devices (state_t *state,
|
|
|
|
ply_device_manager_flags_t flags)
|
|
|
|
@@ -1033,6 +1034,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);
|
2014-09-12 14:52:26 +02:00
|
|
|
|
2016-01-13 19:15:35 +01:00
|
|
|
+ manager = state->device_manager;
|
2014-09-12 14:52:26 +02:00
|
|
|
+
|
2016-01-13 19:15:35 +01:00
|
|
|
ply_device_manager_watch_seats (state->device_manager,
|
|
|
|
(ply_seat_added_handler_t)
|
|
|
|
on_seat_added,
|
|
|
|
@@ -1058,6 +1061,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);
|
|
|
|
}
|
2014-09-12 14:52:26 +02:00
|
|
|
}
|
|
|
|
|
2016-01-13 19:15:35 +01:00
|
|
|
@@ -1974,25 +1978,20 @@ dump_debug_buffer_to_file (void)
|
|
|
|
#include <termios.h>
|
|
|
|
#include <unistd.h>
|
2014-09-12 14:52:26 +02:00
|
|
|
static void
|
|
|
|
-on_crash (int signum)
|
|
|
|
+dosigaction (int signum)
|
|
|
|
{
|
2016-01-13 19:15:35 +01:00
|
|
|
- struct termios term_attributes;
|
|
|
|
int fd;
|
2014-09-12 14:52:26 +02:00
|
|
|
|
2016-01-13 19:15:35 +01:00
|
|
|
- fd = open ("/dev/tty1", O_RDWR | O_NOCTTY);
|
|
|
|
- if (fd < 0) fd = open ("/dev/hvc0", O_RDWR | O_NOCTTY);
|
2014-09-12 14:52:26 +02:00
|
|
|
-
|
2016-01-13 19:15:35 +01:00
|
|
|
- ioctl (fd, KDSETMODE, KD_TEXT);
|
2014-09-12 14:52:26 +02:00
|
|
|
-
|
2016-01-13 19:15:35 +01:00
|
|
|
- tcgetattr (fd, &term_attributes);
|
2014-09-12 14:52:26 +02:00
|
|
|
-
|
2016-01-13 19:15:35 +01:00
|
|
|
- term_attributes.c_iflag |= BRKINT | IGNPAR | ICRNL | IXON;
|
|
|
|
- term_attributes.c_oflag |= OPOST;
|
|
|
|
- term_attributes.c_lflag |= ECHO | ICANON | ISIG | IEXTEN;
|
2014-09-12 14:52:26 +02:00
|
|
|
-
|
2016-01-13 19:15:35 +01:00
|
|
|
- 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) {
|
|
|
|
dump_debug_buffer_to_file ();
|
|
|
|
@@ -2005,7 +2004,6 @@ on_crash (int signum)
|
|
|
|
pid_file = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
- signal (signum, SIG_DFL);
|
|
|
|
raise (signum);
|
2014-09-12 14:52:26 +02:00
|
|
|
}
|
|
|
|
|
2016-01-13 19:15:35 +01:00
|
|
|
@@ -2039,6 +2037,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");
|
|
|
|
@@ -2141,8 +2140,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.
|