Skip to contentSkip to conversation

Don't exit() from library

PATCH In review Ritesh Raj Sarraf 2 participants 3 messages Mar 11, 2014 Device mapper

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Don't exit() from library

Also call pthread_attr_destroy() on thread creation failure

---
 libmpathpersist/mpath_persist.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
libmpathpersist/mpath_persist.c +7 -4
index bd30125..b74ce4e 100644
@@ -585,11 +585,14 @@ int send_prout_activepath(char * dev, int rq_servact, int rq_scope,
 	rc = pthread_create(&thread, &attr, mpath_prout_pthread_fn, (void *)(&param));
 	if (rc){
 		condlog (3, "%s: failed to create thread %d", dev, rc);
-		exit(-1);
+		/* Destroy the thread attribute since we failed to create */
+		pthread_attr_destroy(&attr);
+	}
+	else {
+		/* Free attribute and wait for the other threads */
+		pthread_attr_destroy(&attr);
+		rc = pthread_join(thread, NULL);
 	}
-	/* Free attribute and wait for the other threads */
-	pthread_attr_destroy(&attr);
-	rc = pthread_join(thread, NULL);
 
 	return (param.status);
 }
Signature · 1 line
1.9.0
#1 lore raw
Quoted 20 lines · Ritesh Raj Sarraf

Also call pthread_attr_destroy() on thread creation failure

---
 libmpathpersist/mpath_persist.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
libmpathpersist/mpath_persist.c +4 -1
index bd30125..b74ce4e 100644
@@ -585,11 +585,14 @@ int send_prout_activepath(char * dev, int rq_servact, int rq_scope,
 	rc = pthread_create(&thread, &attr, mpath_prout_pthread_fn, (void *)(&param));
 	if (rc){
 		condlog (3, "%s: failed to create thread %d", dev, rc);
-		exit(-1);
+		/* Destroy the thread attribute since we failed to create */
+		pthread_attr_destroy(&attr);
+	}
+	else {

libmpathpersist/mpath_persist.c int send_prout_activepath(char * dev, int rq_servact, int rq_scope, · line 598

Quoted 10 lines
libmpathpersist/mpath_persist.c +3 -3
+		/* Free attribute and wait for the other threads */
+		pthread_attr_destroy(&attr);
+		rc = pthread_join(thread, NULL);
 	}
-	/* Free attribute and wait for the other threads */
-	pthread_attr_destroy(&attr);
-	rc = pthread_join(thread, NULL);
 
 	return (param.status);
 }

Hello Ritesh,

Maybe there is something I'm not aware of, but is there any reason why the pthread_attr_destroy() call occurs twice in this patch instead of invoking it before the "if (rc) {" statement ? From the pthread_attr_destroy() man page: "Destroying a thread attributes object has no effect on threads that were created using that object".

Thanks,

Bart.

#2 lore raw
Quoted 7 lines · Bart Van Assche

Hello Ritesh,

Maybe there is something I'm not aware of, but is there any reason why the pthread_attr_destroy() call occurs twice in this patch instead of invoking it before the "if (rc) {" statement ? From the pthread_attr_destroy() man page: "Destroying a thread attributes object has no effect on threads that were created using that object".

Yup!! You're right. I won't have access to the dev box today. Can you please follow it up ?

Signature · 2 lines
Ritesh Raj Sarraf | http://people.debian.org/~rrs
Debian - The Universal Operating System