Mercurial > hg
annotate rust/chg/src/sighandlers.c @ 50824:489268c8ee7e
cmdutil: migrate `opts` on commitstatus() to native kwargs
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Sat, 19 Aug 2023 23:06:40 -0400 |
parents | 763b45bc4483 |
children |
rev | line source |
---|---|
28060 | 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 | 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 | 5 * |
6 * This software may be used and distributed according to the terms of the | |
7 * GNU General Public License version 2 or any later version. | |
8 */ | |
9 | |
30693 | 10 #include <assert.h> |
11 #include <errno.h> | |
12 #include <signal.h> | |
13 #include <string.h> | |
14 #include <unistd.h> | |
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 | 17 static pid_t peerpid = 0; |
18 | |
19 static void forwardsignal(int sig) | |
20 { | |
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 | 23 } |
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 | 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 | 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 | 83 struct sigaction sa; |
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 | 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 | 101 |
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 | 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 | 109 /* notify the worker about window resize events */ |
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 | 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 | 134 } |
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 | 174 return 0; |
175 } |