Allow specific signal to specific threads

This commit is contained in:
topjohnwu 2017-11-15 05:15:58 +08:00
parent 32ee8e462c
commit 68eb0bdec9
2 changed files with 21 additions and 1 deletions

View File

@ -10,6 +10,7 @@
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <pthread.h> #include <pthread.h>
#include <signal.h>
#include <sys/un.h> #include <sys/un.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
@ -127,6 +128,13 @@ void start_daemon() {
xdup2(fd, STDERR_FILENO); xdup2(fd, STDERR_FILENO);
close(fd); close(fd);
// Block user signals
sigset_t block_set;
sigemptyset(&block_set);
sigaddset(&block_set, SIGUSR1);
sigaddset(&block_set, SIGUSR2);
pthread_sigmask(SIG_SETMASK, &block_set, NULL);
struct sockaddr_un sun; struct sockaddr_un sun;
fd = setup_socket(&sun); fd = setup_socket(&sun);

View File

@ -149,6 +149,13 @@ exit:
} }
void proc_monitor() { void proc_monitor() {
// Unblock user signals
sigset_t block_set;
sigemptyset(&block_set);
sigaddset(&block_set, TERM_THREAD);
sigaddset(&block_set, HIDE_DONE);
pthread_sigmask(SIG_UNBLOCK, &block_set, NULL);
// Register the cancel signal // Register the cancel signal
struct sigaction act; struct sigaction act;
memset(&act, 0, sizeof(act)); memset(&act, 0, sizeof(act));
@ -188,7 +195,12 @@ void proc_monitor() {
xpipe2(pipefd, O_CLOEXEC); xpipe2(pipefd, O_CLOEXEC);
logcat_events[HIDE_EVENT] = pipefd[1]; logcat_events[HIDE_EVENT] = pipefd[1];
for (char *log, *line; xxread(pipefd[0], &log, sizeof(log)) > 0; free(log)) { for (char *log, *line; 1; free(log)) {
if (read(pipefd[0], &log, sizeof(log)) != sizeof(log)) {
/* It might be interrupted */
log = NULL;
continue;
}
char *ss; char *ss;
if ((ss = strstr(log, "am_proc_start")) && (ss = strchr(ss, '['))) { if ((ss = strstr(log, "am_proc_start")) && (ss = strchr(ss, '['))) {
int pid, ret, comma = 0; int pid, ret, comma = 0;