[ovs-dev] [PATCH] rhel: fix the exit status of the openvswitch init script.
Paul Ingram
pingram at nicira.com
Tue Oct 1 22:34:18 UTC 2013
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
More information about the dev
mailing list