Permalink
Browse files

Move asyncFork() from Base.cpp to Utils.cpp and make getHighestFileDe…

…scriptor() use it.
  • Loading branch information...
1 parent 8d4ecd3 commit 7b3f060db147d590ff22b50b691ae7ef2cfb7176 @FooBarWidget FooBarWidget committed Mar 15, 2013
Showing with 22 additions and 12 deletions.
  1. +16 −1 ext/common/Utils.cpp
  2. +6 −0 ext/common/Utils.h
  3. +0 −11 ext/common/agents/Base.cpp
View
@@ -41,6 +41,10 @@
#include <limits.h>
#include <unistd.h>
#include <signal.h>
+#ifdef __linux__
+ #include <sys/syscall.h>
+ #include <features.h>
+#endif
#include <vector>
#include <FileDescriptor.h>
#include <MessageServer.h>
@@ -960,6 +964,17 @@ runShellCommand(const StaticString &command) {
}
}
+// Async-signal safe way to fork().
+// http://sourceware.org/bugzilla/show_bug.cgi?id=4737
+pid_t
+asyncFork() {
+ #if defined(__linux__)
+ return (pid_t) syscall(SYS_fork);
+ #else
+ return fork();
+ #endif
+}
+
// Async-signal safe way to get the current process's hard file descriptor limit.
static int
getFileDescriptorLimit() {
@@ -1039,7 +1054,7 @@ getHighestFileDescriptor() {
}
do {
- pid = fork();
+ pid = asyncFork();
} while (pid == -1 && errno == EINTR);
if (pid == 0) {
View
@@ -412,6 +412,12 @@ void disableMallocDebugging();
int runShellCommand(const StaticString &command);
/**
+ * Async-signal safe way to fork().
+ * http://sourceware.org/bugzilla/show_bug.cgi?id=4737
+ */
+pid_t asyncFork();
+
+/**
* Close all file descriptors that are higher than <em>lastToKeepOpen</em>.
* This function is async-signal safe. But make sure there are no other
* threads running that might open file descriptors!
View
@@ -149,17 +149,6 @@ hasEnvOption(const char *name, bool defaultValue = false) {
}
}
-// Async-signal safe way to fork().
-// http://sourceware.org/bugzilla/show_bug.cgi?id=4737
-static pid_t
-asyncFork() {
- #if defined(__linux__)
- return (pid_t) syscall(SYS_fork);
- #else
- return fork();
- #endif
-}
-
// No idea whether strlen() is async signal safe, but let's not risk it
// and write our own version instead that's guaranteed to be safe.
static size_t

0 comments on commit 7b3f060

Please sign in to comment.