Skip to content

Commit

Permalink
Added bootstrap/configure option to force pselect
Browse files Browse the repository at this point in the history
All modern Linux kernels have ppoll() but sometimes
you might want to compile on something ancient.

This patch adds the possibility to force the use
of pselect() instead by passing --force-pselect
to bootstrap/configure.

The use of ppoll() is still default for Linux
and OpenBSD
  • Loading branch information
Tobias Hieta committed May 23, 2013
1 parent 082d0be commit 4db8e5d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
6 changes: 6 additions & 0 deletions bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
parser.add_option('--platform',
help='target platform (' + '/'.join(platform_helper.platforms()) + ')',
choices=platform_helper.platforms())
parser.add_option('--force-pselect', action='store_true',
help="ppoll() is used by default on Linux and OpenBSD, but older versions might need to use pselect instead",)
(options, conf_args) = parser.parse_args()


Expand Down Expand Up @@ -107,6 +109,10 @@ def run(*args, **kwargs):
cflags.append('-D_WIN32_WINNT=0x0501')
if options.x64:
cflags.append('-m64')
if (platform.is_linux() or platform.is_openbsd()) and not options.force_pselect:
cflags.append('-DUSE_PPOLL')
if options.force_pselect:
conf_args.append("--force-pselect")
args.extend(cflags)
args.extend(ldflags)
binary = 'ninja.bootstrap'
Expand Down
5 changes: 5 additions & 0 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
parser.add_option('--with-python', metavar='EXE',
help='use EXE as the Python interpreter',
default=os.path.basename(sys.executable))
parser.add_option('--force-pselect', action='store_true',
help="ppoll() is used by default on Linux and OpenBSD, but older versions might need to use pselect instead",)
(options, args) = parser.parse_args()
if args:
print('ERROR: extra unparsed command-line arguments:', args)
Expand Down Expand Up @@ -163,6 +165,9 @@ def binary(name):
cflags.append('-fno-omit-frame-pointer')
libs.extend(['-Wl,--no-as-needed', '-lprofiler'])

if (platform.is_linux() or platform.is_openbsd()) and not options.force_pselect:
cflags.append('-DUSE_PPOLL')

def shell_escape(str):
"""Escape str such that it's interpreted as a single argument by
the shell."""
Expand Down
6 changes: 3 additions & 3 deletions src/subprocess-posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ bool Subprocess::Start(SubprocessSet* set, const string& command) {
if (pipe(output_pipe) < 0)
Fatal("pipe: %s", strerror(errno));
fd_ = output_pipe[0];
#if !defined(linux) && !defined(__OpenBSD__)
#if !defined(USE_PPOLL)
// On Linux and OpenBSD, we use ppoll in DoWork(); elsewhere we use pselect
// and so must avoid overly-large FDs.
if (fd_ >= static_cast<int>(FD_SETSIZE))
Fatal("pipe: %s", strerror(EMFILE));
#endif // !linux && !__OpenBSD__
#endif // !USE_PPOLL
SetCloseOnExec(fd_);

pid_ = fork();
Expand Down Expand Up @@ -178,7 +178,7 @@ Subprocess *SubprocessSet::Add(const string& command) {
return subprocess;
}

#if defined(linux) || defined(__OpenBSD__)
#ifdef USE_PPOLL
bool SubprocessSet::DoWork() {
vector<pollfd> fds;
nfds_t nfds = 0;
Expand Down

0 comments on commit 4db8e5d

Please sign in to comment.