Ack with minor comment: there is no check for the return value from 
sleep(), so sleep time may be shortened if interrupted by a signal. 
Also, sleep() is an old function that according to man page may be 
implemented using SIGALRM, which means there is a risk of interference 
from other threads or a prior call to alarm(). Consider using the new 
OpenSAF utility function osaf_nanosleep() instead, which has no risk of 
interference and handles signal interruption for you. E.g. like this:

#include "osaf_time.h"

struct timespec interval = { 2, 0 };
osaf_nanosleep(&interval);

/ Anders Widell

On 05/12/2014 08:53 AM, Ingvar Bergstrom wrote:
>   osaf/services/saf/smfsv/smfd/SmfUpgradeStep.cc |  58 
> +++----------------------
>   osaf/services/saf/smfsv/smfd/SmfUpgradeStep.hh |   8 ---
>   osaf/services/saf/smfsv/smfd/SmfUtils.cc       |  18 ++++++++
>   osaf/services/saf/smfsv/smfd/SmfUtils.hh       |   1 +
>   4 files changed, 26 insertions(+), 59 deletions(-)
>
>
> smfd wait for the node destination to appear before any command specified in 
> the campaign is executed.
> If the node destination does not appear within a timeout period the campaign 
> will fail.
>
> diff --git a/osaf/services/saf/smfsv/smfd/SmfUpgradeStep.cc 
> b/osaf/services/saf/smfsv/smfd/SmfUpgradeStep.cc
> --- a/osaf/services/saf/smfsv/smfd/SmfUpgradeStep.cc
> +++ b/osaf/services/saf/smfsv/smfd/SmfUpgradeStep.cc
> @@ -1654,41 +1654,6 @@ SmfUpgradeStep::saveImmContent()
>   }
>   
>   
> //------------------------------------------------------------------------------
> -// executeRemoteCmd()
> -//------------------------------------------------------------------------------
> -bool
> -SmfUpgradeStep::executeRemoteCmd( const std::string  &i_cmd,
> -                               const std::string & i_node)
> -{
> -     TRACE_ENTER();
> -     TRACE("Executing script '%s' on node '%s'", i_cmd.c_str(), 
> i_node.c_str());
> -     SaTimeT timeout;
> -     uint32_t cmdrc;
> -     bool rc = true;
> -        SmfndNodeDest nodeDest;
> -        if (!getNodeDestination(i_node, &nodeDest)) {
> -             LOG_NO("no node destination found for node %s", i_node.c_str());
> -             rc = false;
> -             goto done;
> -     }
> -
> -     /* Execute the script remote on node */
> -     timeout = smfd_cb->cliTimeout;  /* Default timeout */
> -
> -     cmdrc = smfnd_exec_remote_cmd(i_cmd.c_str(), &nodeDest, timeout / 
> 10000000, 0);
> -     /* convert ns to 10 ms timeout */
> -     if (cmdrc != 0) {
> -             LOG_NO("executing command '%s' on node '%s' failed (%x)",
> -                    i_cmd.c_str(), i_node.c_str(), cmdrc);
> -             rc = false;
> -             goto done;
> -     }
> -done:
> -     TRACE_LEAVE();
> -     return rc;
> -}
> -
> -//------------------------------------------------------------------------------
>   // callActivationCmd()
>   
> //------------------------------------------------------------------------------
>   bool
> @@ -1744,7 +1709,7 @@ SmfUpgradeStep::callActivationCmd()
>   
>                       TRACE("Executing activation command '%s' on node '%s' 
> (single-step)",
>                             actCommand.c_str(), nodeName);
> -                        if (!getNodeDestination(*n, &nodeDest)) {
> +                        if (!waitForNodeDestination(*n, &nodeDest)) {
>                               LOG_NO("no node destination found for node 
> [%s]", nodeName);
>                               result = false;
>                               goto done;
> @@ -1897,7 +1862,7 @@ SmfUpgradeStep::callBundleScript(SmfInst
>                               char const* nodeName = n->c_str();
>                               TRACE("Executing bundle script '%s' on node 
> '%s' (single-step)",
>                                     command.c_str(), nodeName);
> -                             if (!getNodeDestination(*n, &nodeDest)) {
> +                             if (!waitForNodeDestination(*n, &nodeDest)) {
>                                       LOG_NO("no node destination found for 
> node [%s]", nodeName);
>                                       result = false;
>                                       goto done;
> @@ -1910,7 +1875,6 @@ SmfUpgradeStep::callBundleScript(SmfInst
>                                       goto done;
>                               }
>                       }
> -
>               } else {
>   
>                           SmfndNodeDest nodeDest;
> @@ -1918,19 +1882,11 @@ SmfUpgradeStep::callBundleScript(SmfInst
>                             command.c_str(), i_node.c_str());
>                       TRACE("Get node destination for %s", i_node.c_str());
>   
> -                     int interval = 5;
> -                     int nodetimeout = smfd_cb->rebootTimeout/1000000000; 
> //seconds
> -                     while (!getNodeDestination(i_node, &nodeDest)) {
> -                             if (nodetimeout > 0) {
> -                                     TRACE("No destination found, try again 
> wait %d seconds", interval);
> -                                     sleep(interval);
> -                                     nodetimeout -= interval;
> -                             } else {
> -                                     LOG_NO("no node destination found for 
> node %s", i_node.c_str());
> -                                     result = false;
> -                                     goto done;
> -                             }
> -                     }
> +                        if (!waitForNodeDestination(i_node, &nodeDest)) {
> +                                LOG_NO("no node destination found for node 
> %s", i_node.c_str());
> +                                result = false;
> +                                goto done;
> +                        }
>   
>                       /* TODO : how to handle the case where the cmd is an 
> URI */
>                       /* First fetch the script using e.g. wget etc */
> diff --git a/osaf/services/saf/smfsv/smfd/SmfUpgradeStep.hh 
> b/osaf/services/saf/smfsv/smfd/SmfUpgradeStep.hh
> --- a/osaf/services/saf/smfsv/smfd/SmfUpgradeStep.hh
> +++ b/osaf/services/saf/smfsv/smfd/SmfUpgradeStep.hh
> @@ -627,14 +627,6 @@ class SmfUpgradeStep {
>       } SmfInstallRemoveT;
>   
>   ///
> -/// Purpose:  Call script on remote node
> -/// @param    -
> -/// @return   -
> -///
> -     bool executeRemoteCmd( const std::string &i_cmd,
> -                            const std::string & i_node);
> -
> -///
>   /// Purpose:  Call bundle script on remote node
>   /// @param    -
>   /// @return   -
> diff --git a/osaf/services/saf/smfsv/smfd/SmfUtils.cc 
> b/osaf/services/saf/smfsv/smfd/SmfUtils.cc
> --- a/osaf/services/saf/smfsv/smfd/SmfUtils.cc
> +++ b/osaf/services/saf/smfsv/smfd/SmfUtils.cc
> @@ -60,6 +60,24 @@ SaVersionT SmfImmUtils::s_immVersion = {
>    *   FUNCTION PROTOTYPES
>    * ========================================================================
>    */
> +bool
> +waitForNodeDestination(const std::string & i_node, SmfndNodeDest* o_nodeDest)
> +{
> +        int interval = 2;
> +        int nodetimeout = smfd_cb->rebootTimeout/1000000000; //seconds
> +        while (!getNodeDestination(i_node, o_nodeDest)) {
> +                if (nodetimeout > 0) {
> +                        TRACE("No destination found, try again wait %d 
> seconds", interval);
> +                        sleep(interval);
> +                        nodetimeout -= interval;
> +                } else {
> +                        LOG_NO("no node destination found whitin time limit 
> for node %s", i_node.c_str());
> +                        return false;
> +               }
> +        }
> +
> +        return true;
> +}
>   
>   bool
>   getNodeDestination(const std::string & i_node, SmfndNodeDest* o_nodeDest)
> diff --git a/osaf/services/saf/smfsv/smfd/SmfUtils.hh 
> b/osaf/services/saf/smfsv/smfd/SmfUtils.hh
> --- a/osaf/services/saf/smfsv/smfd/SmfUtils.hh
> +++ b/osaf/services/saf/smfsv/smfd/SmfUtils.hh
> @@ -69,6 +69,7 @@ extern "C" {
>   #ifdef __cplusplus
>   }
>   #endif
> +extern bool waitForNodeDestination(const std::string & i_node, 
> SmfndNodeDest* o_nodeDest);
>   extern bool getNodeDestination(const std::string & i_node, SmfndNodeDest* 
> o_nodeDest);
>   extern std::string replaceAllCopy(const std::string& i_haystack, const  
> std::string& i_needle, const  std::string& i_replacement);
>   


------------------------------------------------------------------------------
"Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
Instantly run your Selenium tests across 300+ browser/OS combos.
Get unparalleled scalability from the best Selenium testing platform available
Simple to use. Nothing to install. Get started now for free."
http://p.sf.net/sfu/SauceLabs
_______________________________________________
Opensaf-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensaf-devel

Reply via email to