Răsfoiți Sursa

Merge trunk revision 2382:
r2382 | fabbione | 2009-08-09 22:32:58 -0700 (Sun, 09 Aug 2009) | 21 lines

logsys: fix segfault in logsys_thread_priority_set

logsys_thread_priority_set expects that wthread is already running
but doesn't perform any check if it is.

if logsys_thread_priority_set is invoked before forking the thread,
a segfault is guaranteed.

this changes to logsys_thread_priority_set ensure that a request
for a new scheduler priority is queued if the wthread is not
created yet and the new scheduler parameters are applied as early
as possible after the thread is created.

At the same time:

- add a few comments on clean up that needs to be done
- remove a redundant check for policy != SCHED_OTHER as that's
corosync need specific. logsys should simply accept the request
and apply it.



git-svn-id: http://svn.fedorahosted.org/svn/corosync/branches/flatiron@2435 fd59a12c-fef9-0310-b244-a6a79926bd2f

Steven Dake 16 ani în urmă
părinte
comite
efc806aa7f
1 a modificat fișierele cu 33 adăugiri și 7 ștergeri
  1. 33 7
      exec/logsys.c

+ 33 - 7
exec/logsys.c

@@ -131,6 +131,10 @@ unsigned int flt_data_size;
 
 static int logsys_system_needs_init = LOGSYS_LOGGER_NEEDS_INIT;
 
+static int logsys_sched_param_queued = 0;
+static int logsys_sched_policy;
+static struct sched_param logsys_sched_param;
+
 static int logsys_after_log_ops_yield = 10;
 
 /*
@@ -783,14 +787,31 @@ static void wthread_create (void)
 	pthread_mutex_init (&logsys_cond_mutex, NULL);
 	pthread_cond_init (&logsys_cond, NULL);
 	pthread_mutex_lock (&logsys_cond_mutex);
-	res = pthread_create (&logsys_thread_id, NULL,
-		logsys_worker_thread, NULL);
-
 
 	/*
-	 * Wait for thread to be started
+	 * TODO: propagate pthread_create errors back to the caller
 	 */
-	wthread_wait_locked ();
+	res = pthread_create (&logsys_thread_id, NULL,
+		logsys_worker_thread, NULL);
+
+	if (res == 0) {
+		/*
+		 * Wait for thread to be started
+		 */
+		wthread_wait_locked ();
+		if (logsys_sched_param_queued == 1) {
+			/*
+			 * TODO: propagate logsys_thread_priority_set errors back to
+			 * the caller
+			 */
+			res = logsys_thread_priority_set (logsys_sched_policy,
+						    &logsys_sched_param,
+						    logsys_after_log_ops_yield);
+			logsys_sched_param_queued = 0;
+		}
+	} else {
+		wthread_active = 0;
+	}
 }
 
 static int _logsys_config_subsys_get_unlocked (const char *subsys)
@@ -1610,15 +1631,20 @@ int logsys_thread_priority_set (
 	int res = 0;
 
 #if defined(HAVE_PTHREAD_SETSCHEDPARAM) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
-	if (policy != SCHED_OTHER) {
+	if (wthread_active == 0) {
+		logsys_sched_policy = policy;
+		memcpy(&logsys_sched_param, &param, sizeof(struct sched_param));
+		logsys_sched_param_queued = 1;
+	} else {
 		res = pthread_setschedparam (logsys_thread_id, policy, param);
 	}
 #endif
+
 	if (after_log_ops_yield > 0) {
 		logsys_after_log_ops_yield = after_log_ops_yield;
 	}
-	return (res);
 
+	return (res);
 }
 
 int logsys_log_rec_store (const char *filename)