namespace zypp
{ /////////////////////////////////////////////////////////////////
-
namespace
{
const char * PLUGIN_DEBUG = getenv( "ZYPP_PLUGIN_DEBUG" );
- const long PLUGIN_TIMEOUT = str::strtonum<long>( getenv( "ZYPP_PLUGIN_TIMEOUT" ) );
- const long PLUGIN_SEND_TIMEOUT = str::strtonum<long>( getenv( "ZYPP_PLUGIN_SEND_TIMEOUT" ) );
- const long PLUGIN_RECEIVE_TIMEOUT = str::strtonum<long>( getenv( "ZYPP_PLUGIN_RECEIVE_TIMEOUT" ) );
/** Dump buffer string if PLUGIN_DEBUG is on.
* \ingroup g_RAII
const std::string & _buffer;
};
- /** Dump buffer string if PLUGIN_DEBUG is on.
+ /** Dump programms stderr.
* \ingroup g_RAII
*/
struct PluginDumpStderr
{
public:
Impl( const Pathname & script_r = Pathname(), const Arguments & args_r = Arguments() )
- : _script( script_r )
+ : _sendTimeout( _defaultSendTimeout )
+ , _receiveTimeout( _defaultReceiveTimeout )
+ , _script( script_r )
, _args( args_r )
{}
{ try { close(); } catch(...) {} }
public:
- /** Timeout (sec.) when sending data. */
- static const long send_timeout;
- /** Timeout (sec.) when receiving data. */
- static const long receive_timeout;
+ static long _defaultSendTimeout;
+ static long _defaultReceiveTimeout;
- public:
+ long _sendTimeout;
+ long _receiveTimeout;
+
+ public:
const Pathname & script() const
{ return _script; }
const Arguments & args() const
- { return _args; }
+ { return _args; }
pid_t getPid() const
{ return _cmd ? _cmd->getpid() : NotConnected; }
///////////////////////////////////////////////////////////////////
- const long PluginScript::Impl::send_timeout = ( PLUGIN_SEND_TIMEOUT > 0 ? PLUGIN_SEND_TIMEOUT
- : ( PLUGIN_TIMEOUT > 0 ? PLUGIN_TIMEOUT : 30 ) );
- const long PluginScript::Impl::receive_timeout = ( PLUGIN_RECEIVE_TIMEOUT > 0 ? PLUGIN_RECEIVE_TIMEOUT
- : ( PLUGIN_TIMEOUT > 0 ? PLUGIN_TIMEOUT : 30 ) );
+ namespace
+ {
+ const long PLUGIN_TIMEOUT = str::strtonum<long>( getenv( "ZYPP_PLUGIN_TIMEOUT" ) );
+ const long PLUGIN_SEND_TIMEOUT = str::strtonum<long>( getenv( "ZYPP_PLUGIN_SEND_TIMEOUT" ) );
+ const long PLUGIN_RECEIVE_TIMEOUT = str::strtonum<long>( getenv( "ZYPP_PLUGIN_RECEIVE_TIMEOUT" ) );
+ }
+
+ long PluginScript::Impl::_defaultSendTimeout = ( PLUGIN_SEND_TIMEOUT > 0 ? PLUGIN_SEND_TIMEOUT
+ : ( PLUGIN_TIMEOUT > 0 ? PLUGIN_TIMEOUT : 30 ) );
+ long PluginScript::Impl::_defaultReceiveTimeout = ( PLUGIN_RECEIVE_TIMEOUT > 0 ? PLUGIN_RECEIVE_TIMEOUT
+ : ( PLUGIN_TIMEOUT > 0 ? PLUGIN_TIMEOUT : 30 ) );
///////////////////////////////////////////////////////////////////
if ( _cmd )
{
DBG << "Close:" << *this << endl;
+ {
+ PluginDumpStderr _dump( *_cmd ); // dump scripts stderr before leaving
+ }
_cmd->kill();
_lastReturn = _cmd->close();
_lastExecError = _cmd->execError();
FD_SET( fd, &wfds );
struct timeval tv;
- tv.tv_sec = send_timeout;
+ tv.tv_sec = _sendTimeout;
tv.tv_usec = 0;
int retval = select( fd+1, NULL, &wfds, NULL, &tv );
FD_SET( fd, &rfds );
struct timeval tv;
- tv.tv_sec = receive_timeout;
+ tv.tv_sec = _receiveTimeout;
tv.tv_usec = 0;
int retval = select( fd+1, &rfds, NULL, NULL, &tv );
const pid_t PluginScript::NotConnected( -1 );
+ long PluginScript::defaultSendTimeout()
+ { return Impl::_defaultSendTimeout; }
+
+ long PluginScript::defaultReceiveTimeout()
+ { return Impl::_defaultReceiveTimeout; }
+
+ void PluginScript::defaultSendTimeout( long newval_r )
+ { Impl::_defaultSendTimeout = newval_r > 0 ? newval_r : 0; }
+
+ void PluginScript::defaultReceiveTimeout( long newval_r )
+ { Impl::_defaultReceiveTimeout = newval_r > 0 ? newval_r : 0; }
+
+ long PluginScript::sendTimeout() const
+ { return _pimpl->_sendTimeout; }
+
+ long PluginScript::receiveTimeout() const
+ { return _pimpl->_receiveTimeout; }
+
+ void PluginScript::sendTimeout( long newval_r )
+ { _pimpl->_sendTimeout = newval_r > 0 ? newval_r : 0; }
+
+ void PluginScript::receiveTimeout( long newval_r )
+ { _pimpl->_receiveTimeout = newval_r > 0 ? newval_r : 0; }
+
PluginScript::PluginScript()
: _pimpl( new Impl )
{}
static const pid_t NotConnected;
public:
+ /** \name Get/set the global timeout settings.
+ * Timeout when sending/receiving data to/from a plugin default to 30 sec. The value
+ * (in seconds) my be changed via the environment variables \c ZYPP_PLUGIN_SEND_TIMEOUT,
+ * \c ZYPP_PLUGIN_RECEIVE_TIMEOUT or \c ZYPP_PLUGIN_TIMEOUT (both: send and receive).
+ */
+ //@{
+ /** Global default timeout (sec.) when sending data. */
+ static long defaultSendTimeout();
+
+ /** Global default timeout (sec.) when receiving data. */
+ static long defaultReceiveTimeout();
+
+ /** Set global default timeout (sec.) when sending data. */
+ static void defaultSendTimeout( long newval_r );
+
+ /** Set global default timeout (sec.) when receiving data. */
+ static void defaultReceiveTimeout( long newval_r );
+
+ /** Set global default timeout (sec.) (both: send and receive).*/
+ static void defaultTimeout( long newval_r )
+ { defaultSendTimeout( newval_r ); defaultReceiveTimeout( newval_r ); }
+ //@}
+
+ public:
/** Default ctor. */
PluginScript();
*/
const std::string & lastExecError() const;
- public:
+ public:
+ /** \name Get/set local timeout settings. */
+ //@{
+ /** Local default timeout (sec.) when sending data. */
+ long sendTimeout() const;
+
+ /** Local default timeout (sec.) when receiving data. */
+ long receiveTimeout() const;
+
+ /** Set local default timeout (sec.) when sending data. */
+ void sendTimeout( long newval_r );
+
+ /** Set local default timeout (sec.) when receiving data. */
+ void receiveTimeout( long newval_r );
+
+ /** Set local default timeout (sec.) (both: send and receive).*/
+ void timeout( long newval_r )
+ { sendTimeout( newval_r ); receiveTimeout( newval_r ); }
+ //@}
+
+ public:
/** Setup connection and execute script.
* \throw PluginScriptException if already connected to a script
* \throw PluginScriptException if script does not exist or is not executable