ply_logger_t *logger;
ply_event_loop_t *loop;
char **argv;
+ ply_fd_watch_t *fd_watch;
ply_terminal_session_output_handler_t output_handler;
ply_terminal_session_done_handler_t done_handler;
return true;
}
+void
+ply_terminal_session_detach (ply_terminal_session_t *session)
+{
+ assert (session != NULL);
+
+ ply_trace ("stopping terminal logger");
+
+ ply_terminal_session_stop_logging (session);
+
+ if (session->console_is_redirected)
+ {
+ ply_trace ("unredirecting console messages");
+ ply_terminal_session_unredirect_console (session);
+ }
+
+ session->output_handler = NULL;
+ session->done_handler = NULL;
+ session->user_data = NULL;
+
+ session->is_running = false;
+}
+
int
ply_terminal_session_get_fd (ply_terminal_session_t *session)
{
static void
ply_terminal_session_on_hangup (ply_terminal_session_t *session)
{
+ ply_terminal_session_done_handler_t done_handler;
+
assert (session != NULL);
+ done_handler = session->done_handler;
+
ply_logger_flush (session->logger);
session->is_running = false;
+ ply_terminal_session_stop_logging (session);
+ session->done_handler = NULL;
- if (session->done_handler != NULL)
- session->done_handler (session->user_data, session);
+ if (done_handler != NULL)
+ done_handler (session->user_data, session);
- ply_terminal_session_stop_logging (session);
+ ply_terminal_session_detach (session);
}
static void
assert (session_fd >= 0);
- ply_event_loop_watch_fd (session->loop, session_fd,
- PLY_EVENT_LOOP_FD_STATUS_HAS_DATA,
- (ply_event_handler_t)
- ply_terminal_session_on_new_data,
- (ply_event_handler_t)
- ply_terminal_session_on_hangup, session);
+ session->fd_watch = ply_event_loop_watch_fd (session->loop,
+ session_fd,
+ PLY_EVENT_LOOP_FD_STATUS_HAS_DATA,
+ (ply_event_handler_t)
+ ply_terminal_session_on_new_data,
+ (ply_event_handler_t)
+ ply_terminal_session_on_hangup,
+ session);
}
static void
if (ply_logger_is_logging (session->logger))
ply_logger_toggle_logging (session->logger);
+
+ if (session->loop != NULL &&
+ session->fd_watch != NULL)
+ ply_event_loop_stop_watching_fd (session->loop,
+ session->fd_watch);
+ session->fd_watch = NULL;
}
bool
static ply_window_t *create_window (state_t *state,
const char *tty_name);
+static bool attach_to_running_session (state_t *state);
+
static void
on_session_output (state_t *state,
const char *output,
{
open_windows (state);
+ if (!state->is_redirected && state->ptmx >= 0)
+ state->is_redirected = attach_to_running_session (state);
+
if (plymouth_should_show_default_splash (state))
show_default_splash (state);
else
if (state->session != NULL)
{
- ply_trace ("unredirecting console");
- int fd;
-
- fd = open ("/dev/console", O_RDWR | O_NOCTTY);
- if (fd >= 0)
- ioctl (fd, TIOCCONS);
-
- close (fd);
+ ply_trace ("detaching session");
+ ply_terminal_session_detach (state->session);
state->is_redirected = false;
}
}
return splash;
}
-static ply_terminal_session_t *
+static bool
attach_to_running_session (state_t *state)
{
ply_terminal_session_t *session;
if (should_be_redirected)
flags |= PLY_TERMINAL_SESSION_FLAGS_REDIRECT_CONSOLE;
- ply_trace ("creating terminal session for current terminal");
- session = ply_terminal_session_new (NULL);
- ply_trace ("attaching terminal session to event loop");
- ply_terminal_session_attach_to_event_loop (session, state->loop);
+ if (state->session == NULL)
+ {
+ ply_trace ("creating new terminal session");
+ session = ply_terminal_session_new (NULL);
+
+ ply_terminal_session_attach_to_event_loop (session, state->loop);
+ }
+ else
+ {
+ session = state->session;
+ ply_trace ("session already created");
+ }
if (!ply_terminal_session_attach (session, flags,
(ply_terminal_session_output_handler_t)
ply_restore_errno ();
state->is_redirected = false;
- return NULL;
+ return false;
}
state->is_redirected = should_be_redirected;
+ state->session = session;
- return session;
+ return true;
}
static bool
if (attach_to_session)
{
- state.session = attach_to_running_session (&state);
-
- if (state.session == NULL)
+ if (!attach_to_running_session (&state))
{
ply_error ("could not create session: %m");
ply_detach_daemon (daemon_handle, EX_UNAVAILABLE);