]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Don't refer to errno when the pthread library fails
authorMIZUTA Takeshi <mizuta.takeshi@fujitsu.com>
Thu, 3 Mar 2022 06:28:56 +0000 (15:28 +0900)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Fri, 25 Mar 2022 17:41:47 +0000 (11:41 -0600)
When the pthread library fails, errno is referenced even though errno is not set.

Fix to refer to the return code of the pthread library instead of errno.

src/lib/io/schedule.c
src/modules/rlm_cache/drivers/rlm_cache_rbtree/rlm_cache_rbtree.c
src/modules/rlm_sql/drivers/rlm_sql_cassandra/rlm_sql_cassandra.c

index 8a938c00174d57afac4fd24867fb7579683d7a6c..47543c2e66352833da65bf14c3b14dcaf3b43195 100644 (file)
@@ -704,6 +704,7 @@ int fr_schedule_destroy(fr_schedule_t **sc_to_free)
        unsigned int            i;
        fr_schedule_worker_t    *sw;
        fr_schedule_network_t   *sn;
+       int                     ret;
 
        if (!sc) return 0;
 
@@ -756,8 +757,8 @@ int fr_schedule_destroy(fr_schedule_t **sc_to_free)
                 *      exited before the main thread cleans up the
                 *      module instances.
                 */
-               if (pthread_join(sn->pthread_id, NULL) != 0) {
-                       ERROR("Failed joining network %i: %s", sn->id, fr_syserror(errno));
+               if ((ret = pthread_join(sn->pthread_id, NULL)) != 0) {
+                       ERROR("Failed joining network %i: %s", sn->id, fr_syserror(ret));
                } else {
                        DEBUG2("Network %i joined (cleaned up)", sn->id);
                }
@@ -790,8 +791,8 @@ int fr_schedule_destroy(fr_schedule_t **sc_to_free)
                 *      exited before the main thread cleans up the
                 *      module instances.
                 */
-               if (pthread_join(sw->pthread_id, NULL) != 0) {
-                       ERROR("Failed joining worker %i: %s", sw->id, fr_syserror(errno));
+               if ((ret = pthread_join(sw->pthread_id, NULL)) != 0) {
+                       ERROR("Failed joining worker %i: %s", sw->id, fr_syserror(ret));
                } else {
                        DEBUG2("Worker %i joined (cleaned up)", sw->id);
                }
index 4701ecd019d5e7b64ec0b1b4f0a9f6f81d916f67..c464d6f8c7496699cb20023549e59cb93788901d 100644 (file)
@@ -97,6 +97,7 @@ static int mod_detach(module_detach_ctx_t const *mctx)
 static int mod_instantiate(module_inst_ctx_t const *mctx)
 {
        rlm_cache_rbtree_t *driver = talloc_get_type_abort(mctx->inst->data, rlm_cache_rbtree_t);
+       int ret;
 
        /*
         *      The cache.
@@ -116,8 +117,8 @@ static int mod_instantiate(module_inst_ctx_t const *mctx)
                return -1;
        }
 
-       if (pthread_mutex_init(&driver->mutex, NULL) < 0) {
-               ERROR("Failed initializing mutex: %s", fr_syserror(errno));
+       if ((ret = pthread_mutex_init(&driver->mutex, NULL)) < 0) {
+               ERROR("Failed initializing mutex: %s", fr_syserror(ret));
                return -1;
        }
 
index 94571a05561f39b0eb61e88a9dbd0772e5ccd749..c689b4724b512cf11c9f362fa122ec47347edca7 100644 (file)
@@ -728,6 +728,7 @@ static int mod_instantiate(module_inst_ctx_t const *mctx)
        bool                    do_tls = false;
        bool                    do_latency_aware_routing = false;
        CassCluster             *cluster;
+       int                     ret;
 
 #define DO_CASS_OPTION(_opt, _x) \
 do {\
@@ -738,8 +739,8 @@ do {\
        }\
 } while (0)
 
-       if (pthread_mutex_init(&inst->connect_mutex, NULL) < 0) {
-               ERROR("Failed initializing mutex: %s", fr_syserror(errno));
+       if ((ret = pthread_mutex_init(&inst->connect_mutex, NULL)) < 0) {
+               ERROR("Failed initializing mutex: %s", fr_syserror(ret));
                TALLOC_FREE(inst);
                return -1;
        }