Discussion:
[ast-developers] last command in pipeline fails with "Exec format error"
lijo george
2015-11-12 22:34:58 UTC
Permalink
I've observed that the last command in a pipeline causes a "Exec format"
error
for the ksh93u+ and earlier versions in a Solaris environment.

Here's a reproducible test case.

***@S11.2_FCS:~# echo
${.sh.version}

Version AJM 93u+ 2012-08-01

***@S11.2_FCS:~# echo "abcdefg" | grep abc >
`hostname`_test

grep: grep: cannot execute [Exec format error]


This issue is not present in the 93v- version as given below.

***@S11.2_FCS:~# echo ${.sh.version}
Version AIJMP 93v- 2013-10-08

***@S11.2_FCS:~# echo "abcdefg" | grep abc > `hostname`_test
***@S11.2_FCS:~# cat S11.2_FCS_test
abcdefg
***@S11.2_FCS:~#

I searched around and found some references to the same issues, but couldn't
find any fixes/patches mentioned.

http://lists.research.att.com/pipermail/ast-developers/2008q4/000347.html
https://access.redhat.com/solutions/23995
https://discussions.apple.com/thread/2544796?tstart=0
https://www.mail-archive.com/ast-***@lists.research.att.com/msg00890.html

The issue seems to be happening because the posix_spawn() for "grep" fails
because one of the "posix_spawn_attributes" is invalid, most probably
because it sets a invalid process group id( the first command in the
pipeline which has already exited) . This causes posix_spawn() to return
EPERM causing ksh to interpret it as a script causing the "Exec format"
error.

I tried to look into the "93v-" source code changes, but I'm not able to
isolate a patch/fix from that. I see that the spawnveg method has been
replaced with spawnvex and some other changes which look relevant.

If someone has a patch for the earlier versions, please let me know.

Thanks,
Lijo

Loading...