2 #include <zypp/base/Easy.h>
3 #include <zypp/base/String.h>
4 #include <zypp/base/Exception.h>
5 #include <zypp/Pathname.h>
6 #include <zypp/misc/CheckAccessDeleted.h>
8 /** Collect max string size. */
11 TableCol( size_t size_r = 0 )
14 TableCol( const std::string & header_r )
15 : header( header_r ), size( header_r.size() )
17 void operator()( const std::string & val_r )
18 { if ( val_r.size() > size ) size = val_r.size(); }
24 /** Scan to determine column sizes, then print. */
32 , command ( "COMMAND" )
33 , service ( "SERVICE" )
37 void scan( const zypp::CheckAccessDeleted::ProcInfo & val_r )
43 command( val_r.command );
44 service( val_r.service() );
47 void printHeader() const
58 void print( const zypp::CheckAccessDeleted::ProcInfo & val_r ) const
66 zypp::str::join( val_r.files, ", " ) );
69 void printRow( const std::string & pid_r,
70 const std::string & ppid_r,
71 const std::string & puid_r,
72 const std::string & login_r,
73 const std::string & command_r,
74 const std::string & service_r,
75 const std::string & files_r ) const
77 printf( "%*s %*s %*s %-*s %-*s %-*s %-s\n",
78 pid.size, pid_r.c_str(),
79 ppid.size, ppid_r.c_str(),
80 puid.size, puid_r.c_str(),
81 login.size, login_r.c_str(),
82 command.size, command_r.c_str(),
83 service.size, (service_r.empty() ? " -" : service_r.c_str()),
96 int main( int argc, char * argv[] )
100 std::string progname( zypp::Pathname::basename( argv[0] ) );
101 if ( strcmp( argv[1], "--help" ) == 0 )
103 std::cout << "Usage: " << progname << " [--help]" << std::endl;
104 std::cout << "List information about all running processe" << std::endl;
105 std::cout << "which access deleted files or libraries." << std::endl;
106 std::cout << " PID " << "process ID" << std::endl;
107 std::cout << " PPID " << "parent process ID" << std::endl;
108 std::cout << " UID " << "process user ID" << std::endl;
109 std::cout << " LOGIN " << "process login name" << std::endl;
110 std::cout << " COMMAND " << "process command name" << std::endl;
111 std::cout << " SERVICE " << "/etc/init.d/ script that might be used to restart the command (guessed)" << std::endl;
112 std::cout << " FILES " << "list of deleted files or libraries accessed" << std::endl;
115 std::cerr << progname << ": unexpected argument '" << argv[1] << "'" << std::endl;
116 std::cerr << "Try `" << progname << " --help' for more information." << std::endl;
120 zypp::CheckAccessDeleted checker(false); // wait for explicit call to check()
124 catch( const zypp::Exception & err )
126 std::cerr << err << std::endl << err.historyAsString();
131 for_( it, checker.begin(), checker.end() )
135 for_( it, checker.begin(), checker.end() )