Bug 1479320 - wait fails on pid of co-process in interactive mode
Summary: wait fails on pid of co-process in interactive mode
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: mksh
Version: 26
Hardware: x86_64
OS: Linux
unspecified
unspecified
Target Milestone: ---
Assignee: Michal Hlavinka
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2017-08-08 11:11 UTC by Michal Hlavinka
Modified: 2018-02-18 16:04 UTC (History)
3 users (show)

Fixed In Version: mksh-56-1.fc26
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2018-02-18 16:04:20 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)

Description Michal Hlavinka 2017-08-08 11:11:25 UTC
Description of problem:

Performing a wait on the pid of a co-process fails in the following circumstance:
    #!/bin/mksh

    ls -l |&
    pid=$!

    tee -a /tmp/out <&p

    wait $pid
    print $?

The wait's return value is always 127.  It does not matter whether the co-process exits with a successful value (e.g., "ls -l") or an unsuccessful value (e.g., "ls -l does-not-exist"); 127 is always returned.

POSIX documentation on wait(1) (http://pubs.opengroup.org/onlinepubs/009695399/utilities/wait.html) states "If one or more pid operands are specified that represent unknown process IDs, wait shall treat them as if they were known process IDs that exited with exit status 127" and later on (in "Exit Status") indicates that 127 is returned only if "[t]he command identified by the last pid operand specified is unknown."

---------------

Version-Release number of selected component (if applicable):
mksh-55-1.fc26

How reproducible:
Always

Steps to Reproduce:
Run sample code above using mksh -i
  
Actual results:
Return value of wait is always 127.

Expected results:
wait returns status of specified command



This bug can't be reproduced when /etc/mksh OR ~/.mkshrc is missing, as the code setting PS1 from those files is required to trigger this bug. This seems to be minimized PS1 value to trigger the bug if you don't have mkshrc on your system:

PS1='${|\\builtin typeset e=$?; \\builtin return $e; } '"\$ "

Comment 1 Thorsten Glaser 2017-08-08 14:34:17 UTC
Thanks. The problem here was, apparently — I hope I’m right — that an interactive shell (still) did not remember (some) asynchronous PIDs. I’m not quite sure why this worked for simple async lists (“&”) in interactive mode, but the job reporting (the thing printing the “[1] + Done” messages) cleaned them up.

I’ve committed a tentative fix which will be in R56:

Index: src/bin/mksh/jobs.c
diff -up src/bin/mksh/jobs.c:1.123 src/bin/mksh/jobs.c:1.124
--- src/bin/mksh/jobs.c:1.123	Tue Aug  8 14:29:23 2017
+++ src/bin/mksh/jobs.c	Tue Aug  8 14:30:10 2017
@@ -1022,8 +1022,14 @@ j_notify(void)
 	}
 	for (j = job_list; j; j = tmp) {
 		tmp = j->next;
-		if (j->flags & JF_REMOVE)
-			remove_job(j, "notify");
+		if (j->flags & JF_REMOVE) {
+			if (j == async_job || (j->flags & JF_KNOWN)) {
+				j->flags = (j->flags & ~JF_REMOVE) | JF_ZOMBIE;
+				j->job = -1;
+				nzombie++;
+			} else
+				remove_job(j, "notify");
+		}
 	}
 	shf_flush(shl_out);
 #ifndef MKSH_NOPROSPECTOFWORK

Comment 2 Michal Hlavinka 2017-08-09 08:50:10 UTC
Thanks. I've checked the patch and it fixes the problem. No regression noted.

Comment 3 Thorsten Glaser 2017-08-09 10:57:59 UTC
Thanks for confirming!

Comment 4 Fedora Update System 2017-08-12 01:28:15 UTC
mksh-56-1.fc25 has been pushed to the Fedora 25 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2017-e2168704bd

Comment 5 Fedora Update System 2017-08-13 04:04:26 UTC
mksh-56-1.fc26 has been pushed to the Fedora 26 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2017-5c09977559

Comment 6 Fedora Update System 2017-08-31 14:53:28 UTC
mksh-56-1.fc26 has been pushed to the Fedora 26 stable repository. If problems still persist, please make note of it in this bug report.

Comment 7 Fedora Update System 2017-08-31 20:50:38 UTC
mksh-56-1.fc25 has been pushed to the Fedora 25 stable repository. If problems still persist, please make note of it in this bug report.


Note You need to log in before you can comment on or make changes to this bug.