All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>, "Jeff King" <peff@peff.net>,
	"Ben Peart" <peartben@gmail.com>,
	"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 10/10] Clean up pthread_create() error handling
Date: Sat, 27 Oct 2018 09:10:03 +0200	[thread overview]
Message-ID: <20181027071003.1347-11-pclouds@gmail.com> (raw)
In-Reply-To: <20181027071003.1347-1-pclouds@gmail.com>

Normally pthread_create() rarely fails and sometimes error handling
can be neglected. But with new pthreads wrapper, pthread_create() will
return ENOSYS on a system without thread support.

Threaded code _is_ protected by HAVE_THREADS and pthread_create()
should never run in the first place. But the situation could change in
the future and bugs may sneak in. Make sure that all pthread_create()
checks and handles the result.

While at there, mark these strings for translation if they aren't.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 name-hash.c     | 16 ++++++++++------
 preload-index.c |  8 ++++++--
 run-command.c   |  2 +-
 3 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/name-hash.c b/name-hash.c
index b3c9ac791d..623ca6923a 100644
--- a/name-hash.c
+++ b/name-hash.c
@@ -494,6 +494,7 @@ static inline void lazy_update_dir_ref_counts(
 static void threaded_lazy_init_name_hash(
 	struct index_state *istate)
 {
+	int err;
 	int nr_each;
 	int k_start;
 	int t;
@@ -526,8 +527,9 @@ static void threaded_lazy_init_name_hash(
 		if (k_start > istate->cache_nr)
 			k_start = istate->cache_nr;
 		td_dir_t->k_end = k_start;
-		if (pthread_create(&td_dir_t->pthread, NULL, lazy_dir_thread_proc, td_dir_t))
-			die("unable to create lazy_dir_thread");
+		err = pthread_create(&td_dir_t->pthread, NULL, lazy_dir_thread_proc, td_dir_t);
+		if (err)
+			die(_("unable to create lazy_dir thread: %s"), strerror(err));
 	}
 	for (t = 0; t < lazy_nr_dir_threads; t++) {
 		struct lazy_dir_thread_data *td_dir_t = td_dir + t;
@@ -547,13 +549,15 @@ static void threaded_lazy_init_name_hash(
 	 */
 	td_name->istate = istate;
 	td_name->lazy_entries = lazy_entries;
-	if (pthread_create(&td_name->pthread, NULL, lazy_name_thread_proc, td_name))
-		die("unable to create lazy_name_thread");
+	err = pthread_create(&td_name->pthread, NULL, lazy_name_thread_proc, td_name);
+	if (err)
+		die(_("unable to create lazy_name thread: %s"), strerror(err));
 
 	lazy_update_dir_ref_counts(istate, lazy_entries);
 
-	if (pthread_join(td_name->pthread, NULL))
-		die("unable to join lazy_name_thread");
+	err = pthread_join(td_name->pthread, NULL);
+	if (err)
+		die(_("unable to join lazy_name thread: %s"), strerror(err));
 
 	cleanup_dir_mutex();
 
diff --git a/preload-index.c b/preload-index.c
index 0e24886aca..ddca1c216e 100644
--- a/preload-index.c
+++ b/preload-index.c
@@ -121,6 +121,8 @@ static void preload_index(struct index_state *index,
 
 	for (i = 0; i < threads; i++) {
 		struct thread_data *p = data+i;
+		int err;
+
 		p->index = index;
 		if (pathspec)
 			copy_pathspec(&p->pathspec, pathspec);
@@ -129,8 +131,10 @@ static void preload_index(struct index_state *index,
 		if (pd.progress)
 			p->progress = &pd;
 		offset += work;
-		if (pthread_create(&p->pthread, NULL, preload_thread, p))
-			die("unable to create threaded lstat");
+		err = pthread_create(&p->pthread, NULL, preload_thread, p);
+
+		if (err)
+			die(_("unable to create threaded lstat: %s"), strerror(err));
 	}
 	for (i = 0; i < threads; i++) {
 		struct thread_data *p = data+i;
diff --git a/run-command.c b/run-command.c
index 84b883c213..26154ba257 100644
--- a/run-command.c
+++ b/run-command.c
@@ -1213,7 +1213,7 @@ int start_async(struct async *async)
 	{
 		int err = pthread_create(&async->tid, NULL, run_thread, async);
 		if (err) {
-			error_errno("cannot create thread");
+			error(_("cannot create async thread: %s"), strerror(err));
 			goto error;
 		}
 	}
-- 
2.19.1.647.g708186aaf9


  parent reply	other threads:[~2018-10-27  7:10 UTC|newest]

Thread overview: 66+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-27  7:09 [PATCH 00/10] Reduce #ifdef NO_PTHREADS Nguyễn Thái Ngọc Duy
2018-10-27  7:09 ` [PATCH 01/10] thread-utils: macros to unconditionally compile pthreads API Nguyễn Thái Ngọc Duy
2018-10-27  7:31   ` Jeff King
2018-10-27  7:40     ` Duy Nguyen
2018-10-27  8:15       ` Jeff King
2018-10-27 14:43         ` Duy Nguyen
2018-10-27  7:09 ` [PATCH 02/10] index-pack: remove #ifdef NO_PTHREADS Nguyễn Thái Ngọc Duy
2018-10-27  7:34   ` Jeff King
2018-10-27  7:09 ` [PATCH 03/10] name-hash.c: " Nguyễn Thái Ngọc Duy
2018-10-27  7:09 ` [PATCH 04/10] attr.c: " Nguyễn Thái Ngọc Duy
2018-10-27  7:09 ` [PATCH 05/10] send-pack.c: " Nguyễn Thái Ngọc Duy
2018-10-27  7:39   ` Jeff King
2018-10-27  7:09 ` [PATCH 06/10] grep: " Nguyễn Thái Ngọc Duy
2018-10-27  7:44   ` Jeff King
2018-10-29  2:16     ` Junio C Hamano
2018-10-29 14:25       ` Jeff King
2018-10-29 16:01         ` Duy Nguyen
2018-10-29 16:20           ` Jeff King
2018-10-30  1:27             ` Junio C Hamano
2018-10-27  7:10 ` [PATCH 07/10] preload-index.c: " Nguyễn Thái Ngọc Duy
2018-10-29 16:52   ` Ben Peart
2018-10-27  7:10 ` [PATCH 08/10] pack-objects: " Nguyễn Thái Ngọc Duy
2018-10-27  7:10 ` [PATCH 09/10] read-cache.c: " Nguyễn Thái Ngọc Duy
2018-10-29 17:05   ` Ben Peart
2018-10-29 17:21     ` Duy Nguyen
2018-10-29 17:58       ` Ben Peart
2018-10-30  1:44       ` Junio C Hamano
2018-10-27  7:10 ` Nguyễn Thái Ngọc Duy [this message]
2018-10-27  7:24 ` [PATCH 00/10] Reduce " Jeff King
2018-10-27  8:13 ` Jeff King
2018-10-27 17:07   ` Duy Nguyen
2018-10-27 17:29 ` [PATCH v2 " Nguyễn Thái Ngọc Duy
2018-10-27 17:29   ` [PATCH v2 01/10] thread-utils: macros to unconditionally compile pthreads API Nguyễn Thái Ngọc Duy
2018-10-27 17:30   ` [PATCH v2 02/10] index-pack: remove #ifdef NO_PTHREADS Nguyễn Thái Ngọc Duy
2018-10-27 17:30   ` [PATCH v2 03/10] name-hash.c: " Nguyễn Thái Ngọc Duy
2018-10-27 17:30   ` [PATCH v2 04/10] attr.c: " Nguyễn Thái Ngọc Duy
2018-10-27 17:30   ` [PATCH v2 05/10] grep: " Nguyễn Thái Ngọc Duy
2018-10-27 17:30   ` [PATCH v2 06/10] preload-index.c: " Nguyễn Thái Ngọc Duy
2018-10-29 17:21     ` Ben Peart
2018-10-29 17:26       ` Duy Nguyen
2018-10-29 18:05         ` Ben Peart
2018-10-29 20:11           ` Jeff King
2018-10-27 17:30   ` [PATCH v2 07/10] pack-objects: " Nguyễn Thái Ngọc Duy
2018-10-27 17:30   ` [PATCH v2 08/10] read-cache.c: " Nguyễn Thái Ngọc Duy
2018-10-29 14:30     ` Jeff King
2018-10-29 17:07       ` Ben Peart
2018-10-29 17:23       ` Ben Peart
2018-10-27 17:30   ` [PATCH v2 09/10] Clean up pthread_create() error handling Nguyễn Thái Ngọc Duy
2018-10-27 17:30   ` [PATCH v2 10/10] read-cache.c: initialize copy_len to shut up gcc 8 Nguyễn Thái Ngọc Duy
2018-10-29 14:31     ` Jeff King
2018-11-03  8:48   ` [PATCH v3 00/14] Reduce #ifdef NO_PTHREADS Nguyễn Thái Ngọc Duy
2018-11-03  8:48     ` [PATCH v3 01/14] thread-utils: macros to unconditionally compile pthreads API Nguyễn Thái Ngọc Duy
2018-11-03  8:48     ` [PATCH v3 02/14] run-command.h: include thread-utils.h instead of pthread.h Nguyễn Thái Ngọc Duy
2018-11-03  8:48     ` [PATCH v3 03/14] send-pack.c: move async's #ifdef NO_PTHREADS back to run-command.c Nguyễn Thái Ngọc Duy
2018-11-03  8:48     ` [PATCH v3 04/14] index-pack: remove #ifdef NO_PTHREADS Nguyễn Thái Ngọc Duy
2018-11-03  8:48     ` [PATCH v3 05/14] name-hash.c: " Nguyễn Thái Ngọc Duy
2018-11-03  8:48     ` [PATCH v3 06/14] attr.c: " Nguyễn Thái Ngọc Duy
2018-11-03  8:48     ` [PATCH v3 07/14] grep: " Nguyễn Thái Ngọc Duy
2018-11-03  8:48     ` [PATCH v3 08/14] grep: clean up num_threads handling Nguyễn Thái Ngọc Duy
2018-11-03  8:48     ` [PATCH v3 09/14] preload-index.c: remove #ifdef NO_PTHREADS Nguyễn Thái Ngọc Duy
2018-11-03  8:48     ` [PATCH v3 10/14] pack-objects: " Nguyễn Thái Ngọc Duy
2018-11-03  8:48     ` [PATCH v3 11/14] read-cache.c: " Nguyễn Thái Ngọc Duy
2018-11-03  8:48     ` [PATCH v3 12/14] read-cache.c: reduce branching based on HAVE_THREADS Nguyễn Thái Ngọc Duy
2018-11-03  8:48     ` [PATCH v3 13/14] read-cache.c: initialize copy_len to shut up gcc 8 Nguyễn Thái Ngọc Duy
2018-11-03  8:48     ` [PATCH v3 14/14] Clean up pthread_create() error handling Nguyễn Thái Ngọc Duy
2018-11-06  4:51     ` [PATCH v3 00/14] Reduce #ifdef NO_PTHREADS Junio C Hamano

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=20181027071003.1347-11-pclouds@gmail.com \
    --to=pclouds@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peartben@gmail.com \
    --cc=peff@peff.net \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.