No subject


Sat Jul 20 05:24:39 UTC 2013


 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 <dcooley at 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 <shettyg at nicira.com> wrote:
>>>> On Mon, Sep 30, 2013 at 7:27 PM, Duffie Cooley <dcooley at nicira.com> wrote:
>>>>> From: Duffie Cooley <dcooley at 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 <dcooley at 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 at openvswitch.org
>> http://openvswitch.org/mailman/listinfo/dev


--------------070501010806010609000306
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">From the reference. <br>
      <br>
      <meta http-equiv="content-type" content="text/html;
        charset=ISO-8859-1">
      <p style="margin: 0px 0px 1em; padding: 0px; border: 0px;
        font-size: 15px; vertical-align: baseline; clear: both;
        word-wrap: break-word; color: rgb(51, 51, 51); font-family:
        'Helvetica Neue', Helvetica, Arial, sans-serif; font-style:
        normal; font-variant: normal; font-weight: normal;
        letter-spacing: normal; line-height: 20px; orphans: auto;
        text-align: left; text-indent: 0px; text-transform: none;
        white-space: normal; widows: auto; word-spacing: 0px;
        -webkit-text-stroke-width: 0px;">Lets examine that step by step.</p>
      <pre class="lang-sh prettyprint prettyprinted" style="margin: 0px 0px 10px; padding: 5px; border: 0px; font-size: 13px; vertical-align: baseline; overflow: auto; width: auto; max-height: 600px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; background-color: rgb(238, 238, 238); color: rgb(51, 51, 51); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 20px; orphans: auto; text-align: left; text-indent: 0px; text-transform: none; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><code style="margin: 0px; padding: 0px; border: 0px; font-size: 13px; vertical-align: baseline; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; color: rgb(34, 34, 34); background-color: rgb(238, 238, 238);"><span class=
 "pun" sty
le="margin: 0px; padding: 0px; border: 0px; font-size: 13px; vertical-align: baseline; color: black;">(</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-size: 13px; vertical-align: baseline; color: black;"> </span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-size: 13px; vertical-align: baseline; color: black;">(</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-size: 13px; vertical-align: baseline; color: black;"> </span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-size: 13px; vertical-align: baseline; color: black;">(</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-size: 13px; vertical-align: baseline; color: black;"> </span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-size: 13px; vertical-align: baseline; color: black;">(</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-size: 13px; vertical-ali
 gn: basel
ine; color: black;"> someprog</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-size: 13px; vertical-align: baseline; color: black;">;</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-size: 13px; vertical-align: baseline; color: black;">          </span><span class="com" style="margin: 0px; padding: 0px; border: 0px; font-size: 13px; vertical-align: baseline; color: gray;">#part6</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-size: 13px; vertical-align: baseline; color: black;">
        echo $</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-size: 13px; vertical-align: baseline; color: black;">?</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-size: 13px; vertical-align: baseline; color: black;"> </span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-size: 13px; vertical-align: baseline; color: black;">&gt;&amp;</span><span class="lit" style="margin: 0px; padding: 0px; border: 0px; font-size: 13px; vertical-align: baseline; color: maroon;">3</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-size: 13px; vertical-align: baseline; color: black;">        </span><span class="com" style="margin: 0px; padding: 0px; border: 0px; font-size: 13px; vertical-align: baseline; color: gray;">#part5</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-size: 13px; vertical-align: baseline; color: black;">
      </span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-size: 13px; vertical-align: baseline; color: black;">)</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-size: 13px; vertical-align: baseline; color: black;"> </span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-size: 13px; vertical-align: baseline; color: black;">|</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-size: 13px; vertical-align: baseline; color: black;"> filter </span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-size: 13px; vertical-align: baseline; color: black;">&gt;&amp;</span><span class="lit" style="margin: 0px; padding: 0px; border: 0px; font-size: 13px; vertical-align: baseline; color: maroon;">4</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-size: 13px; vertical-align: baseline; color: black;">       </span><span class="com" style="margin: 0px; 
 padding: 
0px; border: 0px; font-size: 13px; vertical-align: baseline; color: gray;">#part4</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-size: 13px; vertical-align: baseline; color: black;">
    </span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-size: 13px; vertical-align: baseline; color: black;">)</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-size: 13px; vertical-align: baseline; color: black;"> </span><span class="lit" style="margin: 0px; padding: 0px; border: 0px; font-size: 13px; vertical-align: baseline; color: maroon;">3</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-size: 13px; vertical-align: baseline; color: black;">&gt;&amp;</span><span class="lit" style="margin: 0px; padding: 0px; border: 0px; font-size: 13px; vertical-align: baseline; color: maroon;">1</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-size: 13px; vertical-align: baseline; color: black;">                 </span><span class="com" style="margin: 0px; padding: 0px; border: 0px; font-size: 13px; vertical-align: baseline; color: gray;">#part3</span><span class="pln" style="margin:
  0px; pad
ding: 0px; border: 0px; font-size: 13px; vertical-align: baseline; color: black;">
  </span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-size: 13px; vertical-align: baseline; color: black;">)</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-size: 13px; vertical-align: baseline; color: black;"> </span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-size: 13px; vertical-align: baseline; color: black;">|</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-size: 13px; vertical-align: baseline; color: black;"> stdintoexitstatus    </span><span class="com" style="margin: 0px; padding: 0px; border: 0px; font-size: 13px; vertical-align: baseline; color: gray;">#part2</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-size: 13px; vertical-align: baseline; color: black;">
</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-size: 13px; vertical-align: baseline; color: black;">)</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-size: 13px; vertical-align: baseline; color: black;"> </span><span class="lit" style="margin: 0px; padding: 0px; border: 0px; font-size: 13px; vertical-align: baseline; color: maroon;">4</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-size: 13px; vertical-align: baseline; color: black;">&gt;&amp;</span><span class="lit" style="margin: 0px; padding: 0px; border: 0px; font-size: 13px; vertical-align: baseline; color: maroon;">1</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-size: 13px; vertical-align: baseline; color: black;">                     </span><span class="com" style="margin: 0px; padding: 0px; border: 0px; font-size: 13px; vertical-align: baseline; color: gray;">#part1</span></code></pre>
      <p style="margin: 0px 0px 1em; padding: 0px; border: 0px;
        font-size: 15px; vertical-align: baseline; clear: both;
        word-wrap: break-word; color: rgb(51, 51, 51); font-family:
        'Helvetica Neue', Helvetica, Arial, sans-serif; font-style:
        normal; font-variant: normal; font-weight: normal;
        letter-spacing: normal; line-height: 20px; orphans: auto;
        text-align: left; text-indent: 0px; text-transform: none;
        white-space: normal; widows: auto; word-spacing: 0px;
        -webkit-text-stroke-width: 0px;">From bottom up:</p>
      <ol style="margin: 0px 0px 1em 30px; padding: 0px; border: 0px;
        font-size: 15px; vertical-align: baseline; list-style: decimal;
        color: rgb(51, 51, 51); font-family: 'Helvetica Neue',
        Helvetica, Arial, sans-serif; font-style: normal; font-variant:
        normal; font-weight: normal; letter-spacing: normal;
        line-height: 20px; orphans: auto; text-align: left; text-indent:
        0px; text-transform: none; white-space: normal; widows: auto;
        word-spacing: 0px; -webkit-text-stroke-width: 0px;">
        <li style="margin: 0px 0px 7px; padding: 0px; border: 0px;
          font-size: 15px; vertical-align: baseline; line-height: 16px;
          word-wrap: break-word;">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.</li>
        <li style="margin: 0px 0px 7px; padding: 0px; border: 0px;
          font-size: 15px; vertical-align: baseline; line-height: 16px;
          word-wrap: break-word;">A pipe is created and the commands on
          the left (<code style="margin: 0px; padding: 0px; border: 0px;
            font-size: 13px; vertical-align: baseline; font-family:
            Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation
            Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono',
            'Courier New', monospace, serif; color: rgb(34, 34, 34);
            background-color: rgb(238, 238, 238);">#part3</code>) and
          right (<code style="margin: 0px; padding: 0px; border: 0px;
            font-size: 13px; vertical-align: baseline; font-family:
            Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation
            Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono',
            'Courier New', monospace, serif; color: rgb(34, 34, 34);
            background-color: rgb(238, 238, 238);">stdintoexitstatus</code>)
          are executed.<span class="Apple-converted-space">&nbsp;</span><code
            style="margin: 0px; padding: 0px; border: 0px; font-size:
            13px; vertical-align: baseline; font-family: Consolas,
            Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu
            Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New',
            monospace, serif; color: rgb(34, 34, 34); background-color:
            rgb(238, 238, 238);">stdintoexitstatus</code><span
            class="Apple-converted-space">&nbsp;</span>is also the last
          command of the pipe and that means the exit status of<span
            class="Apple-converted-space">&nbsp;</span><code style="margin:
            0px; padding: 0px; border: 0px; font-size: 13px;
            vertical-align: baseline; font-family: Consolas, Menlo,
            Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans
            Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace,
            serif; color: rgb(34, 34, 34); background-color: rgb(238,
            238, 238);">stdintoexitstatus</code><span
            class="Apple-converted-space">&nbsp;</span>will be the exit
          status of the entire construct.</li>
        <li style="margin: 0px 0px 7px; padding: 0px; border: 0px;
          font-size: 15px; vertical-align: baseline; line-height: 16px;
          word-wrap: break-word;">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<span
            class="Apple-converted-space">&nbsp;</span><code style="margin:
            0px; padding: 0px; border: 0px; font-size: 13px;
            vertical-align: baseline; font-family: Consolas, Menlo,
            Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans
            Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace,
            serif; color: rgb(34, 34, 34); background-color: rgb(238,
            238, 238);">stdintoexitstatus</code><span
            class="Apple-converted-space">&nbsp;</span>and in turn will be
          the exit status of the entire construct.</li>
        <li style="margin: 0px 0px 7px; padding: 0px; border: 0px;
          font-size: 15px; vertical-align: baseline; line-height: 16px;
          word-wrap: break-word;">A pipe is created and the commands on
          the left (<code style="margin: 0px; padding: 0px; border: 0px;
            font-size: 13px; vertical-align: baseline; font-family:
            Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation
            Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono',
            'Courier New', monospace, serif; color: rgb(34, 34, 34);
            background-color: rgb(238, 238, 238);">#part5</code><span
            class="Apple-converted-space">&nbsp;</span>and<span
            class="Apple-converted-space">&nbsp;</span><code style="margin:
            0px; padding: 0px; border: 0px; font-size: 13px;
            vertical-align: baseline; font-family: Consolas, Menlo,
            Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans
            Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace,
            serif; color: rgb(34, 34, 34); background-color: rgb(238,
            238, 238);">#part6</code>) and right (<code style="margin:
            0px; padding: 0px; border: 0px; font-size: 13px;
            vertical-align: baseline; font-family: Consolas, Menlo,
            Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans
            Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace,
            serif; color: rgb(34, 34, 34); background-color: rgb(238,
            238, 238);">filter &gt;&amp;4</code>) are executed. The
          output of<span class="Apple-converted-space">&nbsp;</span><code
            style="margin: 0px; padding: 0px; border: 0px; font-size:
            13px; vertical-align: baseline; font-family: Consolas,
            Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu
            Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New',
            monospace, serif; color: rgb(34, 34, 34); background-color:
            rgb(238, 238, 238);">filter</code><span
            class="Apple-converted-space">&nbsp;</span>is redirected to file
          descriptor 4. In<span class="Apple-converted-space">&nbsp;</span><code
            style="margin: 0px; padding: 0px; border: 0px; font-size:
            13px; vertical-align: baseline; font-family: Consolas,
            Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu
            Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New',
            monospace, serif; color: rgb(34, 34, 34); background-color:
            rgb(238, 238, 238);">#part1</code><span
            class="Apple-converted-space">&nbsp;</span>the file descriptor 4
          was redirected to stdout. This means that the output of<span
            class="Apple-converted-space">&nbsp;</span><code style="margin:
            0px; padding: 0px; border: 0px; font-size: 13px;
            vertical-align: baseline; font-family: Consolas, Menlo,
            Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans
            Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace,
            serif; color: rgb(34, 34, 34); background-color: rgb(238,
            238, 238);">filter</code><span class="Apple-converted-space">&nbsp;</span>is
          the stdout of the entire construct.</li>
        <li style="margin: 0px 0px 7px; padding: 0px; border: 0px;
          font-size: 15px; vertical-align: baseline; line-height: 16px;
          word-wrap: break-word;">Exit status from<span
            class="Apple-converted-space">&nbsp;</span><code style="margin:
            0px; padding: 0px; border: 0px; font-size: 13px;
            vertical-align: baseline; font-family: Consolas, Menlo,
            Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans
            Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace,
            serif; color: rgb(34, 34, 34); background-color: rgb(238,
            238, 238);">#part6</code><span class="Apple-converted-space">&nbsp;</span>is
          printed to file descriptor 3. In<span
            class="Apple-converted-space">&nbsp;</span><code style="margin:
            0px; padding: 0px; border: 0px; font-size: 13px;
            vertical-align: baseline; font-family: Consolas, Menlo,
            Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans
            Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace,
            serif; color: rgb(34, 34, 34); background-color: rgb(238,
            238, 238);">#part3</code><span class="Apple-converted-space">&nbsp;</span>file
          descriptor 3 was redirected to<code style="margin: 0px;
            padding: 0px; border: 0px; font-size: 13px; vertical-align:
            baseline; font-family: Consolas, Menlo, Monaco, 'Lucida
            Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream
            Vera Sans Mono', 'Courier New', monospace, serif; color:
            rgb(34, 34, 34); background-color: rgb(238, 238, 238);">stdintoexitstatus</code>.
          This means that the exit status from<span
            class="Apple-converted-space">&nbsp;</span><code style="margin:
            0px; padding: 0px; border: 0px; font-size: 13px;
            vertical-align: baseline; font-family: Consolas, Menlo,
            Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans
            Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace,
            serif; color: rgb(34, 34, 34); background-color: rgb(238,
            238, 238);">#part6</code><span class="Apple-converted-space">&nbsp;</span>will
          be the final exit status for the entire construct.</li>
        <li style="margin: 0px 0px 7px; padding: 0px; border: 0px;
          font-size: 15px; vertical-align: baseline; line-height: 16px;
          word-wrap: break-word;"><code style="margin: 0px; padding:
            0px; border: 0px; font-size: 13px; vertical-align: baseline;
            font-family: Consolas, Menlo, Monaco, 'Lucida Console',
            'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans
            Mono', 'Courier New', monospace, serif; color: rgb(34, 34,
            34); background-color: rgb(238, 238, 238);">someprog</code><span
            class="Apple-converted-space">&nbsp;</span>is executed. The exit
          status is taken in<span class="Apple-converted-space">&nbsp;</span><code
            style="margin: 0px; padding: 0px; border: 0px; font-size:
            13px; vertical-align: baseline; font-family: Consolas,
            Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu
            Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New',
            monospace, serif; color: rgb(34, 34, 34); background-color:
            rgb(238, 238, 238);">#part5</code>. The stdout is taken by
          the pipe in<code style="margin: 0px; padding: 0px; border:
            0px; font-size: 13px; vertical-align: baseline; font-family:
            Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation
            Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono',
            'Courier New', monospace, serif; color: rgb(34, 34, 34);
            background-color: rgb(238, 238, 238);">#part4</code><span
            class="Apple-converted-space">&nbsp;</span>and forwarded to<span
            class="Apple-converted-space">&nbsp;</span><code style="margin:
            0px; padding: 0px; border: 0px; font-size: 13px;
            vertical-align: baseline; font-family: Consolas, Menlo,
            Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans
            Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace,
            serif; color: rgb(34, 34, 34); background-color: rgb(238,
            238, 238);">filter</code>. The output from<span
            class="Apple-converted-space">&nbsp;</span><code style="margin:
            0px; padding: 0px; border: 0px; font-size: 13px;
            vertical-align: baseline; font-family: Consolas, Menlo,
            Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans
            Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace,
            serif; color: rgb(34, 34, 34); background-color: rgb(238,
            238, 238);">filter</code><span class="Apple-converted-space">&nbsp;</span>will
          in turn reach stdout as explained in<code style="margin: 0px;
            padding: 0px; border: 0px; font-size: 13px; vertical-align:
            baseline; font-family: Consolas, Menlo, Monaco, 'Lucida
            Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream
            Vera Sans Mono', 'Courier New', monospace, serif; color:
            rgb(34, 34, 34); background-color: rgb(238, 238, 238);">#part4</code></li>
      </ol>
      <br>
      <br>
      On 10/01/2013 03:34 PM, Paul Ingram wrote:<br>
    </div>
    <blockquote
      cite="mid:BB749CB6-5F81-434D-9E65-DC8B5D4144BD at nicira.com"
      type="cite">
      <pre wrap="">Why the redirect from descriptor 4?

:: psi

On Oct 1, 2013, at 3:13 PM, Duffie Cooley <a class="moz-txt-link-rfc2396E" href="mailto:dcooley at nicira.com">&lt;dcooley at nicira.com&gt;</a> wrote:

</pre>
      <blockquote type="cite">
        <pre wrap="">What about this?

referenced from here.

<a class="moz-txt-link-freetext" href="http://unix.stackexchange.com/questions/14270/get-exit-status-of-process-thats-piped-to-another/70675#70675">http://unix.stackexchange.com/questions/14270/get-exit-status-of-process-thats-piped-to-another/70675#70675</a>

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 "$@" &gt;&gt; "${logdir}/ovs-ctl.log"
}

+stdintoexitstatus () {
+    read exitstatus
+    return $exitstatus
+}
+
ovs_ctl () {
    case "$@" in
        *"=strace"*)
@@ -51,7 +56,7 @@ ovs_ctl () {
        ;;
        *)
            echo "`date -u`:$@" &gt;&gt; "${logdir}/ovs-ctl.log"
-            "${datadir}/scripts/ovs-ctl" "$@" 2&gt;&amp;1 | tee -a
"${logdir}/ovs-ctl.log"
+            (((("${datadir}/scripts/ovs-ctl" "$@"  2&gt;&amp;1 ; echo $? &gt; &amp;3)
| tee -a "${logdir}/ovs-ctl.log" ) 3&gt;&amp;1) | stdintoexitstatus) 4&gt;&amp;1
        ;;
    esac
}


Thanks,

Duffie


On 10/01/2013 11:48 AM, Gurucharan Shetty wrote:
</pre>
        <blockquote type="cite">
          <pre wrap="">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`:$@" &gt;&gt; "${logdir}/ovs-ctl.log"
-            "${datadir}/scripts/ovs-ctl" "$@" 2&gt;&amp;1 | tee -a
"${logdir}/ovs-ctl.log"
+            unique=`(uuidgen) 2&gt;/dev/null` || unique=`date +"%Y %b %d %T"`
+            mkfifo "/tmp/${unique}"
+            tee -a "${logdir}/ovs-ctl.log" &lt; "/tmp/${unique}" &amp;
+            "${datadir}/scripts/ovs-ctl" "$@" &gt; "/tmp/${unique}" 2&gt;&amp;1
+            rc=$?
+            rm "/tmp/${unique}"
+            return $rc
        ;;
    esac
}

On Tue, Oct 1, 2013 at 10:11 AM, Gurucharan Shetty <a class="moz-txt-link-rfc2396E" href="mailto:shettyg at nicira.com">&lt;shettyg at nicira.com&gt;</a> wrote:
</pre>
          <blockquote type="cite">
            <pre wrap="">On Mon, Sep 30, 2013 at 7:27 PM, Duffie Cooley <a class="moz-txt-link-rfc2396E" href="mailto:dcooley at nicira.com">&lt;dcooley at nicira.com&gt;</a> wrote:
</pre>
            <blockquote type="cite">
              <pre wrap="">From: Duffie Cooley <a class="moz-txt-link-rfc2396E" href="mailto:dcooley at nicira.com">&lt;dcooley at nicira.com&gt;</a>
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 <a class="moz-txt-link-rfc2396E" href="mailto:dcooley at nicira.com">&lt;dcooley at nicira.com&gt;</a>
---
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

</pre>
            </blockquote>
            <pre wrap="">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?

</pre>
          </blockquote>
        </blockquote>
        <pre wrap="">
_______________________________________________
dev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:dev at openvswitch.org">dev at openvswitch.org</a>
<a class="moz-txt-link-freetext" href="http://openvswitch.org/mailman/listinfo/dev">http://openvswitch.org/mailman/listinfo/dev</a>
</pre>
      </blockquote>
      <pre wrap="">
</pre>
    </blockquote>
    <br>
  </body>
</html>

--------------070501010806010609000306--


More information about the dev mailing list