Skip to content
This repository has been archived by the owner on May 1, 2023. It is now read-only.

Commit

Permalink
Move ForkJail into own target
Browse files Browse the repository at this point in the history
Summary: ForkJail's super useful in its own right, shouldn't be limited to just Loom.

Reviewed By: BurntBrunch

Differential Revision: D6159922

fbshipit-source-id: fd519aeac69230fe72f88b6eccfb2c87d450d01d
  • Loading branch information
tophyr authored and facebook-github-bot committed Dec 20, 2017
1 parent cc0fe4a commit 84a4075
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 56 deletions.
4 changes: 2 additions & 2 deletions cpp/profiler/ArtCompatibility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#error "Invalid ART version"
#endif

#include <util/ForkJail.h>
#include <forkjail/ForkJail.h>

namespace fbjni = facebook::jni;

Expand Down Expand Up @@ -223,7 +223,7 @@ jboolean check(JNIEnv* env, jclass) {
facebook::art::InitRuntime();
#endif

util::ForkJail jail([
forkjail::ForkJail jail([
&javaStack,
env,
nativeThread] {
Expand Down
2 changes: 1 addition & 1 deletion cpp/profiler/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ def tracer_library(version):
],
deps = [
loom_path("deps/fb:fb"),
loom_path("deps/forkjail:forkjail"),
loom_path("deps/museum/{version}:{version}").format(version=version),
loom_path("cpp/logger:logger"),
loom_path("cpp/util:forkjail"),
],
)

Expand Down
24 changes: 0 additions & 24 deletions cpp/util/BUCK
Original file line number Diff line number Diff line change
@@ -1,30 +1,6 @@
load("//buck_imports:loom_path.bzl", "loom_path")
load("//buck_imports:xplat", "fb_xplat_cxx_library")

FORKJAIL_EXPORTED_HEADERS = ["ForkJail.h"]

fb_xplat_cxx_library(
name = "forkjail",
srcs = glob([
"ForkJail.cpp",
]),
headers = glob(
["*.h"],
excludes = FORKJAIL_EXPORTED_HEADERS,
),
header_namespace = "util",
exported_headers = FORKJAIL_EXPORTED_HEADERS,
compiler_flags = [
"-fexceptions",
"-fPIC",
"-std=gnu++14",
],
force_static = True,
visibility = [
loom_path("..."),
],
)

UTIL_EXPORTED_HEADERS = [
"common.h",
"ProcFs.h",
Expand Down
14 changes: 0 additions & 14 deletions cpp/util/test/BUCK
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
load("//buck_imports:loom_path.bzl", "loom_path")

cxx_test(
name = "forkjail",
srcs = [
"ForkJailTest.cpp",
],
compiler_flags = [
"-fexceptions",
"-DLOG_TAG=\"Loom\"",
],
deps = [
loom_path("cpp/util:forkjail"),
],
)

cxx_binary(
name = "procfs_perf",
srcs = [
Expand Down
26 changes: 26 additions & 0 deletions deps/forkjail/BUCK
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
include_defs("//buck_imports/xplat") # THIS_IS_FBANDROID

if not THIS_IS_FBANDROID:
FORKJAIL_EXPORTED_HEADERS = ["ForkJail.h"]

fb_xplat_cxx_library(
name = "forkjail",
srcs = glob([
"ForkJail.cpp",
]),
compiler_flags = [
"-fexceptions",
"-fPIC",
"-std=gnu++14",
],
exported_headers = FORKJAIL_EXPORTED_HEADERS,
force_static = True,
header_namespace = "forkjail",
headers = glob(
["*.h"],
excludes = FORKJAIL_EXPORTED_HEADERS,
),
visibility = [
"PUBLIC",
],
)
8 changes: 3 additions & 5 deletions cpp/util/ForkJail.cpp → deps/forkjail/ForkJail.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
#include <string>

namespace facebook {
namespace loom {
namespace util {
namespace forkjail {

namespace {
class SignalMask {
Expand All @@ -34,7 +33,7 @@ class SignalMask {
sigset_t old_;
};

inline static std::system_error errno_error(std::string error){
inline static std::system_error errno_error(std::string error) {
return std::system_error(errno, std::system_category(), error);
}

Expand Down Expand Up @@ -185,6 +184,5 @@ void ForkJail::alarm_handler(int signum){
_exit(kChildTimeoutExitCode);
}

} // util
} // loom
} // forkjail
} // facebook
8 changes: 3 additions & 5 deletions cpp/util/ForkJail.h → deps/forkjail/ForkJail.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
#include <functional>

namespace facebook {
namespace loom {
namespace util {
namespace forkjail {

// A utility class that forks and resets signal handlers in order to prevent a
// A utility class that forks and resets signal handlers in order to prevent a
// dangerous operation from taking down our own process.
class ForkJail {

Expand Down Expand Up @@ -46,6 +45,5 @@ class ForkJail {
static void alarm_handler(int signum);
};

} // util
} // loom
} // forkjail
} // facebook
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@
#include <sys/wait.h>
#include <unistd.h>

#include <util/ForkJail.h>
#include <forkjail/ForkJail.h>
#include <gtest/gtest.h>

#include <system_error>

#include <iostream>

namespace facebook {
namespace loom {
namespace util {
namespace forkjail {

namespace {

Expand Down Expand Up @@ -115,6 +114,5 @@ TEST(ForkJail, testProcessGroupChanged) {
EXPECT_CHILD_STATUS(jail, kExitCodeSuccess);
}

} // util
} // loom
} // forkjail
} // facebook

0 comments on commit 84a4075

Please sign in to comment.