From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5161 invoked by alias); 19 Mar 2009 16:16:03 -0000 Received: (qmail 5151 invoked by alias); 19 Mar 2009 16:16:02 -0000 X-SWARE-Spam-Status: No, hits=-1.5 required=5.0 tests=AWL,BAYES_00,J_CHICKENPOX_66,SPF_HELO_PASS X-Spam-Status: No, hits=-1.5 required=5.0 tests=AWL,BAYES_00,J_CHICKENPOX_66,SPF_HELO_PASS X-Spam-Check-By: sourceware.org X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on bastion.fedora.phx.redhat.com Subject: cluster: STABLE3 - rgmanager: Block signals in worker threads To: cluster-cvs-relay@redhat.com X-Project: Cluster Project X-Git-Module: cluster.git X-Git-Refname: refs/heads/STABLE3 X-Git-Reftype: branch X-Git-Oldrev: 58476c7dab742448b6f269e252941bbd65042f0d X-Git-Newrev: 7644f3bb56f130fe8546fb70fb8bbb12bd56c325 From: Lon Hohberger Message-Id: <20090319161543.0D6E2120272@lists.fedorahosted.org> Date: Thu, 19 Mar 2009 16:16:00 -0000 X-Scanned-By: MIMEDefang 2.58 on 172.16.52.254 Mailing-List: contact cluster-cvs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: cluster-cvs-owner@sourceware.org X-SW-Source: 2009-q1/txt/msg00825.txt.bz2 Gitweb: http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=7644f3bb56f130fe8546fb70fb8bbb12bd56c325 Commit: 7644f3bb56f130fe8546fb70fb8bbb12bd56c325 Parent: 58476c7dab742448b6f269e252941bbd65042f0d Author: Lon Hohberger AuthorDate: Wed Mar 18 17:11:48 2009 -0400 Committer: Lon Hohberger CommitterDate: Thu Mar 19 12:15:35 2009 -0400 rgmanager: Block signals in worker threads Because signals are delivered to a process instead of a thread, not blocking signals means that for example a SIGHUP or SIGUSR1 could interfere with operations taking place like status checks. Signed-off-by: Lon Hohberger --- rgmanager/src/clulib/tmgr.c | 38 +++++++++++++++++++++++++++++++++++++- 1 files changed, 37 insertions(+), 1 deletions(-) diff --git a/rgmanager/src/clulib/tmgr.c b/rgmanager/src/clulib/tmgr.c index 864d090..f2cb2db 100644 --- a/rgmanager/src/clulib/tmgr.c +++ b/rgmanager/src/clulib/tmgr.c @@ -20,10 +20,38 @@ typedef struct _thr { pthread_t th; } mthread_t; +typedef struct _arglist { + void *(*real_thread_fn)(void *arg); + void *real_thread_arg; +} thread_arg_t; + static mthread_t *_tlist = NULL; static int _tcount = 0; static pthread_rwlock_t _tlock = PTHREAD_RWLOCK_INITIALIZER; +void * +setup_thread(void *thread_arg) +{ + thread_arg_t *args = (thread_arg_t *)thread_arg; + void *(*thread_func)(void *arg); + sigset_t set; + + /* Block all non-fatal signals */ + sigemptyset(&set); + sigaddset(&set, SIGUSR1); + sigaddset(&set, SIGUSR2); + sigaddset(&set, SIGINT); + sigaddset(&set, SIGTERM); + sigaddset(&set, SIGQUIT); + sigaddset(&set, SIGHUP); + sigprocmask(SIG_BLOCK, &set, NULL); + + thread_func = args->real_thread_fn; + thread_arg = args->real_thread_arg; + free(args); + return thread_func(thread_arg); +} + void dump_thread_states(FILE *fp) { @@ -49,14 +77,22 @@ __wrap_pthread_create(pthread_t *th, const pthread_attr_t *attr, { void *fn = start_routine; mthread_t *new; + thread_arg_t *targ; int ret; new = malloc(sizeof (*new)); + targ = malloc(sizeof (*targ)); + if (!targ||!new) + return -1; + targ->real_thread_fn = start_routine; + targ->real_thread_arg = arg; - ret = __real_pthread_create(th, attr, start_routine, arg); + ret = __real_pthread_create(th, attr, setup_thread, targ); if (ret) { if (new) free(new); + if (targ) + free(targ); return ret; }