Conversation
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: FedeDP The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
/milestone 0.19.0 |
Perf diff from master - unit testsHeap diff from master - unit testsHeap diff from master - scap fileBenchmarks diff from master |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #2037 +/- ##
=======================================
Coverage 73.57% 73.58%
=======================================
Files 253 253
Lines 31860 31867 +7
Branches 5640 5641 +1
=======================================
+ Hits 23442 23450 +8
+ Misses 8407 8392 -15
- Partials 11 25 +14
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
X64 kernel testing matrix
ARM64 kernel testing matrix
|
f49119f to
cc7d73f
Compare
|
@LucaGuerra tested with this small test file: #include <sys/wait.h>
#include <ext/stdio_filebuf.h>
#include <iostream>
#include <fstream>
#include <unistd.h>
#include <string>
#include <vector>
struct result {
int error = 0;
std::vector<std::string> output;
};
// Old method
result runsc(char *argv[])
{
result res;
int pipefds[2];
int ret = pipe(pipefds);
if(ret)
{
return res;
}
pid_t pid = vfork();
if(pid > 0)
{
int status;
close(pipefds[1]);
wait(&status);
if(!WIFEXITED(status) || WEXITSTATUS(status) != 0)
{
res.error = status;
return res;
}
__gnu_cxx::stdio_filebuf<char> filebuf(pipefds[0], std::ios::in);
std::string line;
std::istream is(&filebuf);
while(std::getline(is, line))
{
res.output.emplace_back(std::string(line));
}
}
else
{
close(pipefds[0]);
dup2(pipefds[1], STDOUT_FILENO);
execvp("docker", argv);
exit(1);
}
return res;
}
// New method
result runsc_popen(char *argv[])
{
result res;
std::string full_command;
int i = 0;
while (true)
{
if (argv[i] == nullptr)
{
break;
}
full_command.append(argv[i]);
full_command.append(" ");
i++;
}
FILE *cmd_out = popen(full_command.c_str(), "r");
if (cmd_out == nullptr)
{
res.error = -errno;
}
else
{
char *out = nullptr;
size_t len = 0;
ssize_t readbytes;
while ((readbytes = getline(&out, &len, cmd_out)) >= 0)
{
if (out[readbytes - 1] == '\n')
out[readbytes - 1] = '\0';
res.output.emplace_back(out);
}
free(out);
int status = pclose(cmd_out);
if(!WIFEXITED(status) || WEXITSTATUS(status) != 0)
{
res.error = status;
}
}
return res;
}
int main()
{
const char *argv[] = {
"docker",
"--version",
nullptr
};
auto res = runsc((char **)argv);
printf("run with exit code: %d\n", res.error);
for (const auto &o : res.output) {
printf("%s\n", o.c_str());
}
auto res_popen = runsc_popen((char **)argv);
printf("run_popen with exit code: %d\n", res_popen.error);
for (const auto &o : res_popen.output) {
printf("%s\n", o.c_str());
}
return 0;
} |
…ecific) `__gnu_cxx::stdio_filebuf`. Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
cc7d73f to
28ba006
Compare
|
New function test: |
| close(pipefds[0]); | ||
| dup2(pipefds[1], STDOUT_FILENO); | ||
| execvp("runsc", argv); | ||
| execvp("docker", argv); |
There was a problem hiding this comment.
greatest catch ever 🤣
Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
2d067ff to
24b3164
Compare
What type of PR is this?
/kind cleanup
Any specific area of the project related to this PR?
/area libscap-engine-gvisor
Does this PR require a change in the driver versions?
What this PR does / why we need it:
Using the glibc specific
__gnu_cxx::stdio_filebufbreaks while trying to build Falco/libs with zig compiler (see falcosecurity/falco#3307).In this specific case, we can make use of POSIX standard
popen.Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
There are a couple more usages of
__gnu_cxx::stdio_filebuf; both are inside libsinsp_e2e tests framework, but we don't really need to build libs tests when we build Falco (with zig) therefore i am skipping them for now.Does this PR introduce a user-facing change?: