annotate rust/chg/src/sighandlers.c @ 47890:3853e6ee160d

dirstatemap: replace `removefile` by an explicit `entry.set_untracked()` All the other caller goes through `reset_state`, so we can safely have an explicit method on `DirstateItem` object. This means that all the logic to preserve the previous state (from p2, merged, etc) is now properly encapsulated within the DirstateItem. This pave the way to using different storage for these information. Differential Revision: https://phab.mercurial-scm.org/D11315
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Fri, 20 Aug 2021 11:27:01 +0200
parents 763b45bc4483
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
28060
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
1 /*
40118
cd490ac908c0 rust-chg: extract signal handlers from chg/procutil.c
Yuya Nishihara <yuya@tcha.org>
parents: 35959
diff changeset
2 * Signal handlers for cHg
28060
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
3 *
40118
cd490ac908c0 rust-chg: extract signal handlers from chg/procutil.c
Yuya Nishihara <yuya@tcha.org>
parents: 35959
diff changeset
4 * Copyright 2011, 2018 Yuya Nishihara <yuya@tcha.org>
28060
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
5 *
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
6 * This software may be used and distributed according to the terms of the
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
7 * GNU General Public License version 2 or any later version.
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
8 */
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
9
30693
baee0f47b533 chg: add procutil.h
Jun Wu <quark@fb.com>
parents: 30692
diff changeset
10 #include <assert.h>
baee0f47b533 chg: add procutil.h
Jun Wu <quark@fb.com>
parents: 30692
diff changeset
11 #include <errno.h>
baee0f47b533 chg: add procutil.h
Jun Wu <quark@fb.com>
parents: 30692
diff changeset
12 #include <signal.h>
baee0f47b533 chg: add procutil.h
Jun Wu <quark@fb.com>
parents: 30692
diff changeset
13 #include <string.h>
baee0f47b533 chg: add procutil.h
Jun Wu <quark@fb.com>
parents: 30692
diff changeset
14 #include <unistd.h>
baee0f47b533 chg: add procutil.h
Jun Wu <quark@fb.com>
parents: 30692
diff changeset
15
29608
681fe090d82e chg: forward SIGINT, SIGHUP to process group
Jun Wu <quark@fb.com>
parents: 29440
diff changeset
16 static pid_t peerpgid = 0;
28060
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
17 static pid_t peerpid = 0;
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
18
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
19 static void forwardsignal(int sig)
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
20 {
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
21 assert(peerpid > 0);
40118
cd490ac908c0 rust-chg: extract signal handlers from chg/procutil.c
Yuya Nishihara <yuya@tcha.org>
parents: 35959
diff changeset
22 (void)kill(peerpid, sig);
28060
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
23 }
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
24
29608
681fe090d82e chg: forward SIGINT, SIGHUP to process group
Jun Wu <quark@fb.com>
parents: 29440
diff changeset
25 static void forwardsignaltogroup(int sig)
681fe090d82e chg: forward SIGINT, SIGHUP to process group
Jun Wu <quark@fb.com>
parents: 29440
diff changeset
26 {
681fe090d82e chg: forward SIGINT, SIGHUP to process group
Jun Wu <quark@fb.com>
parents: 29440
diff changeset
27 /* prefer kill(-pgid, sig), fallback to pid if pgid is invalid */
681fe090d82e chg: forward SIGINT, SIGHUP to process group
Jun Wu <quark@fb.com>
parents: 29440
diff changeset
28 pid_t killpid = peerpgid > 1 ? -peerpgid : peerpid;
40118
cd490ac908c0 rust-chg: extract signal handlers from chg/procutil.c
Yuya Nishihara <yuya@tcha.org>
parents: 35959
diff changeset
29 (void)kill(killpid, sig);
29608
681fe090d82e chg: forward SIGINT, SIGHUP to process group
Jun Wu <quark@fb.com>
parents: 29440
diff changeset
30 }
681fe090d82e chg: forward SIGINT, SIGHUP to process group
Jun Wu <quark@fb.com>
parents: 29440
diff changeset
31
28086
65d24ca35496 chg: forward job control signals to worker process (issue5051)
Yuya Nishihara <yuya@tcha.org>
parents: 28085
diff changeset
32 static void handlestopsignal(int sig)
65d24ca35496 chg: forward job control signals to worker process (issue5051)
Yuya Nishihara <yuya@tcha.org>
parents: 28085
diff changeset
33 {
65d24ca35496 chg: forward job control signals to worker process (issue5051)
Yuya Nishihara <yuya@tcha.org>
parents: 28085
diff changeset
34 sigset_t unblockset, oldset;
65d24ca35496 chg: forward job control signals to worker process (issue5051)
Yuya Nishihara <yuya@tcha.org>
parents: 28085
diff changeset
35 struct sigaction sa, oldsa;
41336
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 40119
diff changeset
36 if (sigemptyset(&unblockset) < 0) {
40118
cd490ac908c0 rust-chg: extract signal handlers from chg/procutil.c
Yuya Nishihara <yuya@tcha.org>
parents: 35959
diff changeset
37 return;
41336
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 40119
diff changeset
38 }
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 40119
diff changeset
39 if (sigaddset(&unblockset, sig) < 0) {
40118
cd490ac908c0 rust-chg: extract signal handlers from chg/procutil.c
Yuya Nishihara <yuya@tcha.org>
parents: 35959
diff changeset
40 return;
41336
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 40119
diff changeset
41 }
28086
65d24ca35496 chg: forward job control signals to worker process (issue5051)
Yuya Nishihara <yuya@tcha.org>
parents: 28085
diff changeset
42 memset(&sa, 0, sizeof(sa));
65d24ca35496 chg: forward job control signals to worker process (issue5051)
Yuya Nishihara <yuya@tcha.org>
parents: 28085
diff changeset
43 sa.sa_handler = SIG_DFL;
65d24ca35496 chg: forward job control signals to worker process (issue5051)
Yuya Nishihara <yuya@tcha.org>
parents: 28085
diff changeset
44 sa.sa_flags = SA_RESTART;
41336
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 40119
diff changeset
45 if (sigemptyset(&sa.sa_mask) < 0) {
40118
cd490ac908c0 rust-chg: extract signal handlers from chg/procutil.c
Yuya Nishihara <yuya@tcha.org>
parents: 35959
diff changeset
46 return;
41336
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 40119
diff changeset
47 }
28086
65d24ca35496 chg: forward job control signals to worker process (issue5051)
Yuya Nishihara <yuya@tcha.org>
parents: 28085
diff changeset
48
65d24ca35496 chg: forward job control signals to worker process (issue5051)
Yuya Nishihara <yuya@tcha.org>
parents: 28085
diff changeset
49 forwardsignal(sig);
41336
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 40119
diff changeset
50 if (raise(sig) < 0) { /* resend to self */
40118
cd490ac908c0 rust-chg: extract signal handlers from chg/procutil.c
Yuya Nishihara <yuya@tcha.org>
parents: 35959
diff changeset
51 return;
41336
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 40119
diff changeset
52 }
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 40119
diff changeset
53 if (sigaction(sig, &sa, &oldsa) < 0) {
40118
cd490ac908c0 rust-chg: extract signal handlers from chg/procutil.c
Yuya Nishihara <yuya@tcha.org>
parents: 35959
diff changeset
54 return;
41336
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 40119
diff changeset
55 }
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 40119
diff changeset
56 if (sigprocmask(SIG_UNBLOCK, &unblockset, &oldset) < 0) {
40118
cd490ac908c0 rust-chg: extract signal handlers from chg/procutil.c
Yuya Nishihara <yuya@tcha.org>
parents: 35959
diff changeset
57 return;
41336
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 40119
diff changeset
58 }
28086
65d24ca35496 chg: forward job control signals to worker process (issue5051)
Yuya Nishihara <yuya@tcha.org>
parents: 28085
diff changeset
59 /* resent signal will be handled before sigprocmask() returns */
41336
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 40119
diff changeset
60 if (sigprocmask(SIG_SETMASK, &oldset, NULL) < 0) {
40118
cd490ac908c0 rust-chg: extract signal handlers from chg/procutil.c
Yuya Nishihara <yuya@tcha.org>
parents: 35959
diff changeset
61 return;
41336
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 40119
diff changeset
62 }
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 40119
diff changeset
63 if (sigaction(sig, &oldsa, NULL) < 0) {
40118
cd490ac908c0 rust-chg: extract signal handlers from chg/procutil.c
Yuya Nishihara <yuya@tcha.org>
parents: 35959
diff changeset
64 return;
41336
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 40119
diff changeset
65 }
28086
65d24ca35496 chg: forward job control signals to worker process (issue5051)
Yuya Nishihara <yuya@tcha.org>
parents: 28085
diff changeset
66 }
65d24ca35496 chg: forward job control signals to worker process (issue5051)
Yuya Nishihara <yuya@tcha.org>
parents: 28085
diff changeset
67
40118
cd490ac908c0 rust-chg: extract signal handlers from chg/procutil.c
Yuya Nishihara <yuya@tcha.org>
parents: 35959
diff changeset
68 /*
cd490ac908c0 rust-chg: extract signal handlers from chg/procutil.c
Yuya Nishihara <yuya@tcha.org>
parents: 35959
diff changeset
69 * Installs signal handlers.
cd490ac908c0 rust-chg: extract signal handlers from chg/procutil.c
Yuya Nishihara <yuya@tcha.org>
parents: 35959
diff changeset
70 *
cd490ac908c0 rust-chg: extract signal handlers from chg/procutil.c
Yuya Nishihara <yuya@tcha.org>
parents: 35959
diff changeset
71 * Returns 0 on success, -1 on error and errno is set appropriately.
cd490ac908c0 rust-chg: extract signal handlers from chg/procutil.c
Yuya Nishihara <yuya@tcha.org>
parents: 35959
diff changeset
72 * Installed handlers wouldn't be cleaned up on error.
cd490ac908c0 rust-chg: extract signal handlers from chg/procutil.c
Yuya Nishihara <yuya@tcha.org>
parents: 35959
diff changeset
73 */
cd490ac908c0 rust-chg: extract signal handlers from chg/procutil.c
Yuya Nishihara <yuya@tcha.org>
parents: 35959
diff changeset
74 int setupsignalhandler(pid_t pid, pid_t pgid)
28060
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
75 {
40118
cd490ac908c0 rust-chg: extract signal handlers from chg/procutil.c
Yuya Nishihara <yuya@tcha.org>
parents: 35959
diff changeset
76 if (pid <= 0) {
cd490ac908c0 rust-chg: extract signal handlers from chg/procutil.c
Yuya Nishihara <yuya@tcha.org>
parents: 35959
diff changeset
77 errno = EINVAL;
cd490ac908c0 rust-chg: extract signal handlers from chg/procutil.c
Yuya Nishihara <yuya@tcha.org>
parents: 35959
diff changeset
78 return -1;
cd490ac908c0 rust-chg: extract signal handlers from chg/procutil.c
Yuya Nishihara <yuya@tcha.org>
parents: 35959
diff changeset
79 }
28060
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
80 peerpid = pid;
29608
681fe090d82e chg: forward SIGINT, SIGHUP to process group
Jun Wu <quark@fb.com>
parents: 29440
diff changeset
81 peerpgid = (pgid <= 1 ? 0 : pgid);
681fe090d82e chg: forward SIGINT, SIGHUP to process group
Jun Wu <quark@fb.com>
parents: 29440
diff changeset
82
28060
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
83 struct sigaction sa;
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
84 memset(&sa, 0, sizeof(sa));
31229
68c94f286e25 chg: document why we send SIGHUP and SIGINT to process group
Jun Wu <quark@fb.com>
parents: 30693
diff changeset
85
68c94f286e25 chg: document why we send SIGHUP and SIGINT to process group
Jun Wu <quark@fb.com>
parents: 30693
diff changeset
86 /* deadly signals meant to be sent to a process group:
68c94f286e25 chg: document why we send SIGHUP and SIGINT to process group
Jun Wu <quark@fb.com>
parents: 30693
diff changeset
87 * - SIGHUP: usually generated by the kernel, when termination of a
68c94f286e25 chg: document why we send SIGHUP and SIGINT to process group
Jun Wu <quark@fb.com>
parents: 30693
diff changeset
88 * process causes that process group to become orphaned
68c94f286e25 chg: document why we send SIGHUP and SIGINT to process group
Jun Wu <quark@fb.com>
parents: 30693
diff changeset
89 * - SIGINT: usually generated by the terminal */
29608
681fe090d82e chg: forward SIGINT, SIGHUP to process group
Jun Wu <quark@fb.com>
parents: 29440
diff changeset
90 sa.sa_handler = forwardsignaltogroup;
28060
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
91 sa.sa_flags = SA_RESTART;
41336
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 40119
diff changeset
92 if (sigemptyset(&sa.sa_mask) < 0) {
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 40119
diff changeset
93 return -1;
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 40119
diff changeset
94 }
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 40119
diff changeset
95 if (sigaction(SIGHUP, &sa, NULL) < 0) {
40118
cd490ac908c0 rust-chg: extract signal handlers from chg/procutil.c
Yuya Nishihara <yuya@tcha.org>
parents: 35959
diff changeset
96 return -1;
41336
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 40119
diff changeset
97 }
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 40119
diff changeset
98 if (sigaction(SIGINT, &sa, NULL) < 0) {
40118
cd490ac908c0 rust-chg: extract signal handlers from chg/procutil.c
Yuya Nishihara <yuya@tcha.org>
parents: 35959
diff changeset
99 return -1;
41336
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 40119
diff changeset
100 }
28060
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
101
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
102 /* terminate frontend by double SIGTERM in case of server freeze */
29608
681fe090d82e chg: forward SIGINT, SIGHUP to process group
Jun Wu <quark@fb.com>
parents: 29440
diff changeset
103 sa.sa_handler = forwardsignal;
28060
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
104 sa.sa_flags |= SA_RESETHAND;
41336
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 40119
diff changeset
105 if (sigaction(SIGTERM, &sa, NULL) < 0) {
40118
cd490ac908c0 rust-chg: extract signal handlers from chg/procutil.c
Yuya Nishihara <yuya@tcha.org>
parents: 35959
diff changeset
106 return -1;
41336
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 40119
diff changeset
107 }
28086
65d24ca35496 chg: forward job control signals to worker process (issue5051)
Yuya Nishihara <yuya@tcha.org>
parents: 28085
diff changeset
108
28980
b89e4457fa86 chg: forward SIGWINCH to worker
Jun Wu <quark@fb.com>
parents: 28863
diff changeset
109 /* notify the worker about window resize events */
b89e4457fa86 chg: forward SIGWINCH to worker
Jun Wu <quark@fb.com>
parents: 28863
diff changeset
110 sa.sa_flags = SA_RESTART;
41336
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 40119
diff changeset
111 if (sigaction(SIGWINCH, &sa, NULL) < 0) {
40118
cd490ac908c0 rust-chg: extract signal handlers from chg/procutil.c
Yuya Nishihara <yuya@tcha.org>
parents: 35959
diff changeset
112 return -1;
41336
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 40119
diff changeset
113 }
31230
cc37b5a06e32 chg: forward user-defined signals
Jun Wu <quark@fb.com>
parents: 31229
diff changeset
114 /* forward user-defined signals */
41336
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 40119
diff changeset
115 if (sigaction(SIGUSR1, &sa, NULL) < 0) {
40118
cd490ac908c0 rust-chg: extract signal handlers from chg/procutil.c
Yuya Nishihara <yuya@tcha.org>
parents: 35959
diff changeset
116 return -1;
41336
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 40119
diff changeset
117 }
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 40119
diff changeset
118 if (sigaction(SIGUSR2, &sa, NULL) < 0) {
40118
cd490ac908c0 rust-chg: extract signal handlers from chg/procutil.c
Yuya Nishihara <yuya@tcha.org>
parents: 35959
diff changeset
119 return -1;
41336
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 40119
diff changeset
120 }
28086
65d24ca35496 chg: forward job control signals to worker process (issue5051)
Yuya Nishihara <yuya@tcha.org>
parents: 28085
diff changeset
121 /* propagate job control requests to worker */
65d24ca35496 chg: forward job control signals to worker process (issue5051)
Yuya Nishihara <yuya@tcha.org>
parents: 28085
diff changeset
122 sa.sa_handler = forwardsignal;
65d24ca35496 chg: forward job control signals to worker process (issue5051)
Yuya Nishihara <yuya@tcha.org>
parents: 28085
diff changeset
123 sa.sa_flags = SA_RESTART;
41336
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 40119
diff changeset
124 if (sigaction(SIGCONT, &sa, NULL) < 0) {
40118
cd490ac908c0 rust-chg: extract signal handlers from chg/procutil.c
Yuya Nishihara <yuya@tcha.org>
parents: 35959
diff changeset
125 return -1;
41336
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 40119
diff changeset
126 }
28086
65d24ca35496 chg: forward job control signals to worker process (issue5051)
Yuya Nishihara <yuya@tcha.org>
parents: 28085
diff changeset
127 sa.sa_handler = handlestopsignal;
65d24ca35496 chg: forward job control signals to worker process (issue5051)
Yuya Nishihara <yuya@tcha.org>
parents: 28085
diff changeset
128 sa.sa_flags = SA_RESTART;
41336
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 40119
diff changeset
129 if (sigaction(SIGTSTP, &sa, NULL) < 0) {
40118
cd490ac908c0 rust-chg: extract signal handlers from chg/procutil.c
Yuya Nishihara <yuya@tcha.org>
parents: 35959
diff changeset
130 return -1;
41336
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 40119
diff changeset
131 }
28086
65d24ca35496 chg: forward job control signals to worker process (issue5051)
Yuya Nishihara <yuya@tcha.org>
parents: 28085
diff changeset
132
40118
cd490ac908c0 rust-chg: extract signal handlers from chg/procutil.c
Yuya Nishihara <yuya@tcha.org>
parents: 35959
diff changeset
133 return 0;
28060
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
134 }
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
135
40118
cd490ac908c0 rust-chg: extract signal handlers from chg/procutil.c
Yuya Nishihara <yuya@tcha.org>
parents: 35959
diff changeset
136 /*
cd490ac908c0 rust-chg: extract signal handlers from chg/procutil.c
Yuya Nishihara <yuya@tcha.org>
parents: 35959
diff changeset
137 * Restores signal handlers to the default, and masks SIGINT.
cd490ac908c0 rust-chg: extract signal handlers from chg/procutil.c
Yuya Nishihara <yuya@tcha.org>
parents: 35959
diff changeset
138 *
cd490ac908c0 rust-chg: extract signal handlers from chg/procutil.c
Yuya Nishihara <yuya@tcha.org>
parents: 35959
diff changeset
139 * Returns 0 on success, -1 on error and errno is set appropriately.
cd490ac908c0 rust-chg: extract signal handlers from chg/procutil.c
Yuya Nishihara <yuya@tcha.org>
parents: 35959
diff changeset
140 */
cd490ac908c0 rust-chg: extract signal handlers from chg/procutil.c
Yuya Nishihara <yuya@tcha.org>
parents: 35959
diff changeset
141 int restoresignalhandler(void)
29369
85a18f3c0bdd chg: reset signal handlers to default before waiting pager
Yuya Nishihara <yuya@tcha.org>
parents: 29357
diff changeset
142 {
85a18f3c0bdd chg: reset signal handlers to default before waiting pager
Yuya Nishihara <yuya@tcha.org>
parents: 29357
diff changeset
143 struct sigaction sa;
85a18f3c0bdd chg: reset signal handlers to default before waiting pager
Yuya Nishihara <yuya@tcha.org>
parents: 29357
diff changeset
144 memset(&sa, 0, sizeof(sa));
85a18f3c0bdd chg: reset signal handlers to default before waiting pager
Yuya Nishihara <yuya@tcha.org>
parents: 29357
diff changeset
145 sa.sa_handler = SIG_DFL;
85a18f3c0bdd chg: reset signal handlers to default before waiting pager
Yuya Nishihara <yuya@tcha.org>
parents: 29357
diff changeset
146 sa.sa_flags = SA_RESTART;
41336
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 40119
diff changeset
147 if (sigemptyset(&sa.sa_mask) < 0) {
40118
cd490ac908c0 rust-chg: extract signal handlers from chg/procutil.c
Yuya Nishihara <yuya@tcha.org>
parents: 35959
diff changeset
148 return -1;
41336
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 40119
diff changeset
149 }
29369
85a18f3c0bdd chg: reset signal handlers to default before waiting pager
Yuya Nishihara <yuya@tcha.org>
parents: 29357
diff changeset
150
41336
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 40119
diff changeset
151 if (sigaction(SIGHUP, &sa, NULL) < 0) {
40118
cd490ac908c0 rust-chg: extract signal handlers from chg/procutil.c
Yuya Nishihara <yuya@tcha.org>
parents: 35959
diff changeset
152 return -1;
41336
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 40119
diff changeset
153 }
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 40119
diff changeset
154 if (sigaction(SIGTERM, &sa, NULL) < 0) {
40118
cd490ac908c0 rust-chg: extract signal handlers from chg/procutil.c
Yuya Nishihara <yuya@tcha.org>
parents: 35959
diff changeset
155 return -1;
41336
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 40119
diff changeset
156 }
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 40119
diff changeset
157 if (sigaction(SIGWINCH, &sa, NULL) < 0) {
40118
cd490ac908c0 rust-chg: extract signal handlers from chg/procutil.c
Yuya Nishihara <yuya@tcha.org>
parents: 35959
diff changeset
158 return -1;
41336
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 40119
diff changeset
159 }
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 40119
diff changeset
160 if (sigaction(SIGCONT, &sa, NULL) < 0) {
40118
cd490ac908c0 rust-chg: extract signal handlers from chg/procutil.c
Yuya Nishihara <yuya@tcha.org>
parents: 35959
diff changeset
161 return -1;
41336
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 40119
diff changeset
162 }
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 40119
diff changeset
163 if (sigaction(SIGTSTP, &sa, NULL) < 0) {
40118
cd490ac908c0 rust-chg: extract signal handlers from chg/procutil.c
Yuya Nishihara <yuya@tcha.org>
parents: 35959
diff changeset
164 return -1;
41336
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 40119
diff changeset
165 }
29369
85a18f3c0bdd chg: reset signal handlers to default before waiting pager
Yuya Nishihara <yuya@tcha.org>
parents: 29357
diff changeset
166
29370
3ddf4d0c4170 chg: ignore SIGINT while waiting pager termination
Yuya Nishihara <yuya@tcha.org>
parents: 29369
diff changeset
167 /* ignore Ctrl+C while shutting down to make pager exits cleanly */
3ddf4d0c4170 chg: ignore SIGINT while waiting pager termination
Yuya Nishihara <yuya@tcha.org>
parents: 29369
diff changeset
168 sa.sa_handler = SIG_IGN;
41336
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 40119
diff changeset
169 if (sigaction(SIGINT, &sa, NULL) < 0) {
40118
cd490ac908c0 rust-chg: extract signal handlers from chg/procutil.c
Yuya Nishihara <yuya@tcha.org>
parents: 35959
diff changeset
170 return -1;
41336
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 40119
diff changeset
171 }
29370
3ddf4d0c4170 chg: ignore SIGINT while waiting pager termination
Yuya Nishihara <yuya@tcha.org>
parents: 29369
diff changeset
172
29369
85a18f3c0bdd chg: reset signal handlers to default before waiting pager
Yuya Nishihara <yuya@tcha.org>
parents: 29357
diff changeset
173 peerpid = 0;
29344
bb3d5c20eaf6 chg: exec pager in child process
Jun Wu <quark@fb.com>
parents: 29016
diff changeset
174 return 0;
bb3d5c20eaf6 chg: exec pager in child process
Jun Wu <quark@fb.com>
parents: 29016
diff changeset
175 }