From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id 37cf1c48 for ; Wed, 16 Oct 2019 16:27:02 +0000 (UTC) Received: (qmail 1599 invoked by alias); 16 Oct 2019 16:26:53 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 44841 Received: (qmail 2309 invoked by uid 1010); 16 Oct 2019 16:26:53 -0000 X-Qmail-Scanner-Diagnostics: from forward400o.mail.yandex.net by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.102.0/25601. spamassassin: 3.4.2. Clear:RC:0(37.140.190.176):SA:0(-2.7/5.0):. Processed in 3.279786 secs); 16 Oct 2019 16:26:53 -0000 X-Envelope-From: ruro.ruro@ya.ru X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _spf-ipv4.yandex.ru designates 37.140.190.176 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ya.ru; s=mail; t=1571243166; bh=CpQsWvoOhnwMx9MNPp0BZDKTInb6k556DaiVBqu+5Wk=; h=Message-Id:Date:Subject:To:From; b=ZYtDu+S+i8rJZT6BLKfmj01SZQrbV7e+TNyNI+ADt060x2G1cBYfl7hM11jOHtXIO pQxWu3EDNFMuWKwllpN7JVU/nXyV7If9cMHDuD2Fg4Si7F5GHOfngXLnr209pjfvHu TCxN1719hqb/UZ7EJquLKgM2poJnzGxfpYHF1pBc= Authentication-Results: mxback7q.mail.yandex.net; dkim=pass header.i=@ya.ru From: =?utf-8?B?X1J1Um9fICjQkNC90LTRgNC10Lkg0KHRgtC+0YbQutC40Lkp?= Envelope-From: ruro-ruro@yandex.ru To: zsh-workers Subject: [PATCH] POSIX compliant nice error checking MIME-Version: 1.0 X-Mailer: Yamail [ http://yandex.ru ] 5.0 Date: Wed, 16 Oct 2019 19:26:06 +0300 Message-Id: <5360011571243166@vla1-d97dbca235a9.qloud-c.yandex.net> Content-Transfer-Encoding: 7bit Content-Type: text/plain In `Src/exec.c`, the return value of nice(5) is checked, however according to POSIX (http://man7.org/linux/man-pages/man2/nice.2.html), one should check errno instead, since nice can return negative values even on success. Since nice(5) increments the niceness by 5, the return value can be negative, if the original niceness was less than -5. For example, with nice -6, you'll get the annoying `zsh: nice(5) failed: success` error message: ``` > sudo renice -6 $$ 17187 (process ID) old priority 0, new priority -6 > cat & [1] 6200 zsh: nice(5) failed: success [1] + 6200 suspended (tty input) cat > kill %1 [1] + 6200 terminated cat ``` With nice -5 this doesn't happen: ``` > sudo renice -5 $$ 17187 (process ID) old priority -6, new priority -5 > cat & [1] 7559 [1] + 7559 suspended (tty input) cat > kill %1 [1] + 7559 terminated cat ``` Checking errno instead of the return value fixes this. --- Src/exec.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Src/exec.c b/Src/exec.c index 042ba065a..08411ce28 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -2762,9 +2762,12 @@ execcmd_fork(Estate state, int how, int type, Wordcode varspc, sigtrapped[SIGEXIT] = 0; #ifdef HAVE_NICE /* Check if we should run background jobs at a lower priority. */ - if ((how & Z_ASYNC) && isset(BGNICE)) - if (nice(5) < 0) + if ((how & Z_ASYNC) && isset(BGNICE)) { + errno = 0; + nice(5); + if (errno) zwarn("nice(5) failed: %e", errno); + } #endif /* HAVE_NICE */ return 0; -- 2.23.0