>From the reference. Lets examine that step by step.
|( ( ( ( someprog; #part6 echo $? >&3 #part5 ) | filter >&4 #part4 ) 3>&1 #part3 ) | stdintoexitstatus #part2 ) 4>&1 #part1| >From bottom up: 1. A subshell is created with file descriptor 4 redirected to stdout. This means that whatever is printed to file descriptor 4 in the subshell will end up as the stdout of the entire construct. 2. A pipe is created and the commands on the left (|#part3|) and right (|stdintoexitstatus|) are executed. |stdintoexitstatus| is also the last command of the pipe and that means the exit status of |stdintoexitstatus| will be the exit status of the entire construct. 3. A subshell is created with file descriptor 3 redirected to stdout. This means that whatever is printed to file descriptor 3 in this subshell will end up in |stdintoexitstatus| and in turn will be the exit status of the entire construct. 4. A pipe is created and the commands on the left (|#part5| and |#part6|) and right (|filter >&4|) are executed. The output of |filter| is redirected to file descriptor 4. In |#part1| the file descriptor 4 was redirected to stdout. This means that the output of |filter| is the stdout of the entire construct. 5. Exit status from |#part6| is printed to file descriptor 3. In |#part3| file descriptor 3 was redirected to|stdintoexitstatus|. This means that the exit status from |#part6| will be the final exit status for the entire construct. 6. |someprog| is executed. The exit status is taken in |#part5|. The stdout is taken by the pipe in|#part4| and forwarded to |filter|. The output from |filter| will in turn reach stdout as explained in|#part4| On 10/01/2013 03:34 PM, Paul Ingram wrote: > Why the redirect from descriptor 4? > > :: psi > > On Oct 1, 2013, at 3:13 PM, Duffie Cooley <dcoo...@nicira.com> wrote: > >> What about this? >> >> referenced from here. >> >> http://unix.stackexchange.com/questions/14270/get-exit-status-of-process-thats-piped-to-another/70675#70675 >> >> diff --git a/utilities/ovs-lib.in b/utilities/ovs-lib.in >> index 1684ddc..5286e12 100644 >> --- a/utilities/ovs-lib.in >> +++ b/utilities/ovs-lib.in >> @@ -41,6 +41,11 @@ ovs_ctl_log () { >> echo "$@" >> "${logdir}/ovs-ctl.log" >> } >> >> +stdintoexitstatus () { >> + read exitstatus >> + return $exitstatus >> +} >> + >> ovs_ctl () { >> case "$@" in >> *"=strace"*) >> @@ -51,7 +56,7 @@ ovs_ctl () { >> ;; >> *) >> echo "`date -u`:$@" >> "${logdir}/ovs-ctl.log" >> - "${datadir}/scripts/ovs-ctl" "$@" 2>&1 | tee -a >> "${logdir}/ovs-ctl.log" >> + (((("${datadir}/scripts/ovs-ctl" "$@" 2>&1 ; echo $? > &3) >> | tee -a "${logdir}/ovs-ctl.log" ) 3>&1) | stdintoexitstatus) 4>&1 >> ;; >> esac >> } >> >> >> Thanks, >> >> Duffie >> >> >> On 10/01/2013 11:48 AM, Gurucharan Shetty wrote: >>> This patch works for me, but it is a little hacky. >>> >>> diff --git a/utilities/ovs-lib.in b/utilities/ovs-lib.in >>> index 1684ddc..b0cdaf2 100644 >>> --- a/utilities/ovs-lib.in >>> +++ b/utilities/ovs-lib.in >>> @@ -51,7 +51,13 @@ ovs_ctl () { >>> ;; >>> *) >>> echo "`date -u`:$@" >> "${logdir}/ovs-ctl.log" >>> - "${datadir}/scripts/ovs-ctl" "$@" 2>&1 | tee -a >>> "${logdir}/ovs-ctl.log" >>> + unique=`(uuidgen) 2>/dev/null` || unique=`date +"%Y %b %d %T"` >>> + mkfifo "/tmp/${unique}" >>> + tee -a "${logdir}/ovs-ctl.log" < "/tmp/${unique}" & >>> + "${datadir}/scripts/ovs-ctl" "$@" > "/tmp/${unique}" 2>&1 >>> + rc=$? >>> + rm "/tmp/${unique}" >>> + return $rc >>> ;; >>> esac >>> } >>> >>> On Tue, Oct 1, 2013 at 10:11 AM, Gurucharan Shetty <shet...@nicira.com> >>> wrote: >>>> On Mon, Sep 30, 2013 at 7:27 PM, Duffie Cooley <dcoo...@nicira.com> wrote: >>>>> From: Duffie Cooley <dcoo...@nicira.com> >>>>> This is a fix for a request to make sure that the openvswitch status >>>>> command >>>>> in rhel based distros gives a useful exit status. That was fixed in >>>>> >>>>> commit 5e0c05bc058c78a11be6747f62e6ad88e5d06b70 >>>>> debian: Fix exit status of openvswitch-switch init script "status" command >>>>> >>>>> >>>>> >>>>> Signed-off-by: Duffie Cooley <dcoo...@nicira.com> >>>>> --- >>>>> rhel/etc_init.d_openvswitch | 3 ++- >>>>> 1 file changed, 2 insertions(+), 1 deletion(-) >>>>> >>>>> diff --git a/rhel/etc_init.d_openvswitch b/rhel/etc_init.d_openvswitch >>>>> index 7e64132..6a53cef 100755 >>>>> --- a/rhel/etc_init.d_openvswitch >>>>> +++ b/rhel/etc_init.d_openvswitch >>>>> @@ -5,7 +5,7 @@ >>>>> # chkconfig: 2345 09 91 >>>>> # description: Manage Open vSwitch kernel modules and user-space daemons >>>>> >>>>> -# Copyright (C) 2009, 2010, 2011 Nicira, Inc. >>>>> +# Copyright (C) 2009, 2010, 2011, 2013 Nicira, Inc. >>>>> # >>>>> # Licensed under the Apache License, Version 2.0 (the "License"); >>>>> # you may not use this file except in compliance with the License. >>>>> @@ -81,6 +81,7 @@ case $1 in >>>>> ;; >>>>> status) >>>>> ovs_ctl status >>>>> + exit $? >>>>> ;; >>>>> version) >>>>> ovs_ctl version >>>>> -- >>>>> 1.8.1.2 >>>>> >>>> I don't think this helps. The exit status is always 0. I broke this >>>> with my implementation of 'ovs_ctl' in ovs-lib tee'ing the o/p to >>>> ovs-ctl.log. tee will return an exit status of success even though the >>>> previous command returned an exit status of 1. >>>> >>>> I can use the PIPESTATUS variable. But I don't think it is POSIX >>>> compliant. Any other ideas? >>>> >> _______________________________________________ >> dev mailing list >> dev@openvswitch.org >> http://openvswitch.org/mailman/listinfo/dev
_______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev