aboutsummaryrefslogtreecommitdiffstats
path: root/executor/files.h
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2024-11-27 17:23:09 +0100
committerDmitry Vyukov <dvyukov@google.com>2024-12-11 15:22:17 +0000
commit299ee674e6c124a35f1cf258df4f0f3c6e1db1f3 (patch)
tree416b515e959a1d0a64a9516b1524a062ae63ba7d /executor/files.h
parentff949d2512c5ac33d0407d26d80f1df77b2de0e7 (diff)
executor: query globs in the test program context
We query globs for 2 reasons: 1. Expand glob types in syscall descriptions. 2. Dynamic file probing for automatic descriptions generation. In both of these contexts are are interested in files that will be present during test program execution (rather than normal unsandboxed execution). For example, some files may not be accessible to test programs after pivot root. On the other hand, we create and link some additional files for the test program that don't normally exist. Add a new request type for querying of globs that are executed in the test program context.
Diffstat (limited to 'executor/files.h')
-rw-r--r--executor/files.h23
1 files changed, 8 insertions, 15 deletions
diff --git a/executor/files.h b/executor/files.h
index 7be826d0a..f1d2a6104 100644
--- a/executor/files.h
+++ b/executor/files.h
@@ -24,20 +24,25 @@ static std::vector<std::string> Glob(const std::string& pattern)
// because they cause recursion, or lead outside of the target glob
// (e.g. /proc/self/{root,cwd}).
// However, we want to keep few links: /proc/self, /proc/thread-self,
- // /sys/kernel/slab/kmalloc-64 (may be a link with slab merging).
+ // /sys/kernel/slab/kmalloc-64 (may be a link with slab merging),
+ // and cgroup links created in the test dir.
// This is a hacky way to do it b/c e.g. "self" will be matched in all paths,
// not just /proc. A proper fix would require writing completly custom version of glob
// that would support recursion and would allow using/not using links on demand.
+
buf.gl_readdir = [](void* dir) -> dirent* {
for (;;) {
struct dirent* ent = readdir(static_cast<DIR*>(dir));
if (!ent || ent->d_type != DT_LNK ||
!strcmp(ent->d_name, "self") ||
!strcmp(ent->d_name, "thread-self") ||
- !strcmp(ent->d_name, "kmalloc-64"))
+ !strcmp(ent->d_name, "kmalloc-64") ||
+ !strcmp(ent->d_name, "cgroup") ||
+ !strcmp(ent->d_name, "cgroup.cpu") ||
+ !strcmp(ent->d_name, "cgroup.net"))
return ent;
}
- },
+ };
buf.gl_stat = stat;
buf.gl_lstat = lstat;
int res = glob(pattern.c_str(), GLOB_MARK | GLOB_NOSORT | GLOB_ALTDIRFUNC, nullptr, &buf);
@@ -112,15 +117,3 @@ static std::vector<std::unique_ptr<rpc::FileInfoRawT>> ReadFiles(const std::vect
}
return results;
}
-
-static std::vector<std::unique_ptr<rpc::GlobInfoRawT>> ReadGlobs(const std::vector<std::string>& patterns)
-{
- std::vector<std::unique_ptr<rpc::GlobInfoRawT>> results;
- for (const auto& pattern : patterns) {
- auto info = std::make_unique<rpc::GlobInfoRawT>();
- info->name = pattern;
- info->files = Glob(pattern);
- results.push_back(std::move(info));
- }
- return results;
-}