fix relaunch on linux (#14975)

* chore: re-enable relaunch test for Linux

* fix: relauncher_linux listening for parent exit
This commit is contained in:
Charles Kerr 2018-10-04 18:41:37 -05:00 committed by GitHub
parent 53d3a96489
commit 9d4818c784
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 31 deletions

View file

@ -12,47 +12,44 @@
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/files/scoped_file.h" #include "base/files/scoped_file.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/posix/eintr_wrapper.h"
#include "base/process/launch.h" #include "base/process/launch.h"
#include "base/synchronization/waitable_event.h"
namespace relauncher { namespace relauncher {
namespace internal { namespace internal {
// this is global to be visible to the sa_handler
base::WaitableEvent parentWaiter;
void RelauncherSynchronizeWithParent() { void RelauncherSynchronizeWithParent() {
base::ScopedFD relauncher_sync_fd(kRelauncherSyncFD); base::ScopedFD relauncher_sync_fd(kRelauncherSyncFD);
static const auto signum = SIGUSR2;
// Don't execute signal handlers of SIGUSR2. // send signum to current process when parent process ends.
sigset_t mask; if (HANDLE_EINTR(prctl(PR_SET_PDEATHSIG, signum)) != 0) {
sigemptyset(&mask);
sigaddset(&mask, SIGUSR2);
if (sigprocmask(SIG_BLOCK, &mask, NULL) < 0) {
PLOG(ERROR) << "sigprocmask";
return;
}
// Create a signalfd that watches for SIGUSR2.
int usr2_fd = signalfd(-1, &mask, 0);
if (usr2_fd < 0) {
PLOG(ERROR) << "signalfd";
return;
}
// Send SIGUSR2 to current process when parent process ends.
if (HANDLE_EINTR(prctl(PR_SET_PDEATHSIG, SIGUSR2)) != 0) {
PLOG(ERROR) << "prctl"; PLOG(ERROR) << "prctl";
return; return;
} }
// Write a '\0' character to the pipe. // set up a signum handler
struct sigaction action;
memset(&action, 0, sizeof(action));
action.sa_handler = [](int /*signum*/) { parentWaiter.Signal(); };
if (sigaction(signum, &action, nullptr) != 0) {
PLOG(ERROR) << "sigaction";
return;
}
// write a '\0' character to the pipe to the parent process.
// this is how the parent knows that we're ready for it to exit.
if (HANDLE_EINTR(write(relauncher_sync_fd.get(), "", 1)) != 1) { if (HANDLE_EINTR(write(relauncher_sync_fd.get(), "", 1)) != 1) {
PLOG(ERROR) << "write"; PLOG(ERROR) << "write";
return; return;
} }
// Wait the SIGUSR2 signal to happen. // Wait for the parent to exit
struct signalfd_siginfo si; parentWaiter.Wait();
HANDLE_EINTR(read(usr2_fd, &si, sizeof(si)));
} }
int LaunchProgram(const StringVector& relauncher_args, int LaunchProgram(const StringVector& relauncher_args,

View file

@ -217,14 +217,6 @@ describe('app module', () => {
let server = null let server = null
const socketPath = process.platform === 'win32' ? '\\\\.\\pipe\\electron-app-relaunch' : '/tmp/electron-app-relaunch' const socketPath = process.platform === 'win32' ? '\\\\.\\pipe\\electron-app-relaunch' : '/tmp/electron-app-relaunch'
// TODO(alexeykuzmin): [Ch68] Fails on Linux.
// Enable the test back.
before(function () {
if (process.platform === 'linux') {
this.skip()
}
})
beforeEach(done => { beforeEach(done => {
fs.unlink(socketPath, () => { fs.unlink(socketPath, () => {
server = net.createServer() server = net.createServer()