13 #include <unordered_set>
25 #undef ZYPP_BASE_LOGGER_LOGGROUP
26 #define ZYPP_BASE_LOGGER_LOGGROUP "zypp::misc"
45 typedef std::pair<std::string,std::unordered_set<std::string>> CacheEntry;
51 inline void addDataIf( std::vector<CheckAccessDeleted::ProcInfo> & data_r,
const CacheEntry & cache_r )
53 const auto & filelist( cache_r.second );
55 if ( filelist.empty() )
59 data_r.push_back( CheckAccessDeleted::ProcInfo() );
60 CheckAccessDeleted::ProcInfo & pinfo( data_r.back() );
61 pinfo.files.insert( pinfo.files.begin(), filelist.begin(), filelist.end() );
63 const std::string & pline( cache_r.first );
64 for_( ch, pline.begin(), pline.end() )
72 pinfo.ppid = &*(ch+1);
75 pinfo.puid = &*(ch+1);
78 pinfo.login = &*(ch+1);
81 pinfo.command = &*(ch+1);
84 if ( *ch ==
'\n' )
break;
85 do { ++ch; }
while ( *ch !=
'\0' );
88 if ( pinfo.command.size() == 15 )
92 if ( ! command.empty() )
93 pinfo.command = command.basename();
104 inline void addCacheIf( CacheEntry & cache_r,
const std::string & line_r,
bool verbose_r )
110 for_( ch, line_r.c_str(), ch+line_r.size() )
115 if ( *(ch+1) !=
'0' )
128 if ( *ch ==
'\n' )
break;
129 do { ++ch; }
while ( *ch !=
'\0' );
132 if ( !t || !f || !n )
135 if ( !( ( *t ==
'R' && *(t+1) ==
'E' && *(t+2) ==
'G' && *(t+3) ==
'\0' )
136 || ( *t ==
'D' && *(t+1) ==
'E' && *(t+2) ==
'L' && *(t+3) ==
'\0' ) ) )
139 if ( !( ( *f ==
'm' && *(f+1) ==
'e' && *(f+2) ==
'm' && *(f+3) ==
'\0' )
140 || ( *f ==
't' && *(f+1) ==
'x' && *(f+2) ==
't' && *(f+3) ==
'\0' )
141 || ( *f ==
'D' && *(f+1) ==
'E' && *(f+2) ==
'L' && *(f+3) ==
'\0' )
142 || ( *f ==
'l' && *(f+1) ==
't' && *(f+2) ==
'x' && *(f+3) ==
'\0' ) ) )
154 if ( *f ==
'm' || *f ==
'D' )
156 static const char * black[] = {
168 cache_r.second.insert( n );
178 static const char* argv[] =
180 "lsof",
"-n",
"-FpcuLRftkn0", NULL
185 std::map<pid_t,CacheEntry> cachemap;
190 if ( line[0] ==
'p' )
193 cachemap[cachepid].first.swap( line );
197 addCacheIf( cachemap[cachepid], line, verbose_r );
201 int ret = prog.
close();
209 std::vector<ProcInfo> data;
210 for (
const auto & cached : cachemap )
212 addDataIf( data, cached.second );
221 p.
command = command_r.basename();
243 return std::string();
247 static const Pathname initD(
"/etc/init.d" );
250 if ( pi.isFile() && pi.isX() )
254 std::string alt(
command+
"d" );
255 PathInfo pi( initD/alt );
256 if ( pi.isFile() && pi.isX() )
259 if ( *
command.rbegin() ==
'd' )
262 alt.erase( alt.size()-1 );
263 PathInfo pi( initD/alt );
265 if ( pi.isFile() && pi.isX() )
268 return std::string();
278 return dumpRange( str <<
"CheckAccessDeleted ",
290 if ( obj.
pid.empty() )
291 return str <<
"<NoProc>";