diff mbox series

[pseudo] pseudo_util: Silence symlink errors and fix resolution bug

Message ID 20220819152352.590-1-tomi.belan@gmail.com
State New
Headers show
Series [pseudo] pseudo_util: Silence symlink errors and fix resolution bug | expand

Commit Message

Tomi Belan Aug. 19, 2022, 3:23 p.m. UTC
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.

Signed-off-by: Tomi Belan <tomi.belan@gmail.com>
---
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(-)
diff mbox series

Patch

diff --git a/pseudo_util.c b/pseudo_util.c
index f150a1b..e8e9803 100644
--- a/pseudo_util.c
+++ b/pseudo_util.c
@@ -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 */