summaryrefslogtreecommitdiffstats
path: root/src/shared/dev-setup.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2023-10-17 19:43:31 +0200
committerLuca Boccassi <luca.boccassi@gmail.com>2023-10-19 19:03:21 +0200
commitaf189d7b50823876e71d1be5f5c575281ffb99c7 (patch)
treec52410fbc70682f7b8fcabc0192753eb5904dfa6 /src/shared/dev-setup.c
parenttest: unify checking for user xattrs support in cgroupfs (diff)
downloadsystemd-af189d7b50823876e71d1be5f5c575281ffb99c7.tar.xz
systemd-af189d7b50823876e71d1be5f5c575281ffb99c7.zip
pid1,vconsole-setup: lock /dev/console instead of the tty device
As requested in https://github.com/systemd/systemd/pull/27867#pullrequestreview-1567161854. /dev/console, /dev/tty0, and /dev/ttyN are "different" device nodes that may point to a single underlying device. We want to use a single lock so that we don't get a race if different writers are using a different device path, so let's just always lock around /dev/console. This effectively makes the locking less granular. Fixup for a0043bfa51281c2374878e2a98cf2a3ee10fd92c. Fixes https://github.com/systemd/systemd/issues/28721. Maybe fixes https://github.com/systemd/systemd/issues/28778 and https://github.com/systemd/systemd/issues/28634.
Diffstat (limited to 'src/shared/dev-setup.c')
-rw-r--r--src/shared/dev-setup.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/shared/dev-setup.c b/src/shared/dev-setup.c
index 7dca6ad7d4..f7ed16193f 100644
--- a/src/shared/dev-setup.c
+++ b/src/shared/dev-setup.c
@@ -6,14 +6,32 @@
#include "alloc-util.h"
#include "dev-setup.h"
+#include "fd-util.h"
#include "label-util.h"
+#include "lock-util.h"
#include "log.h"
#include "mkdir-label.h"
#include "nulstr-util.h"
#include "path-util.h"
+#include "terminal-util.h"
#include "umask-util.h"
#include "user-util.h"
+int lock_dev_console(void) {
+ _cleanup_close_ int fd = -EBADF;
+ int r;
+
+ fd = open_terminal("/dev/console", O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW);
+ if (fd < 0)
+ return fd;
+
+ r = lock_generic(fd, LOCK_BSD, LOCK_EX);
+ if (r < 0)
+ return log_error_errno(r, "Failed to lock /dev/console: %m");
+
+ 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"