]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
terminal-util: move lock_dev_console() here
authorLennart Poettering <lennart@poettering.net>
Wed, 17 Jul 2024 10:20:32 +0000 (12:20 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 19 Jul 2024 09:44:04 +0000 (11:44 +0200)
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.

src/basic/terminal-util.c
src/basic/terminal-util.h
src/core/exec-invoke.c
src/core/execute.c
src/shared/dev-setup.c
src/shared/dev-setup.h

index d8253037ec452a9ba54927ba39e83fd61e00f0db..6d3a0f8a5c7d79db3b521885e7f81a6ce3647fbf 100644 (file)
@@ -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;
 
index 11aab24acb558330023495f1797707b40d0ea6b6..3cf0ff984852ea9c49c474e9af9fc50f4870b784 100644 (file)
@@ -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);
index 08f9188ec7d76bbac61b584e692c2326969c2f0c..2521e940c9b505db95f945cfce69f1de8cb91f10 100644 (file)
@@ -32,7 +32,6 @@
 #include "chown-recursive.h"
 #include "copy.h"
 #include "data-fd-util.h"
-#include "dev-setup.h"
 #include "env-util.h"
 #include "escape.h"
 #include "exec-credential.h"
index dc418fd14c2e48bed7cbdc771b797eea667bec89..cdc12779564e1aba6c48323fc67c9a10efef3e01 100644 (file)
@@ -25,7 +25,6 @@
 #include "cgroup-setup.h"
 #include "constants.h"
 #include "cpu-set-util.h"
-#include "dev-setup.h"
 #include "env-file.h"
 #include "env-util.h"
 #include "errno-list.h"
index 4b4b62565c5145c28956e7cbe044944c2240f36e..eb72793c04b4283bb9638452fe67faf5c6108fd5 100644 (file)
 #include "umask-util.h"
 #include "user-util.h"
 
-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 dev_setup(const char *prefix, uid_t uid, gid_t gid) {
         static const char symlinks[] =
                 "-/proc/kcore\0"     "/dev/core\0"
index 5339bc4e5e9075605283076ffc338740a3ab1a6b..92ba6cf76403346dc55a8da9c50a158f4fb6791f 100644 (file)
@@ -3,8 +3,6 @@
 
 #include <sys/types.h>
 
-int lock_dev_console(void);
-
 int dev_setup(const char *prefix, uid_t uid, gid_t gid);
 
 int make_inaccessible_nodes(const char *parent_dir, uid_t uid, gid_t gid);