fix: re-enable PartitionAlloc on macOS (#32442)

* fix: re-enable PartitionAlloc on macOS

* no need to copy ignore_result on linux

* factor out FixStdioStreams

* include buildflags.h in electron_main_linux

* #include electron/fuses

* more missing includes
This commit is contained in:
Jeremy Rose 2022-01-16 23:46:33 -08:00 committed by GitHub
parent fac61122d5
commit 6e6f5efad9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 197 additions and 182 deletions

32
shell/app/uv_stdio_fix.cc Normal file
View file

@ -0,0 +1,32 @@
// Copyright (c) 2022 Slack Technologies, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "shell/app/uv_stdio_fix.h"
#include <errno.h>
#include <sys/stat.h>
#include <unistd.h>
#include <cstdio>
// Copied from //base/ignore_result.h to avoid taking a dependency on //base on
// macOS.
template <typename T>
inline void ignore_result(const T&) {}
void FixStdioStreams() {
// libuv may mark stdin/stdout/stderr as close-on-exec, which interferes
// with chromium's subprocess spawning. As a workaround, we detect if these
// streams are closed on startup, and reopen them as /dev/null if necessary.
// Otherwise, an unrelated file descriptor will be assigned as stdout/stderr
// which may cause various errors when attempting to write to them.
//
// For details see https://github.com/libuv/libuv/issues/2062
struct stat st;
if (fstat(STDIN_FILENO, &st) < 0 && errno == EBADF)
ignore_result(freopen("/dev/null", "r", stdin));
if (fstat(STDOUT_FILENO, &st) < 0 && errno == EBADF)
ignore_result(freopen("/dev/null", "w", stdout));
if (fstat(STDERR_FILENO, &st) < 0 && errno == EBADF)
ignore_result(freopen("/dev/null", "w", stderr));
}