From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/13120 Path: news.gmane.org!.POSTED!not-for-mail From: Piotr Tworek Newsgroups: gmane.linux.lib.musl.general Subject: [PATCH] Don't return new thread ID from pthread_create. Date: Thu, 16 Aug 2018 01:09:33 +0200 Message-ID: <20180815230933.9962-1-tworaz@tworaz.net> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org X-Trace: blaine.gmane.org 1534374474 12913 195.159.176.226 (15 Aug 2018 23:07:54 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 15 Aug 2018 23:07:54 +0000 (UTC) Cc: Piotr Tworek To: musl@lists.openwall.com Original-X-From: musl-return-13136-gllmg-musl=m.gmane.org@lists.openwall.com Thu Aug 16 01:07:50 2018 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1fq4tJ-0003AK-9f for gllmg-musl@m.gmane.org; Thu, 16 Aug 2018 01:07:49 +0200 Original-Received: (qmail 13845 invoked by uid 550); 15 Aug 2018 23:09:51 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 13809 invoked from network); 15 Aug 2018 23:09:51 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=jVcmE04iOSRTFllR7rJnIFxohwJwGYXXGOc8L0JkOg4=; b=QCPKhDv4dFLYajCQk3tRZNAyJQGWYqCBjXt3ikTzQ9HDodoKiV5b5wTT/PY6I98+pJ t4JDt/WpN5FK9qfxJPuWKmJvp9fkdxloTUC3VJwfsfrJl+aexqWzlMB6LiNJVqmOx93C l0I59+vkp5KFHLI33WysxEPxAsa5/mMSbuC8Gr4S9iWKaUF5YvLGEo1fV1kjzQqV7nPW BKs5tbggCM1+qhDLu9XasXmnqvSI/muSmnlMkUcIKMwOZ0P01YmxUESpgoGdZCO+L61Q l4Bw2BEdsjYq0HpJiN5747ot/blPf3ih/NkANF48YLwCYQhPlaU7Z3SeKqEEEm5ervRn 0qEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=jVcmE04iOSRTFllR7rJnIFxohwJwGYXXGOc8L0JkOg4=; b=lA7HoJ5M/H9i8o2sxkldXQDsM5gFnVQr/5nFFXwqWFsbUQvkNVJIw4w/h57lalN1XR dMMRSHcEj/dbtCJSVeHXMTLrU3YicFQ31BxzjUQ7vvZuRxlApXIcHoa6FMr0txTvkVeD XL6cmHNsCgnAFjXv/wBmf6XhFNX1f+nbYRmxxc2cWjI6a0bl4VKcu9CXkBd+ZQALcfyi QN1T/Sol5Q36ztUCDAo2QirK9T1vfrK/OiGgbQ8M0EbAIGiX6QysKjNWET3dc6NRvQFR 26vTu/g5M0cCdt+d7mNax0TNryOZfLBLFf3uyU/yWeeuKzaO+I6WdcgS6rRw20QhE+Yl yzNg== X-Gm-Message-State: AOUpUlG76Tw3DJSH8ln02HGrfvye1uNo5OPyOCXmKPyuZWlgiUzHWSft KVEOUkoh6z8ghfS2bbqhrVm7NYZx X-Google-Smtp-Source: AA+uWPy/LDqlcOUVnOkkOxJnz6r0rUZxwcblmKhlj9cqOfyWvaFW93Rv4i1vshEGKgfg3W37iDgJcA== X-Received: by 2002:a19:6308:: with SMTP id x8-v6mr18671161lfb.104.1534374579403; Wed, 15 Aug 2018 16:09:39 -0700 (PDT) X-Google-Original-From: Piotr Tworek X-Mailer: git-send-email 2.16.4 Xref: news.gmane.org gmane.linux.lib.musl.general:13120 Archived-At: From: Piotr Tworek According to documentation pthread_create is supposed to return 0 on success or error code in case of failure. Unfortunately this is not always the case in musl. In case the application has called pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED), pthread_create will return new thread ID. To make matters worse such non zero value does not mean thread creation failed. Its quite the oposite. Thread was created succesfully and start routine passed to pthread_create will actually get invoked. To fix the problem simply drop the return statement from the last if statement in musl's pthread_create. The value currently being returned from there is a return code from __clone. Negative values indicating failure have already been handled by previous if statement and positive value indicates everything went correctly and pthread_create should return 0. --- src/thread/pthread_create.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/thread/pthread_create.c b/src/thread/pthread_create.c index 2df2e9f9..792cb42e 100644 --- a/src/thread/pthread_create.c +++ b/src/thread/pthread_create.c @@ -306,7 +306,6 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att if (do_sched) { __futexwait(&ssa.futex, -1, 1); - if (ret) return ret; } *res = new; -- 2.16.4