3 #include <zypp/base/Easy.h>
4 #include <zypp/base/String.h>
5 #include <zypp/base/Exception.h>
6 #include <zypp/Pathname.h>
7 #include <zypp/misc/CheckAccessDeleted.h>
9 /** Collect max string size. */
12 TableCol( size_t size_r = 0 )
15 TableCol( const std::string & header_r )
16 : header( header_r ), size( header_r.size() )
18 void operator()( const std::string & val_r )
19 { if ( val_r.size() > size ) size = val_r.size(); }
25 /** Scan to determine column sizes, then print. */
33 , command ( "COMMAND" )
34 , service ( "SERVICE" )
38 void scan( const zypp::CheckAccessDeleted::ProcInfo & val_r )
44 command( val_r.command );
45 service( val_r.service() );
48 void printHeader() const
59 void print( const zypp::CheckAccessDeleted::ProcInfo & val_r ) const
67 zypp::str::join( val_r.files, ", " ) );
70 void printRow( const std::string & pid_r,
71 const std::string & ppid_r,
72 const std::string & puid_r,
73 const std::string & login_r,
74 const std::string & command_r,
75 const std::string & service_r,
76 const std::string & files_r ) const
78 printf( "%*s %*s %*s %-*s %-*s %-*s %-s\n",
79 (int)pid.size, pid_r.c_str(),
80 (int)ppid.size, ppid_r.c_str(),
81 (int)puid.size, puid_r.c_str(),
82 (int)login.size, login_r.c_str(),
83 (int)command.size, command_r.c_str(),
84 (int)service.size, (service_r.empty() ? " -" : service_r.c_str()),
97 void usage ( const std::string &appname )
99 std::cout << "Usage: " << appname << " [--help] [--debugFile <file>] [--zypper]" << std::endl;
100 std::cout << "List information about all running processe" << std::endl;
101 std::cout << "which access deleted executables or libraries." << std::endl;
102 std::cout << std::endl;
103 std::cout << "GLOBALOPTS:" << std::endl;
104 std::cout << " --debugFile <file> Use information from <file> instead" << std::endl;
105 std::cout << " of inspecting the host system." << std::endl;
106 std::cout << " --zypper Disable verbose checking like zypper does." << std::endl;
107 std::cout << std::endl;
108 std::cout << "TABLEHEADERS:" << std::endl;
109 std::cout << " PID " << "process ID" << std::endl;
110 std::cout << " PPID " << "parent process ID" << std::endl;
111 std::cout << " UID " << "process user ID" << std::endl;
112 std::cout << " LOGIN " << "process login name" << std::endl;
113 std::cout << " COMMAND " << "process command name" << std::endl;
114 std::cout << " SERVICE " << "/etc/init.d/ script that might be used to restart the command (guessed)" << std::endl;
115 std::cout << " FILES " << "list of deleted executables or libraries accessed" << std::endl;
118 int main( int argc, char * argv[] )
121 std::string progname( zypp::Pathname::basename( argv[0] ) );
122 std::string debugInputFile;
128 if ( strcmp( argv[0], "--help" ) == 0 )
132 } else if ( strcmp( argv[0], "--debugFile" ) == 0 ) {
134 std::cerr << progname << ": debugFile requires a argument" << std::endl;
140 debugInputFile = argv[0];
142 } else if ( strcmp( argv[0], "--zypper" ) == 0 ) {
145 std::cerr << progname << ": unexpected argument '" << argv[0] << "'" << std::endl;
146 std::cerr << "Try `" << progname << " --help' for more information." << std::endl;
154 zypp::CheckAccessDeleted checker(false); // wait for explicit call to check()
156 if ( debugInputFile.empty() )
157 checker.check( verbose );
159 checker.check( debugInputFile, verbose );
161 catch( const zypp::Exception & err )
163 std::cerr << err << std::endl << err.historyAsString();
168 for_( it, checker.begin(), checker.end() )
172 for_( it, checker.begin(), checker.end() )