Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[PATCH] POSIX compliant nice error checking
- X-seq: zsh-workers 44841
- From: _RuRo_ (Андрей Стоцкий) <ruro.ruro@xxxxx>
- To: zsh-workers <zsh-workers@xxxxxxx>
- Subject: [PATCH] POSIX compliant nice error checking
- Date: Wed, 16 Oct 2019 19:26:06 +0300
- Authentication-results: mxback7q.mail.yandex.net; dkim=pass header.i=@ya.ru
- 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=
- Envelope-from: ruro-ruro@xxxxxxxxx
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author