On Mon, 22 May 2023 10:52:03 +0200 Stefano Brivio <sbrivio(a)redhat.com> wrote:+bool ns_is_init(void) +{ + const char root_uid_map[] = " 0 0 4294967295\n"; + char buf[sizeof(root_uid_map)]; + bool ret = true; + int fd; + + if ((fd = open("/proc/self/uid_map", O_RDONLY | O_CLOEXEC)) < 0) { + die("Can't determine if we're in init namespace: %s", + strerror(errno)); + } + + if (read(fd, buf, sizeof(root_uid_map)) != sizeof(root_uid_map) - 1 || + strncmp(buf, root_uid_map, sizeof(root_uid_map)))Oops, valgrind noticed I didn't actually initialise that extra byte at the end of 'buf'. Fixing this up as well before pushing... -- Stefano