ref: refs/heads/master
commit fd553fc1080b7d76d08ac34410ab302f5b89c835
Author: Michael Andres
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 <