mirror of
https://gitlab.freedesktop.org/plymouth/plymouth.git
synced 2026-05-08 13:38:45 +02:00
ply-utils: Introduce ply_change_to_vt_with_fd () and ply_change_to_vt ()
This commit is contained in:
parent
6b79792829
commit
6f2c70c9e1
3 changed files with 35 additions and 12 deletions
|
|
@ -912,16 +912,6 @@ ply_terminal_get_vt_number (ply_terminal_t *terminal)
|
|||
return terminal->vt_number;
|
||||
}
|
||||
|
||||
static bool
|
||||
set_active_vt (ply_terminal_t *terminal,
|
||||
int vt_number)
|
||||
{
|
||||
if (ioctl (terminal->fd, VT_ACTIVATE, vt_number) < 0)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
wait_for_vt_to_become_active (ply_terminal_t *terminal,
|
||||
int vt_number)
|
||||
|
|
@ -953,7 +943,7 @@ ply_terminal_activate_vt (ply_terminal_t *terminal)
|
|||
if (terminal->is_active)
|
||||
return true;
|
||||
|
||||
if (!set_active_vt (terminal, terminal->vt_number)) {
|
||||
if (!ply_change_to_vt_with_fd (terminal->vt_number, terminal->fd)) {
|
||||
ply_trace ("unable to set active vt to %d: %m",
|
||||
terminal->vt_number);
|
||||
return false;
|
||||
|
|
@ -994,7 +984,7 @@ ply_terminal_deactivate_vt (ply_terminal_t *terminal)
|
|||
if (ply_terminal_is_active (terminal)) {
|
||||
ply_trace ("Attempting to set active vt back to %d from %d",
|
||||
terminal->initial_vt_number, old_vt_number);
|
||||
if (!set_active_vt (terminal, terminal->initial_vt_number)) {
|
||||
if (!ply_change_to_vt_with_fd (terminal->initial_vt_number, terminal->fd)) {
|
||||
ply_trace ("Couldn't move console to initial vt: %m");
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1232,4 +1232,33 @@ ply_get_random_number (long lower_bound,
|
|||
return lower_bound + offset;
|
||||
}
|
||||
|
||||
bool
|
||||
ply_change_to_vt_with_fd (int vt_number,
|
||||
int tty_fd)
|
||||
{
|
||||
if (ioctl (tty_fd, VT_ACTIVATE, vt_number) < 0)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
ply_change_to_vt (int vt_number)
|
||||
{
|
||||
int fd;
|
||||
bool changed_vt;
|
||||
|
||||
fd = open ("/dev/tty0", O_RDWR);
|
||||
|
||||
if (fd < 0)
|
||||
return false;
|
||||
|
||||
ply_save_errno ();
|
||||
changed_vt = ply_change_to_vt_with_fd (vt_number, fd);
|
||||
ply_restore_errno ();
|
||||
close (fd);
|
||||
|
||||
return changed_vt;
|
||||
}
|
||||
|
||||
/* vim: set ts=4 sw=4 expandtab autoindent cindent cino={.5s,(0: */
|
||||
|
|
|
|||
|
|
@ -162,6 +162,10 @@ bool ply_is_secure_boot_enabled (void);
|
|||
|
||||
long ply_get_random_number (long lower_bound, long range);
|
||||
|
||||
bool ply_change_to_vt_with_fd (int vt_number,
|
||||
int tty_fd);
|
||||
bool ply_change_to_vt (int vt_number);
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* PLY_UTILS_H */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue