annotate rust/chg/src/sighandlers.c @ 40119:e70b616a077b

rust-chg: remove SIGCHLD handler which won't work in oxidized chg Since pager is managed by the Rust part, the C code doesn't know the pager pid. I could make the Rust part teach the pid to C, but still installing SIGCHLD handler seems horrible idea since we no longer use handcrafted low-level process management functions. Instead, I'm thinking of adding async handler to send SIGPIPE at the exit of the pager.
author Yuya Nishihara <yuya@tcha.org>
date Mon, 24 Sep 2018 22:19:49 +0900
parents cd490ac908c0
children 763b45bc4483
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;
65d24ca35496 chg: forward job control signals to worker process (issue5051)
Yuya Nishihara <yuya@tcha.org>
parents: 28085
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;
28086
65d24ca35496 chg: forward job control signals to worker process (issue5051)
Yuya Nishihara <yuya@tcha.org>
parents: 28085
diff changeset
38 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
39 return;
28086
65d24ca35496 chg: forward job control signals to worker process (issue5051)
Yuya Nishihara <yuya@tcha.org>
parents: 28085
diff changeset
40 memset(&sa, 0, sizeof(sa));
65d24ca35496 chg: forward job control signals to worker process (issue5051)
Yuya Nishihara <yuya@tcha.org>
parents: 28085
diff changeset
41 sa.sa_handler = SIG_DFL;
65d24ca35496 chg: forward job control signals to worker process (issue5051)
Yuya Nishihara <yuya@tcha.org>
parents: 28085
diff changeset
42 sa.sa_flags = SA_RESTART;
65d24ca35496 chg: forward job control signals to worker process (issue5051)
Yuya Nishihara <yuya@tcha.org>
parents: 28085
diff changeset
43 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
44 return;
28086
65d24ca35496 chg: forward job control signals to worker process (issue5051)
Yuya Nishihara <yuya@tcha.org>
parents: 28085
diff changeset
45
65d24ca35496 chg: forward job control signals to worker process (issue5051)
Yuya Nishihara <yuya@tcha.org>
parents: 28085
diff changeset
46 forwardsignal(sig);
35959
9724f54923ec chg: enable clang-format on all .c and .h files
Augie Fackler <augie@google.com>
parents: 31941
diff changeset
47 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
48 return;
28086
65d24ca35496 chg: forward job control signals to worker process (issue5051)
Yuya Nishihara <yuya@tcha.org>
parents: 28085
diff changeset
49 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
50 return;
28086
65d24ca35496 chg: forward job control signals to worker process (issue5051)
Yuya Nishihara <yuya@tcha.org>
parents: 28085
diff changeset
51 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
52 return;
28086
65d24ca35496 chg: forward job control signals to worker process (issue5051)
Yuya Nishihara <yuya@tcha.org>
parents: 28085
diff changeset
53 /* resent signal will be handled before sigprocmask() returns */
65d24ca35496 chg: forward job control signals to worker process (issue5051)
Yuya Nishihara <yuya@tcha.org>
parents: 28085
diff changeset
54 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
55 return;
28086
65d24ca35496 chg: forward job control signals to worker process (issue5051)
Yuya Nishihara <yuya@tcha.org>
parents: 28085
diff changeset
56 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
57 return;
28086
65d24ca35496 chg: forward job control signals to worker process (issue5051)
Yuya Nishihara <yuya@tcha.org>
parents: 28085
diff changeset
58 }
65d24ca35496 chg: forward job control signals to worker process (issue5051)
Yuya Nishihara <yuya@tcha.org>
parents: 28085
diff changeset
59
40118
cd490ac908c0 rust-chg: extract signal handlers from chg/procutil.c
Yuya Nishihara <yuya@tcha.org>
parents: 35959
diff changeset
60 /*
cd490ac908c0 rust-chg: extract signal handlers from chg/procutil.c
Yuya Nishihara <yuya@tcha.org>
parents: 35959
diff changeset
61 * Installs signal handlers.
cd490ac908c0 rust-chg: extract signal handlers from chg/procutil.c
Yuya Nishihara <yuya@tcha.org>
parents: 35959
diff changeset
62 *
cd490ac908c0 rust-chg: extract signal handlers from chg/procutil.c
Yuya Nishihara <yuya@tcha.org>
parents: 35959
diff changeset
63 * 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
64 * 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
65 */
cd490ac908c0 rust-chg: extract signal handlers from chg/procutil.c
Yuya Nishihara <yuya@tcha.org>
parents: 35959
diff changeset
66 int setupsignalhandler(pid_t pid, pid_t pgid)
28060
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
67 {
40118
cd490ac908c0 rust-chg: extract signal handlers from chg/procutil.c
Yuya Nishihara <yuya@tcha.org>
parents: 35959
diff changeset
68 if (pid <= 0) {
cd490ac908c0 rust-chg: extract signal handlers from chg/procutil.c
Yuya Nishihara <yuya@tcha.org>
parents: 35959
diff changeset
69 errno = EINVAL;
cd490ac908c0 rust-chg: extract signal handlers from chg/procutil.c
Yuya Nishihara <yuya@tcha.org>
parents: 35959
diff changeset
70 return -1;
cd490ac908c0 rust-chg: extract signal handlers from chg/procutil.c
Yuya Nishihara <yuya@tcha.org>
parents: 35959
diff changeset
71 }
28060
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
72 peerpid = pid;
29608
681fe090d82e chg: forward SIGINT, SIGHUP to process group
Jun Wu <quark@fb.com>
parents: 29440
diff changeset
73 peerpgid = (pgid <= 1 ? 0 : pgid);
681fe090d82e chg: forward SIGINT, SIGHUP to process group
Jun Wu <quark@fb.com>
parents: 29440
diff changeset
74
28060
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
75 struct sigaction sa;
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
76 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
77
68c94f286e25 chg: document why we send SIGHUP and SIGINT to process group
Jun Wu <quark@fb.com>
parents: 30693
diff changeset
78 /* 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
79 * - 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
80 * 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
81 * - SIGINT: usually generated by the terminal */
29608
681fe090d82e chg: forward SIGINT, SIGHUP to process group
Jun Wu <quark@fb.com>
parents: 29440
diff changeset
82 sa.sa_handler = forwardsignaltogroup;
28060
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
83 sa.sa_flags = SA_RESTART;
28085
c0d1bf1b26b7 chg: verify return value of sigaction() and sigemptyset()
Yuya Nishihara <yuya@tcha.org>
parents: 28084
diff changeset
84 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
85 return -1;
28085
c0d1bf1b26b7 chg: verify return value of sigaction() and sigemptyset()
Yuya Nishihara <yuya@tcha.org>
parents: 28084
diff changeset
86 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
87 return -1;
28085
c0d1bf1b26b7 chg: verify return value of sigaction() and sigemptyset()
Yuya Nishihara <yuya@tcha.org>
parents: 28084
diff changeset
88 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
89 return -1;
28060
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
90
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
91 /* 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
92 sa.sa_handler = forwardsignal;
28060
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
93 sa.sa_flags |= SA_RESETHAND;
28085
c0d1bf1b26b7 chg: verify return value of sigaction() and sigemptyset()
Yuya Nishihara <yuya@tcha.org>
parents: 28084
diff changeset
94 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
95 return -1;
28086
65d24ca35496 chg: forward job control signals to worker process (issue5051)
Yuya Nishihara <yuya@tcha.org>
parents: 28085
diff changeset
96
28980
b89e4457fa86 chg: forward SIGWINCH to worker
Jun Wu <quark@fb.com>
parents: 28863
diff changeset
97 /* notify the worker about window resize events */
b89e4457fa86 chg: forward SIGWINCH to worker
Jun Wu <quark@fb.com>
parents: 28863
diff changeset
98 sa.sa_flags = SA_RESTART;
b89e4457fa86 chg: forward SIGWINCH to worker
Jun Wu <quark@fb.com>
parents: 28863
diff changeset
99 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
100 return -1;
31230
cc37b5a06e32 chg: forward user-defined signals
Jun Wu <quark@fb.com>
parents: 31229
diff changeset
101 /* forward user-defined signals */
cc37b5a06e32 chg: forward user-defined signals
Jun Wu <quark@fb.com>
parents: 31229
diff changeset
102 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
103 return -1;
31230
cc37b5a06e32 chg: forward user-defined signals
Jun Wu <quark@fb.com>
parents: 31229
diff changeset
104 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
105 return -1;
28086
65d24ca35496 chg: forward job control signals to worker process (issue5051)
Yuya Nishihara <yuya@tcha.org>
parents: 28085
diff changeset
106 /* 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
107 sa.sa_handler = forwardsignal;
65d24ca35496 chg: forward job control signals to worker process (issue5051)
Yuya Nishihara <yuya@tcha.org>
parents: 28085
diff changeset
108 sa.sa_flags = SA_RESTART;
65d24ca35496 chg: forward job control signals to worker process (issue5051)
Yuya Nishihara <yuya@tcha.org>
parents: 28085
diff changeset
109 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
110 return -1;
28086
65d24ca35496 chg: forward job control signals to worker process (issue5051)
Yuya Nishihara <yuya@tcha.org>
parents: 28085
diff changeset
111 sa.sa_handler = handlestopsignal;
65d24ca35496 chg: forward job control signals to worker process (issue5051)
Yuya Nishihara <yuya@tcha.org>
parents: 28085
diff changeset
112 sa.sa_flags = SA_RESTART;
65d24ca35496 chg: forward job control signals to worker process (issue5051)
Yuya Nishihara <yuya@tcha.org>
parents: 28085
diff changeset
113 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
114 return -1;
28086
65d24ca35496 chg: forward job control signals to worker process (issue5051)
Yuya Nishihara <yuya@tcha.org>
parents: 28085
diff changeset
115
40118
cd490ac908c0 rust-chg: extract signal handlers from chg/procutil.c
Yuya Nishihara <yuya@tcha.org>
parents: 35959
diff changeset
116 return 0;
28060
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
117 }
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
118
40118
cd490ac908c0 rust-chg: extract signal handlers from chg/procutil.c
Yuya Nishihara <yuya@tcha.org>
parents: 35959
diff changeset
119 /*
cd490ac908c0 rust-chg: extract signal handlers from chg/procutil.c
Yuya Nishihara <yuya@tcha.org>
parents: 35959
diff changeset
120 * 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
121 *
cd490ac908c0 rust-chg: extract signal handlers from chg/procutil.c
Yuya Nishihara <yuya@tcha.org>
parents: 35959
diff changeset
122 * 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
123 */
cd490ac908c0 rust-chg: extract signal handlers from chg/procutil.c
Yuya Nishihara <yuya@tcha.org>
parents: 35959
diff changeset
124 int restoresignalhandler(void)
29369
85a18f3c0bdd chg: reset signal handlers to default before waiting pager
Yuya Nishihara <yuya@tcha.org>
parents: 29357
diff changeset
125 {
85a18f3c0bdd chg: reset signal handlers to default before waiting pager
Yuya Nishihara <yuya@tcha.org>
parents: 29357
diff changeset
126 struct sigaction sa;
85a18f3c0bdd chg: reset signal handlers to default before waiting pager
Yuya Nishihara <yuya@tcha.org>
parents: 29357
diff changeset
127 memset(&sa, 0, sizeof(sa));
85a18f3c0bdd chg: reset signal handlers to default before waiting pager
Yuya Nishihara <yuya@tcha.org>
parents: 29357
diff changeset
128 sa.sa_handler = SIG_DFL;
85a18f3c0bdd chg: reset signal handlers to default before waiting pager
Yuya Nishihara <yuya@tcha.org>
parents: 29357
diff changeset
129 sa.sa_flags = SA_RESTART;
85a18f3c0bdd chg: reset signal handlers to default before waiting pager
Yuya Nishihara <yuya@tcha.org>
parents: 29357
diff changeset
130 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
131 return -1;
29369
85a18f3c0bdd chg: reset signal handlers to default before waiting pager
Yuya Nishihara <yuya@tcha.org>
parents: 29357
diff changeset
132
85a18f3c0bdd chg: reset signal handlers to default before waiting pager
Yuya Nishihara <yuya@tcha.org>
parents: 29357
diff changeset
133 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
134 return -1;
29369
85a18f3c0bdd chg: reset signal handlers to default before waiting pager
Yuya Nishihara <yuya@tcha.org>
parents: 29357
diff changeset
135 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
136 return -1;
29369
85a18f3c0bdd chg: reset signal handlers to default before waiting pager
Yuya Nishihara <yuya@tcha.org>
parents: 29357
diff changeset
137 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
138 return -1;
29369
85a18f3c0bdd chg: reset signal handlers to default before waiting pager
Yuya Nishihara <yuya@tcha.org>
parents: 29357
diff changeset
139 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
140 return -1;
29369
85a18f3c0bdd chg: reset signal handlers to default before waiting pager
Yuya Nishihara <yuya@tcha.org>
parents: 29357
diff changeset
141 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
142 return -1;
29369
85a18f3c0bdd chg: reset signal handlers to default before waiting pager
Yuya Nishihara <yuya@tcha.org>
parents: 29357
diff changeset
143
29370
3ddf4d0c4170 chg: ignore SIGINT while waiting pager termination
Yuya Nishihara <yuya@tcha.org>
parents: 29369
diff changeset
144 /* 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
145 sa.sa_handler = SIG_IGN;
3ddf4d0c4170 chg: ignore SIGINT while waiting pager termination
Yuya Nishihara <yuya@tcha.org>
parents: 29369
diff changeset
146 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
147 return -1;
29370
3ddf4d0c4170 chg: ignore SIGINT while waiting pager termination
Yuya Nishihara <yuya@tcha.org>
parents: 29369
diff changeset
148
29369
85a18f3c0bdd chg: reset signal handlers to default before waiting pager
Yuya Nishihara <yuya@tcha.org>
parents: 29357
diff changeset
149 peerpid = 0;
29344
bb3d5c20eaf6 chg: exec pager in child process
Jun Wu <quark@fb.com>
parents: 29016
diff changeset
150 return 0;
bb3d5c20eaf6 chg: exec pager in child process
Jun Wu <quark@fb.com>
parents: 29016
diff changeset
151 }