From: Jeff Trawick Date: Mon, 31 Jul 2000 15:39:19 +0000 (+0000) Subject: Fix some problems with which error code to use after a pthread_ failure. X-Git-Tag: APACHE_2_0_ALPHA_5~24 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e23401a35b1f1f7f293ddfa1a94026d3fdd75762;p=apache Fix some problems with which error code to use after a pthread_ failure. Most of the changes added support for PTHREAD_SETS_ERRNO; a few of the changes fixed bugs in existing code which always used errno (which doesn't get the right error code on most platforms). git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@85963 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/server/mpm/dexter/dexter.c b/server/mpm/dexter/dexter.c index 7de8d0108d..e0b8df672f 100644 --- a/server/mpm/dexter/dexter.c +++ b/server/mpm/dexter/dexter.c @@ -434,12 +434,16 @@ static void *worker_thread(void *); static int start_thread(void) { pthread_t thread; + int rc; pthread_mutex_lock(&worker_thread_count_mutex); if (worker_thread_count < max_threads) { - if (pthread_create(&thread, &worker_thread_attr, worker_thread, - &worker_thread_free_ids[worker_thread_count])) { - ap_log_error(APLOG_MARK, APLOG_ALERT, errno, ap_server_conf, + if ((rc = pthread_create(&thread, &worker_thread_attr, worker_thread, + &worker_thread_free_ids[worker_thread_count]))) { +#ifdef PTHREAD_SETS_ERRNO + rc = errno; +#endif + ap_log_error(APLOG_MARK, APLOG_ALERT, rc, ap_server_conf, "pthread_create: unable to create worker thread"); /* In case system resources are maxxed out, we don't want Apache running away with the CPU trying to fork over and @@ -694,8 +698,11 @@ static void child_main(int child_num_arg) ap_log_error(APLOG_MARK, APLOG_ALERT, errno, ap_server_conf, "sigprocmask"); } #else - if (pthread_sigmask(SIG_SETMASK, &sig_mask, NULL) != 0) { - ap_log_error(APLOG_MARK, APLOG_ALERT, errno, ap_server_conf, + if ((rv = pthread_sigmask(SIG_SETMASK, &sig_mask, NULL)) != 0) { +#ifdef PTHREAD_SETS_ERRNO + rv = errno; +#endif + ap_log_error(APLOG_MARK, APLOG_ALERT, rv, ap_server_conf, "pthread_sigmask"); } #endif diff --git a/server/mpm/experimental/perchild/perchild.c b/server/mpm/experimental/perchild/perchild.c index 0a0051d45b..bca25653fa 100644 --- a/server/mpm/experimental/perchild/perchild.c +++ b/server/mpm/experimental/perchild/perchild.c @@ -467,12 +467,16 @@ static void *worker_thread(void *); static int start_thread(void) { pthread_t thread; + int rc; pthread_mutex_lock(&worker_thread_count_mutex); if (worker_thread_count < max_threads) { - if (pthread_create(&thread, &worker_thread_attr, worker_thread, - &worker_thread_free_ids[worker_thread_count])) { - ap_log_error(APLOG_MARK, APLOG_ALERT, errno, ap_server_conf, + if ((rc = pthread_create(&thread, &worker_thread_attr, worker_thread, + &worker_thread_free_ids[worker_thread_count]))) { +#ifdef PTHREAD_SETS_ERRNO + rc = errno; +#endif + ap_log_error(APLOG_MARK, APLOG_ALERT, rc, ap_server_conf, "pthread_create: unable to create worker thread"); /* In case system resources are maxxed out, we don't want Apache running away with the CPU trying to fork over and @@ -858,8 +862,11 @@ static void child_main(int child_num_arg) ap_log_error(APLOG_MARK, APLOG_ALERT, errno, ap_server_conf, "sigprocmask"); } #else - if (pthread_sigmask(SIG_SETMASK, &sig_mask, NULL) != 0) { - ap_log_error(APLOG_MARK, APLOG_ALERT, errno, ap_server_conf, + if ((rv = pthread_sigmask(SIG_SETMASK, &sig_mask, NULL)) != 0) { +#ifdef PTHREAD_SETS_ERRNO + rv = errno; +#endif + ap_log_error(APLOG_MARK, APLOG_ALERT, rv, ap_server_conf, "pthread_sigmask"); } #endif diff --git a/server/mpm/mpmt_pthread/mpmt_pthread.c b/server/mpm/mpmt_pthread/mpmt_pthread.c index 7142bc7b54..3aec08e7c6 100644 --- a/server/mpm/mpmt_pthread/mpmt_pthread.c +++ b/server/mpm/mpmt_pthread/mpmt_pthread.c @@ -638,8 +638,11 @@ static void child_main(int child_num_arg) ap_log_error(APLOG_MARK, APLOG_ALERT, errno, ap_server_conf, "sigprocmask"); } #else - if (pthread_sigmask(SIG_SETMASK, &sig_mask, NULL) != 0) { - ap_log_error(APLOG_MARK, APLOG_ALERT, errno, ap_server_conf, "pthread_sigmask"); + if ((rv = pthread_sigmask(SIG_SETMASK, &sig_mask, NULL)) != 0) { +#ifdef PTHREAD_SETS_ERRNO + rv = errno; +#endif + ap_log_error(APLOG_MARK, APLOG_ALERT, rv, ap_server_conf, "pthread_sigmask"); } #endif @@ -686,8 +689,11 @@ static void child_main(int child_num_arg) (void) ap_update_child_status(my_child_num, i, SERVER_STARTING, (request_rec *) NULL); #ifndef NO_THREADS - if (pthread_create(&thread, &thread_attr, worker_thread, my_info)) { - ap_log_error(APLOG_MARK, APLOG_ALERT, errno, ap_server_conf, + if ((rv = pthread_create(&thread, &thread_attr, worker_thread, my_info))) { +#ifdef PTHREAD_SETS_ERRNO + rv = errno; +#endif + ap_log_error(APLOG_MARK, APLOG_ALERT, rv, ap_server_conf, "pthread_create: unable to create worker thread"); /* In case system resources are maxxed out, we don't want Apache running away with the CPU trying to fork over and diff --git a/server/mpm/perchild/perchild.c b/server/mpm/perchild/perchild.c index 0a0051d45b..bca25653fa 100644 --- a/server/mpm/perchild/perchild.c +++ b/server/mpm/perchild/perchild.c @@ -467,12 +467,16 @@ static void *worker_thread(void *); static int start_thread(void) { pthread_t thread; + int rc; pthread_mutex_lock(&worker_thread_count_mutex); if (worker_thread_count < max_threads) { - if (pthread_create(&thread, &worker_thread_attr, worker_thread, - &worker_thread_free_ids[worker_thread_count])) { - ap_log_error(APLOG_MARK, APLOG_ALERT, errno, ap_server_conf, + if ((rc = pthread_create(&thread, &worker_thread_attr, worker_thread, + &worker_thread_free_ids[worker_thread_count]))) { +#ifdef PTHREAD_SETS_ERRNO + rc = errno; +#endif + ap_log_error(APLOG_MARK, APLOG_ALERT, rc, ap_server_conf, "pthread_create: unable to create worker thread"); /* In case system resources are maxxed out, we don't want Apache running away with the CPU trying to fork over and @@ -858,8 +862,11 @@ static void child_main(int child_num_arg) ap_log_error(APLOG_MARK, APLOG_ALERT, errno, ap_server_conf, "sigprocmask"); } #else - if (pthread_sigmask(SIG_SETMASK, &sig_mask, NULL) != 0) { - ap_log_error(APLOG_MARK, APLOG_ALERT, errno, ap_server_conf, + if ((rv = pthread_sigmask(SIG_SETMASK, &sig_mask, NULL)) != 0) { +#ifdef PTHREAD_SETS_ERRNO + rv = errno; +#endif + ap_log_error(APLOG_MARK, APLOG_ALERT, rv, ap_server_conf, "pthread_sigmask"); } #endif