terminal-util: move lock_dev_console() here
It doesn't really make sense to have that in dev-setup.c, which is mostly about setting up /dev/, creating device nodes and stuff. let's move it to the other stuff that deals with /dev/console's peculiarities.
This commit is contained in:
@@ -618,6 +618,23 @@ void reset_dev_console_fd(int fd, bool switch_to_text) {
|
||||
log_warning_errno(r, "Failed to reset /dev/console using ANSI sequences, ignoring: %m");
|
||||
}
|
||||
|
||||
int lock_dev_console(void) {
|
||||
_cleanup_close_ int fd = -EBADF;
|
||||
int r;
|
||||
|
||||
/* NB: We do not use O_NOFOLLOW here, because some container managers might place a symlink to some
|
||||
* pty in /dev/console, in which case it should be fine to lock the target TTY. */
|
||||
fd = open_terminal("/dev/console", O_RDONLY|O_CLOEXEC|O_NOCTTY);
|
||||
if (fd < 0)
|
||||
return fd;
|
||||
|
||||
r = lock_generic(fd, LOCK_BSD, LOCK_EX);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
return TAKE_FD(fd);
|
||||
}
|
||||
|
||||
int make_console_stdio(void) {
|
||||
int fd, r;
|
||||
|
||||
|
||||
@@ -88,6 +88,7 @@ int vtnr_from_tty(const char *tty);
|
||||
const char* default_term_for_tty(const char *tty);
|
||||
|
||||
void reset_dev_console_fd(int fd, bool switch_to_text);
|
||||
int lock_dev_console(void);
|
||||
int make_console_stdio(void);
|
||||
|
||||
int fd_columns(int fd);
|
||||
|
||||
Reference in New Issue
Block a user