[openssh-commits] [openssh] branch master updated: minimal shims for fstatat(2)/unlinkat(2) in agent
git+noreply at mindrot.org
git+noreply at mindrot.org
Thu May 22 18:44:04 AEST 2025
This is an automated email from the git hooks/post-receive script.
djm pushed a commit to branch master
in repository openssh.
The following commit(s) were added to refs/heads/master by this push:
new de25e7397 minimal shims for fstatat(2)/unlinkat(2) in agent
de25e7397 is described below
commit de25e739781c4c09d20abd410f50f0a6f192dc72
Author: Damien Miller <djm at mindrot.org>
AuthorDate: Thu May 22 18:42:44 2025 +1000
minimal shims for fstatat(2)/unlinkat(2) in agent
Add some very minimal and task-specific replacements for
fstatat(2) and unlinkat(2) in the ssh-agent socket cleanup
loop, for platforms that lack these functions. ok dtucker@
---
misc-agent.c | 20 +++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)
diff --git a/misc-agent.c b/misc-agent.c
index 312cff60d..712c42b82 100644
--- a/misc-agent.c
+++ b/misc-agent.c
@@ -264,13 +264,20 @@ socket_is_stale(const char *path)
return 0;
}
+#ifndef HAVE_FSTATAT
+# define fstatat(x, y, buf, z) lstat(path, buf)
+#endif
+#ifndef HAVE_UNLINKAT
+# define unlinkat(x, y, z) unlink(path)
+#endif
+
void
agent_cleanup_stale(const char *homedir, int ignore_hosthash)
{
DIR *d = NULL;
struct dirent *dp;
struct stat sb;
- char *prefix = NULL, *dirpath = NULL, *path;
+ char *prefix = NULL, *dirpath = NULL, *path = NULL;
struct timespec now, sub, *mtimp = NULL;
/* Only consider sockets last modified > 1 hour ago */
@@ -290,6 +297,7 @@ agent_cleanup_stale(const char *homedir, int ignore_hosthash)
}
xasprintf(&prefix, "s.%s.", path);
free(path);
+ path = NULL;
}
xasprintf(&dirpath, "%s/%s", homedir, _PATH_SSH_AGENT_SOCKET_DIR);
@@ -298,7 +306,11 @@ agent_cleanup_stale(const char *homedir, int ignore_hosthash)
error_f("opendir \"%s\": %s", dirpath, strerror(errno));
goto out;
}
+
+ path = NULL;
while ((dp = readdir(d)) != NULL) {
+ free(path);
+ xasprintf(&path, "%s/%s", dirpath, dp->d_name);
#ifdef HAVE_DIRENT_D_TYPE
if (dp->d_type != DT_SOCK && dp->d_type != DT_UNKNOWN)
continue;
@@ -329,16 +341,18 @@ agent_cleanup_stale(const char *homedir, int ignore_hosthash)
"from different host", dirpath, dp->d_name);
continue;
}
- xasprintf(&path, "%s/%s", dirpath, dp->d_name);
if (socket_is_stale(path)) {
debug_f("cleanup stale socket %s", path);
unlinkat(dirfd(d), dp->d_name, 0);
}
- free(path);
}
out:
if (d != NULL)
closedir(d);
+ free(path);
free(dirpath);
free(prefix);
}
+
+#undef unlinkat
+#undef fstatat
--
To stop receiving notification emails like this one, please contact
djm at mindrot.org.
More information about the openssh-commits
mailing list