Skip to contentSkip to conversation

pseudo_util: Silence symlink errors and fix resolution bug

PATCH New Tomi Belan 1 participant 1 message Aug 19, 2022

lore
Share & tools
lore

Tomi Belan

author
#0 lore raw

PATCH 1/1 pseudo_util: Silence symlink errors and fix resolution bug

readlink() failures are normal. pseudo should just set errno and let the program decide whether to report it. E.g. /proc/$pid/{cwd,exe,fd/*,root} are unreadable for other users' processes. The "pidof" program calls stat() on each /proc/$pid/exe, which causes pseudo to spam stderr. "pidof" is used e.g. by various dpkg postinst scripts.

This if branch also forgot to update *pcurrent, so "cat /proc/1/cwd/stat" would read /proc/1/stat instead of failing as it should.

---
Hi. I'd like to contribute this patch to 'pseudo'. I'm not familiar with git-send-email so I hope I sent it to the right place and it looks good. Cheers!

 pseudo_util.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
pseudo_util.c +3 -2
index f150a1b..e8e9803 100644
@@ -679,7 +679,7 @@ pseudo_append_element(char *newpath, char *root, size_t allocated, char **pcurre
 	if (!leave_this && is_dir) {
 		int is_link = S_ISLNK(buf->st_mode);
 		if (link_recursion >= PSEUDO_MAX_LINK_RECURSION && is_link) {
-			pseudo_diag("link recursion too deep, not expanding path '%s'.\n", newpath);
+			pseudo_debug(PDBGF_PATH, "link recursion too deep, not expanding path '%s'.\n", newpath);
 			is_link = 0;
 		}
 		if (is_link) {
@@ -689,7 +689,8 @@ pseudo_append_element(char *newpath, char *root, size_t allocated, char **pcurre
 
 			linklen = readlink(newpath, linkbuf, pseudo_path_max());
 			if (linklen == -1) {
-				pseudo_diag("uh-oh!  '%s' seems to be a symlink, but I can't read it.  Ignoring.", newpath);
+				pseudo_debug(PDBGF_PATH, "uh-oh!  '%s' seems to be a symlink, but I can't read it.  Ignoring.\n", newpath);
+				*pcurrent = current;
 				return 0;
 			}
 			/* null-terminate buffer */
Signature · 1 line
2.25.1