21#undef ZYPP_BASE_LOGGER_LOGGROUP
22#define ZYPP_BASE_LOGGER_LOGGROUP "MODALIAS"
24#include <zypp/base/LogTools.h>
25#include <zypp/base/IOStream.h>
26#include <zypp-core/base/InputStream>
27#include <zypp/AutoDispose.h>
28#include <zypp/PathInfo.h>
44 inline bool isBlackListed(
const Pathname & dir_r,
const char * file_r )
46#define PATH_IS( D, F ) ( ::strcmp( file_r, F ) == 0 && ::strcmp( dir_r.c_str(), D ) == 0 )
50 return PATH_IS(
"/sys/devices/system",
"memory" );
57 void foreach_file_recursive(
const Pathname & dir_r, std::set<std::string> & arg_r )
59 AutoDispose<DIR *> dir( ::opendir( dir_r.c_str() ), ::closedir );
63 struct dirent * dirent = NULL;
64 while ( (dirent = ::readdir(dir)) != NULL )
66 if ( dirent->d_name[0] ==
'.' )
69 if ( isBlackListed( dir_r, dirent->d_name ) )
73 unsigned char d_type = dirent->d_type;
74 if ( d_type == DT_UNKNOWN )
76 path = dir_r/dirent->d_name;
80 else if ( pi.isFile() )
84 if ( d_type == DT_DIR )
87 path = dir_r/dirent->d_name;
88 foreach_file_recursive( path, arg_r );
90 else if ( d_type == DT_REG && ::strcmp( dirent->d_name,
"modalias" ) == 0 )
93 path = dir_r/dirent->d_name;
95 std::ifstream
str( path.c_str() );
106 std::set<std::string> arg;
107 foreach_file_recursive( dir_r, arg );
108 arg_r.insert( arg_r.end(), arg.begin(), arg.end() );
123 const char * dir = getenv(
"ZYPP_MODALIAS_SYSFS");
132 DBG <<
"Using $ZYPP_MODALIAS_SYSFS modalias file: " << dir << endl;
134 [&](
int num_r, std::string line_r )->bool
136 this->_modaliases.push_back( line_r );
141 DBG <<
"Using $ZYPP_MODALIAS_SYSFS: " << dir << endl;
146 DBG <<
"Using /sys directory." << endl;
170 bool query(
const char * cap_r )
const
172 if ( cap_r && *cap_r )
176 if ( fnmatch( cap_r, (*it).c_str(), 0 ) == 0 )
190 static shared_ptr<Impl> _nullimpl(
new Impl );
213 : _pimpl(
Impl::nullimpl() )
226 {
return _pimpl->query( cap_r ); }
229 {
return _pimpl->_modaliases; }
232 {
_pimpl->_modaliases.swap( newlist_r ); }
Wrapper class for stat/lstat.
const Pathname & path() const
Return current Pathname.
Hardware abstaction layer singleton.
Modalias()
Singleton ctor.
bool query(IdString cap_r) const
Checks if a device on the system matches a modalias pattern.
static Modalias & instance()
Singleton access.
std::vector< std::string > ModaliasList
const ModaliasList & modaliasList() const
List of modaliases found on system.
RW_pointer< Impl > _pimpl
Pointer to implementation.
String related utilities and Regular expression matching.
int forEachLine(std::istream &str_r, function< bool(int, std::string)> consume_r)
Simple lineparser: Call functor consume_r for each line.
std::string getline(std::istream &str)
Read one line from stream.
std::ostream & operator<<(std::ostream &str, const CommitPackageCache &obj)
Easy-to use interface to the ZYPP dependency resolver.
std::ostream & dumpRange(std::ostream &str, TIterator begin, TIterator end, const std::string &intro="{", const std::string &pfx="\n ", const std::string &sep="\n ", const std::string &sfx="\n", const std::string &extro="}")
Print range defined by iterators (multiline style).
bool query(const char *cap_r) const
std::ostream & operator<<(std::ostream &str, const Modalias::Impl &obj)
Stream output And maybe std::ostream & operator<< Modalias::Impl below too.
static shared_ptr< Impl > nullimpl()
Offer default Impl.
#define for_(IT, BEG, END)
Convenient for-loops using iterator.