public inbox for cluster-cvs@sourceware.org
help / color / mirror / Atom feed
From: Lon Hohberger <lon@fedoraproject.org>
To: cluster-cvs-relay@redhat.com
Subject: cluster: RHEL5 - rgmanager: Block signals in worker threads
Date: Fri, 27 Mar 2009 14:27:00 -0000	[thread overview]
Message-ID: <20090327142615.952A0120150@lists.fedorahosted.org> (raw)

Gitweb:        http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=54c701171b723d8856baeb14a2ee1d1f0ee82f71
Commit:        54c701171b723d8856baeb14a2ee1d1f0ee82f71
Parent:        638f8dbcfc5c9e81ef6f6da324f6a532fa5a71f7
Author:        Lon Hohberger <lhh@redhat.com>
AuthorDate:    Wed Mar 18 17:11:48 2009 -0400
Committer:     Lon Hohberger <lhh@redhat.com>
CommitterDate: Fri Mar 27 10:25:09 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 <lhh@redhat.com>
---
 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 2565f26..c3c249f 100644
--- a/rgmanager/src/clulib/tmgr.c
+++ b/rgmanager/src/clulib/tmgr.c
@@ -39,10 +39,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)
 {
@@ -68,14 +96,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;
 	}
 


                 reply	other threads:[~2009-03-27 14:27 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090327142615.952A0120150@lists.fedorahosted.org \
    --to=lon@fedoraproject.org \
    --cc=cluster-cvs-relay@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).