From aa4ce0d5acf115d39576ffac0db1e03334aa928a Mon Sep 17 00:00:00 2001 From: Josh Patra Date: Wed, 8 Jul 2026 10:16:22 -0400 Subject: [PATCH] fix: resolve dev/urandom mount error inside container using mknod fallback --- gamdl-aio/wrapper-v2/src/launcher/wrapper.c | 29 +++++++++++++++------ 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/gamdl-aio/wrapper-v2/src/launcher/wrapper.c b/gamdl-aio/wrapper-v2/src/launcher/wrapper.c index cbdacc77..2c31095a 100644 --- a/gamdl-aio/wrapper-v2/src/launcher/wrapper.c +++ b/gamdl-aio/wrapper-v2/src/launcher/wrapper.c @@ -33,6 +33,7 @@ #include #include #include +#include #include extern char** environ; @@ -109,16 +110,28 @@ int main(int argc, char* argv[], char* envp[]) { if (ensure_dir(ROOTFS "/dev", 0755) != 0) return 1; - int fd = open(ROOTFS "/dev/urandom", O_CREAT | O_RDWR, 0666); - if (fd < 0) { - fprintf(stderr, "wrapper: open %s/dev/urandom: %s\n", ROOTFS, strerror(errno)); - return 1; + struct stat st; + if (stat(ROOTFS "/dev/urandom", &st) == 0) { + if (!S_ISCHR(st.st_mode)) { + unlink(ROOTFS "/dev/urandom"); + } } - close(fd); - if (mount("/dev/urandom", ROOTFS "/dev/urandom", NULL, MS_BIND, NULL) != 0) { - fprintf(stderr, "wrapper: bind-mount /dev/urandom: %s\n", strerror(errno)); - return 1; + if (stat(ROOTFS "/dev/urandom", &st) != 0) { + if (mknod(ROOTFS "/dev/urandom", S_IFCHR | 0666, makedev(1, 9)) != 0) { + fprintf(stderr, "wrapper: mknod /dev/urandom failed: %s, trying bind-mount\n", strerror(errno)); + int fd = open(ROOTFS "/dev/urandom", O_CREAT | O_RDWR, 0666); + if (fd < 0) { + fprintf(stderr, "wrapper: open %s/dev/urandom: %s\n", ROOTFS, strerror(errno)); + return 1; + } + close(fd); + + if (mount("/dev/urandom", ROOTFS "/dev/urandom", NULL, MS_BIND, NULL) != 0) { + fprintf(stderr, "wrapper: bind-mount /dev/urandom: %s\n", strerror(errno)); + return 1; + } + } } if (chdir(ROOTFS) != 0) {