From: Willy Tarreau Date: Wed, 22 Nov 2023 10:48:23 +0000 (+0100) Subject: MINOR: debug: report in post_mortem if the container techno used is docker X-Git-Tag: v2.9-dev11~24 X-Git-Url: http://git.haproxy.org/?a=commitdiff_plain;h=2974f3e71b91c34ac5407673f2db7d1028d81383;p=haproxy-3.0.git MINOR: debug: report in post_mortem if the container techno used is docker If we detect we're running inside a container on Linux, let's check if it seems to be docker. Docker usually creates a /.dockerenv file, which is easy to check. It's uncertain whether it's always the case, but on the few tested instances that was true, and we don't really care, what matters is to place helpful debugging info for developers. When this file is detected, we report "docker" instead of "yes" in the container techno. --- diff --git a/src/debug.c b/src/debug.c index a637304..a4dfc5a 100644 --- a/src/debug.c +++ b/src/debug.c @@ -1898,6 +1898,8 @@ REGISTER_PER_THREAD_INIT(init_debug_per_thread); static void feed_post_mortem_linux() { #if defined(__linux__) + struct stat statbuf; + /* DMI reports either HW or hypervisor, this allows to detect most VMs. * On ARM the device-tree is often more precise for the model. Since many * boards present "to be filled by OEM" or so in many fields, we dedup @@ -1935,7 +1937,12 @@ static void feed_post_mortem_linux() if (read_line_to_trash("/proc/2/status") <= 0 || (strcmp(trash.area, "Name:\tkthreadd") != 0 && strcmp(trash.area, "Name:\tkeventd") != 0)) { - strlcpy2(post_mortem.platform.cont_techno, "yes", sizeof(post_mortem.platform.cont_techno)); + /* OK we're in a container. Docker often has /.dockerenv */ + const char *tech = "yes"; + + if (stat("/.dockerenv", &statbuf) == 0) + tech = "docker"; + strlcpy2(post_mortem.platform.cont_techno, tech, sizeof(post_mortem.platform.cont_techno)); } else { strlcpy2(post_mortem.platform.cont_techno, "no", sizeof(post_mortem.platform.cont_techno));