##// END OF EJS Templates
copies: don't filter out copy targets created on other side of merge commit...
copies: don't filter out copy targets created on other side of merge commit If file X is copied to Y on one side of merge and the other side creates Y (no copy), we would not mark that as copy. In the changeset-centric pathcopies() version, that was done by checking if the copy target existed on the other branch. Even though merge commits are pretty uncommon, it still turned out to be too expensive to load the manifest of the parents of merge commits. In a repo of mozilla-unified converted to storing copies in changesets, about 2m30s of `hg debugpathcopies FIREFOX_BETA_59_END FIREFOX_BETA_60_BASE` is spent on this check of merge commits. I tried to think of a way of storing more information in the changesets in order to cheaply detect these cases, but I couldn't think of a solution. So this patch simply removes those checks. For reference, these extra copies are reported from the aforementioned command after this patch: browser/base/content/sanitize.js -> browser/modules/Sanitizer.jsm testing/mozbase/mozprocess/tests/process_normal_finish_python.ini -> testing/mozbase/mozprocess/tests/process_normal_finish.ini testing/mozbase/mozprocess/tests/process_waittimeout_python.ini -> testing/mozbase/mozprocess/tests/process_waittimeout.ini testing/mozbase/mozprocess/tests/process_waittimeout_10s_python.ini -> testing/mozbase/mozprocess/tests/process_waittimeout_10s.ini Since these copies were created on one side of some merge, it still seems reasonable to include them, so I'm not even sure it's worse than filelog pathcopies(), just different. Differential Revision: https://phab.mercurial-scm.org/D6420

File last commit:

r41367:763b45bc default
r42686:35d674a3 default
Show More
sighandlers.c
175 lines | 3.7 KiB | text/x-c | CLexer
Yuya Nishihara
rust-chg: extract signal handlers from chg/procutil.c...
r40154 /*
* Signal handlers for cHg
*
* Copyright 2011, 2018 Yuya Nishihara <yuya@tcha.org>
*
* This software may be used and distributed according to the terms of the
* GNU General Public License version 2 or any later version.
*/
#include <assert.h>
#include <errno.h>
#include <signal.h>
#include <string.h>
#include <unistd.h>
static pid_t peerpgid = 0;
static pid_t peerpid = 0;
static void forwardsignal(int sig)
{
assert(peerpid > 0);
(void)kill(peerpid, sig);
}
static void forwardsignaltogroup(int sig)
{
/* prefer kill(-pgid, sig), fallback to pid if pgid is invalid */
pid_t killpid = peerpgid > 1 ? -peerpgid : peerpid;
(void)kill(killpid, sig);
}
static void handlestopsignal(int sig)
{
sigset_t unblockset, oldset;
struct sigaction sa, oldsa;
Augie Fackler
cleanup: use clang-tidy to add missing {} around one-line statements...
r41367 if (sigemptyset(&unblockset) < 0) {
Yuya Nishihara
rust-chg: extract signal handlers from chg/procutil.c...
r40154 return;
Augie Fackler
cleanup: use clang-tidy to add missing {} around one-line statements...
r41367 }
if (sigaddset(&unblockset, sig) < 0) {
Yuya Nishihara
rust-chg: extract signal handlers from chg/procutil.c...
r40154 return;
Augie Fackler
cleanup: use clang-tidy to add missing {} around one-line statements...
r41367 }
Yuya Nishihara
rust-chg: extract signal handlers from chg/procutil.c...
r40154 memset(&sa, 0, sizeof(sa));
sa.sa_handler = SIG_DFL;
sa.sa_flags = SA_RESTART;
Augie Fackler
cleanup: use clang-tidy to add missing {} around one-line statements...
r41367 if (sigemptyset(&sa.sa_mask) < 0) {
Yuya Nishihara
rust-chg: extract signal handlers from chg/procutil.c...
r40154 return;
Augie Fackler
cleanup: use clang-tidy to add missing {} around one-line statements...
r41367 }
Yuya Nishihara
rust-chg: extract signal handlers from chg/procutil.c...
r40154
forwardsignal(sig);
Augie Fackler
cleanup: use clang-tidy to add missing {} around one-line statements...
r41367 if (raise(sig) < 0) { /* resend to self */
Yuya Nishihara
rust-chg: extract signal handlers from chg/procutil.c...
r40154 return;
Augie Fackler
cleanup: use clang-tidy to add missing {} around one-line statements...
r41367 }
if (sigaction(sig, &sa, &oldsa) < 0) {
Yuya Nishihara
rust-chg: extract signal handlers from chg/procutil.c...
r40154 return;
Augie Fackler
cleanup: use clang-tidy to add missing {} around one-line statements...
r41367 }
if (sigprocmask(SIG_UNBLOCK, &unblockset, &oldset) < 0) {
Yuya Nishihara
rust-chg: extract signal handlers from chg/procutil.c...
r40154 return;
Augie Fackler
cleanup: use clang-tidy to add missing {} around one-line statements...
r41367 }
Yuya Nishihara
rust-chg: extract signal handlers from chg/procutil.c...
r40154 /* resent signal will be handled before sigprocmask() returns */
Augie Fackler
cleanup: use clang-tidy to add missing {} around one-line statements...
r41367 if (sigprocmask(SIG_SETMASK, &oldset, NULL) < 0) {
Yuya Nishihara
rust-chg: extract signal handlers from chg/procutil.c...
r40154 return;
Augie Fackler
cleanup: use clang-tidy to add missing {} around one-line statements...
r41367 }
if (sigaction(sig, &oldsa, NULL) < 0) {
Yuya Nishihara
rust-chg: extract signal handlers from chg/procutil.c...
r40154 return;
Augie Fackler
cleanup: use clang-tidy to add missing {} around one-line statements...
r41367 }
Yuya Nishihara
rust-chg: extract signal handlers from chg/procutil.c...
r40154 }
/*
* Installs signal handlers.
*
* Returns 0 on success, -1 on error and errno is set appropriately.
* Installed handlers wouldn't be cleaned up on error.
*/
int setupsignalhandler(pid_t pid, pid_t pgid)
{
if (pid <= 0) {
errno = EINVAL;
return -1;
}
peerpid = pid;
peerpgid = (pgid <= 1 ? 0 : pgid);
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
/* deadly signals meant to be sent to a process group:
* - SIGHUP: usually generated by the kernel, when termination of a
* process causes that process group to become orphaned
* - SIGINT: usually generated by the terminal */
sa.sa_handler = forwardsignaltogroup;
sa.sa_flags = SA_RESTART;
Augie Fackler
cleanup: use clang-tidy to add missing {} around one-line statements...
r41367 if (sigemptyset(&sa.sa_mask) < 0) {
return -1;
}
if (sigaction(SIGHUP, &sa, NULL) < 0) {
Yuya Nishihara
rust-chg: extract signal handlers from chg/procutil.c...
r40154 return -1;
Augie Fackler
cleanup: use clang-tidy to add missing {} around one-line statements...
r41367 }
if (sigaction(SIGINT, &sa, NULL) < 0) {
Yuya Nishihara
rust-chg: extract signal handlers from chg/procutil.c...
r40154 return -1;
Augie Fackler
cleanup: use clang-tidy to add missing {} around one-line statements...
r41367 }
Yuya Nishihara
rust-chg: extract signal handlers from chg/procutil.c...
r40154
/* terminate frontend by double SIGTERM in case of server freeze */
sa.sa_handler = forwardsignal;
sa.sa_flags |= SA_RESETHAND;
Augie Fackler
cleanup: use clang-tidy to add missing {} around one-line statements...
r41367 if (sigaction(SIGTERM, &sa, NULL) < 0) {
Yuya Nishihara
rust-chg: extract signal handlers from chg/procutil.c...
r40154 return -1;
Augie Fackler
cleanup: use clang-tidy to add missing {} around one-line statements...
r41367 }
Yuya Nishihara
rust-chg: extract signal handlers from chg/procutil.c...
r40154
/* notify the worker about window resize events */
sa.sa_flags = SA_RESTART;
Augie Fackler
cleanup: use clang-tidy to add missing {} around one-line statements...
r41367 if (sigaction(SIGWINCH, &sa, NULL) < 0) {
Yuya Nishihara
rust-chg: extract signal handlers from chg/procutil.c...
r40154 return -1;
Augie Fackler
cleanup: use clang-tidy to add missing {} around one-line statements...
r41367 }
Yuya Nishihara
rust-chg: extract signal handlers from chg/procutil.c...
r40154 /* forward user-defined signals */
Augie Fackler
cleanup: use clang-tidy to add missing {} around one-line statements...
r41367 if (sigaction(SIGUSR1, &sa, NULL) < 0) {
Yuya Nishihara
rust-chg: extract signal handlers from chg/procutil.c...
r40154 return -1;
Augie Fackler
cleanup: use clang-tidy to add missing {} around one-line statements...
r41367 }
if (sigaction(SIGUSR2, &sa, NULL) < 0) {
Yuya Nishihara
rust-chg: extract signal handlers from chg/procutil.c...
r40154 return -1;
Augie Fackler
cleanup: use clang-tidy to add missing {} around one-line statements...
r41367 }
Yuya Nishihara
rust-chg: extract signal handlers from chg/procutil.c...
r40154 /* propagate job control requests to worker */
sa.sa_handler = forwardsignal;
sa.sa_flags = SA_RESTART;
Augie Fackler
cleanup: use clang-tidy to add missing {} around one-line statements...
r41367 if (sigaction(SIGCONT, &sa, NULL) < 0) {
Yuya Nishihara
rust-chg: extract signal handlers from chg/procutil.c...
r40154 return -1;
Augie Fackler
cleanup: use clang-tidy to add missing {} around one-line statements...
r41367 }
Yuya Nishihara
rust-chg: extract signal handlers from chg/procutil.c...
r40154 sa.sa_handler = handlestopsignal;
sa.sa_flags = SA_RESTART;
Augie Fackler
cleanup: use clang-tidy to add missing {} around one-line statements...
r41367 if (sigaction(SIGTSTP, &sa, NULL) < 0) {
Yuya Nishihara
rust-chg: extract signal handlers from chg/procutil.c...
r40154 return -1;
Augie Fackler
cleanup: use clang-tidy to add missing {} around one-line statements...
r41367 }
Yuya Nishihara
rust-chg: extract signal handlers from chg/procutil.c...
r40154
return 0;
}
/*
* Restores signal handlers to the default, and masks SIGINT.
*
* Returns 0 on success, -1 on error and errno is set appropriately.
*/
int restoresignalhandler(void)
{
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sa.sa_handler = SIG_DFL;
sa.sa_flags = SA_RESTART;
Augie Fackler
cleanup: use clang-tidy to add missing {} around one-line statements...
r41367 if (sigemptyset(&sa.sa_mask) < 0) {
Yuya Nishihara
rust-chg: extract signal handlers from chg/procutil.c...
r40154 return -1;
Augie Fackler
cleanup: use clang-tidy to add missing {} around one-line statements...
r41367 }
Yuya Nishihara
rust-chg: extract signal handlers from chg/procutil.c...
r40154
Augie Fackler
cleanup: use clang-tidy to add missing {} around one-line statements...
r41367 if (sigaction(SIGHUP, &sa, NULL) < 0) {
Yuya Nishihara
rust-chg: extract signal handlers from chg/procutil.c...
r40154 return -1;
Augie Fackler
cleanup: use clang-tidy to add missing {} around one-line statements...
r41367 }
if (sigaction(SIGTERM, &sa, NULL) < 0) {
Yuya Nishihara
rust-chg: extract signal handlers from chg/procutil.c...
r40154 return -1;
Augie Fackler
cleanup: use clang-tidy to add missing {} around one-line statements...
r41367 }
if (sigaction(SIGWINCH, &sa, NULL) < 0) {
Yuya Nishihara
rust-chg: extract signal handlers from chg/procutil.c...
r40154 return -1;
Augie Fackler
cleanup: use clang-tidy to add missing {} around one-line statements...
r41367 }
if (sigaction(SIGCONT, &sa, NULL) < 0) {
Yuya Nishihara
rust-chg: extract signal handlers from chg/procutil.c...
r40154 return -1;
Augie Fackler
cleanup: use clang-tidy to add missing {} around one-line statements...
r41367 }
if (sigaction(SIGTSTP, &sa, NULL) < 0) {
Yuya Nishihara
rust-chg: extract signal handlers from chg/procutil.c...
r40154 return -1;
Augie Fackler
cleanup: use clang-tidy to add missing {} around one-line statements...
r41367 }
Yuya Nishihara
rust-chg: extract signal handlers from chg/procutil.c...
r40154
/* ignore Ctrl+C while shutting down to make pager exits cleanly */
sa.sa_handler = SIG_IGN;
Augie Fackler
cleanup: use clang-tidy to add missing {} around one-line statements...
r41367 if (sigaction(SIGINT, &sa, NULL) < 0) {
Yuya Nishihara
rust-chg: extract signal handlers from chg/procutil.c...
r40154 return -1;
Augie Fackler
cleanup: use clang-tidy to add missing {} around one-line statements...
r41367 }
Yuya Nishihara
rust-chg: extract signal handlers from chg/procutil.c...
r40154
peerpid = 0;
return 0;
}