-# A helper subroutine for detecting (based on MAKEFLAGS) if make jobserver
-# is enabled, if it is available or MAKEFLAGS contains "jobs" option.
-# It returns current status (jobserver, jobserver-unavailable or jobs-N where
-# N is number of jobs, 0 if infinite) and MAKEFLAGS cleaned up from
-# job control options.
-sub get_make_jobserver_status {
- my $jobsre = qr/(?:^|\s)(?:(?:-j\s*|--jobs(?:=|\s+))(\d+)?|--jobs)\b/;
- my $status = "";
- my $makeflags;
+# Checks if make's jobserver is enabled via MAKEFLAGS, but
+# the FD used to communicate with it is actually not available.
+sub is_make_jobserver_unavailable {
+ if (exists $ENV{MAKEFLAGS} &&
+ $ENV{MAKEFLAGS} =~ /(?:^|\s)--jobserver-fds=(\d+)/) {
+ if (!open(my $in, "<&$1")) {
+ return 1; # unavailable
+ }
+ else {
+ close $in;
+ return 0; # available
+ }
+ }
+
+ return; # no jobserver specified
+}