Description: library: Recover from meminfo seek() in LXC
 Running procps tools under LXC may fail with the message:
 "Unable to create meminfo structure"
 .
 This is due to a lseek() failing with a ESPIPE error.
 It doesn't appear to impact all LXC installations and it's
 unclear why some are impacted and some not.
 .
 The fix is to check for that error and reopen the file
 if required.
Author: Paul Slootman <paul@debian.org>
Origin: upstream, https://gitlab.com/procps-ng/procps/-/commit/104b3ce3df67092eeb868ba5e019cb895ebdf32d
Bug-Debian: https://bugs.debian.org/1072831
Applied-Upstream: 4.0.5
Last-Update: 2025-04-14
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- a/library/meminfo.c
+++ b/library/meminfo.c
@@ -646,12 +646,20 @@
     // clear out the soon to be 'current' values
     memset(&info->hist.new, 0, sizeof(struct meminfo_data));
 
-    if (-1 == info->meminfo_fd
-    && (-1 == (info->meminfo_fd = open(MEMINFO_FILE, O_RDONLY))))
-        return 1;
-
-    if (lseek(info->meminfo_fd, 0L, SEEK_SET) == -1)
-        return 1;
+    if (-1 == info->meminfo_fd) {
+    	if (-1 == (info->meminfo_fd = open(MEMINFO_FILE, O_RDONLY)))
+	    return 1;
+    }
+    else {
+	if (lseek(info->meminfo_fd, 0L, SEEK_SET) == -1)
+	    if (ESPIPE == errno) {
+		close(info->meminfo_fd);
+		if (-1 == (info->meminfo_fd = open(MEMINFO_FILE, O_RDONLY)))
+		    return 1;
+	    }
+	    else
+		return 1;
+    }
 
     for (;;) {
         if ((size = read(info->meminfo_fd, buf, sizeof(buf)-1)) < 0) {
