*/
#include <iostream>
+#include <fstream>
#include <string>
#include <memory>
+#include <stdexcept>
#include <unistd.h>
-#include <sys/types.h>
-#include <sys/wait.h>
#include <pwd.h>
#include <sys/prctl.h>
+#include <sys/types.h>
+#include <sys/wait.h>
#include <cstring>
#include <sys/capability.h>
const cap_value_t ADMIN[] = { CAP_SETGID, CAP_DAC_OVERRIDE, CAP_SYS_ADMIN, CAP_MAC_OVERRIDE, CAP_MAC_ADMIN };
const cap_value_t LIMITED[] = { CAP_SETGID };
+const char* CACHE_DROP = "/proc/sys/vm/drop_caches";
int main(int argc, char* argv[])
{
pid_t pid = fork();
if (pid < 0) {
std::cerr << "fork() failed" << std::endl;
- return 1;
+ exit(1);
}
if (pid > 0) {
do
child = waitpid(pid, &status, 0);
while (child != pid);
- return 0;
+
+ try {
+ sync();
+
+ std::ofstream of(CACHE_DROP);
+ if (!of) {
+ std::cerr << "Failed to open " << CACHE_DROP << std:: endl;
+ return 1;
+ }
+
+ of << 2 << std::endl;;
+ } catch (const std::exception& e) {
+ std::cerr << e.what() << std::endl;
+ return 1;
+ } catch (...) {
+ std::cerr << "Unknown exception" << std::endl;
+ return 1;
+ }
} else {
// prevent capabilities drop
if (0 != prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0)) {
free(user_argv[0]);
return 1;
}
+ return 0;
}