Mailinglist Archive: zypp-commit (38 mails)

< Previous Next >
[zypp-commit] <libzypp> master : CheckAccessDeleted::findService interface for testing.
  • From: Michael Andres <ma@xxxxxxx>
  • Date: Fri, 7 Aug 2009 12:28:12 +0200
  • Message-id: <E1MZMgQ-0005DC-K7@xxxxxxxxxxxxxxxx>
ref: refs/heads/master
commit fd553fc1080b7d76d08ac34410ab302f5b89c835
Author: Michael Andres <ma@xxxxxxx>
Date: Fri Aug 7 12:28:12 2009 +0200

CheckAccessDeleted::findService interface for testing.
---
zypp/misc/CheckAccessDeleted.cc | 46 +++++++++++++++++++++++++++++++++++++-
zypp/misc/CheckAccessDeleted.h | 14 +++++++++++
2 files changed, 58 insertions(+), 2 deletions(-)

diff --git a/zypp/misc/CheckAccessDeleted.cc b/zypp/misc/CheckAccessDeleted.cc
index b0f0275..ce0b7e7 100644
--- a/zypp/misc/CheckAccessDeleted.cc
+++ b/zypp/misc/CheckAccessDeleted.cc
@@ -83,7 +83,9 @@ namespace zypp
if ( pinfo.command.size() == 15 )
{
// the command name might be truncated, so we check against
/proc/<pid>/exe
- pinfo.command = filesystem::readlink(
Pathname("/proc")/pinfo.pid/"exe" ).basename();
+ Pathname command( filesystem::readlink(
Pathname("/proc")/pinfo.pid/"exe" ) );
+ if ( ! command.empty() )
+ pinfo.command = command.basename();
}

MIL << " Take " << pinfo << endl;
@@ -163,6 +165,21 @@ namespace zypp
return _data.size();
}

+ std::string CheckAccessDeleted::findService( const Pathname & command_r )
+ {
+ ProcInfo p;
+ p.command = command_r.basename();
+ return p.service();
+ }
+ std::string CheckAccessDeleted::findService( const char * command_r )
+ { return findService( Pathname( command_r ) ); }
+
+ std::string CheckAccessDeleted::findService( const std::string & command_r )
+ { return findService( Pathname( command_r ) ); }
+
+ std::string CheckAccessDeleted::findService( pid_t pid_r )
+ { return findService( filesystem::readlink(
Pathname("/proc")/str::numstring(pid_r)/"exe" ) ); }
+
///////////////////////////////////////////////////////////////////
namespace
{ /////////////////////////////////////////////////////////////////
@@ -172,7 +189,32 @@ namespace zypp

std::string CheckAccessDeleted::ProcInfo::service() const
{
- // TODO: This needs to be implemented.
+ if ( command.empty() )
+ return std::string();
+ // TODO: This needs to be implemented smarter... be carefull
+ // as we don't know whether the target is up.
+
+ static const Pathname initD( "/etc/init.d" );
+ { // init.d script with same name
+ PathInfo pi( initD/command );
+ if ( pi.isFile() && pi.isX() )
+ return command;
+ }
+ { // init.d script with name + 'd'
+ std::string alt( command+"d" );
+ PathInfo pi( initD/alt );
+ if ( pi.isFile() && pi.isX() )
+ return alt;
+ }
+ if ( *command.rbegin() == 'd' )
+ { // init.d script with name - trailing'd'
+ std::string alt( command );
+ alt.erase( alt.size()-1 );
+ PathInfo pi( initD/alt );
+ WAR <<pi << endl;
+ if ( pi.isFile() && pi.isX() )
+ return alt;
+ }
return std::string();
}

diff --git a/zypp/misc/CheckAccessDeleted.h b/zypp/misc/CheckAccessDeleted.h
index 1e9513a..10c1455 100644
--- a/zypp/misc/CheckAccessDeleted.h
+++ b/zypp/misc/CheckAccessDeleted.h
@@ -79,6 +79,20 @@ namespace zypp
const_iterator begin() const { return _data.begin(); }
const_iterator end() const { return _data.end(); }

+ public:
+ /** Guess if \c command was started by an \c /etc/init.d/ script.
+ * The name of an \c /etc/init.d/ script that might be used to restart
the
+ * command. \c command may be specifies by name, full path or pid.
+ * \warning This is just a guess.
+ */
+ static std::string findService( const char * command_r );
+ /** \overload Taking a string.*/
+ static std::string findService( const std::string & command_r );
+ /** \overload Taking a pathname. */
+ static std::string findService( const Pathname & command_r );
+ /** \overload taking the pid. */
+ static std::string findService( pid_t pid_r );
+
private:
std::vector<ProcInfo> _data;
};
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: zypp-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages