21 #undef ZYPP_BASE_LOGGER_LOGGROUP
22 #define ZYPP_BASE_LOGGER_LOGGROUP "MODALIAS"
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" );
60 AutoDispose<DIR *> dir( ::opendir( dir_r.c_str() ), ::closedir );
64 struct dirent * dirent = NULL;
65 while ( (dirent = ::
readdir(dir)) != NULL )
67 if ( dirent->d_name[0] ==
'.' )
70 if ( isBlackListed( dir_r, dirent->d_name ) )
73 PathInfo pi( dir_r / dirent->d_name, PathInfo::LSTAT );
77 foreach_file_recursive( pi.path(), arg );
79 else if ( pi.isFile() && ::strcmp( dirent->d_name,
"modalias" ) == 0 )
82 std::ifstream str( pi.path().c_str() );
85 arg.push_back( line );
102 const char * dir = getenv(
"ZYPP_MODALIAS_SYSFS");
111 DBG <<
"Using $ZYPP_MODALIAS_SYSFS modalias file: " << dir << endl;
113 [&](
int num_r, std::string line_r )->bool
120 DBG <<
"Using $ZYPP_MODALIAS_SYSFS: " << dir << endl;
125 DBG <<
"Using /sys directory." << endl;
149 bool query(
const char * cap_r )
const
151 if ( cap_r && *cap_r )
155 if ( fnmatch( cap_r, (*it).c_str(), 0 ) == 0 )
169 static shared_ptr<Impl> _nullimpl(
new Impl );
192 : _pimpl(
Impl::nullimpl() )
205 {
return _pimpl->query( cap_r ); }
208 {
return _pimpl->_modaliases; }
211 {
_pimpl->_modaliases.swap( newlist_r ); }
214 {
return str << *obj.
_pimpl; }
Modalias()
Singleton ctor.
bool query(IdString cap_r) const
Checks if a device on the system matches a modalias pattern.
RW_pointer< Impl > _pimpl
Pointer to implementation.
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
const ModaliasList & modaliasList() const
List of modaliases found on system.
std::string getline(std::istream &str)
Read one line from stream.
std::ostream & dumpRange(std::ostream &str, _Iterator begin, _Iterator 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).
int forEachLine(std::istream &str_r, function< bool(int, std::string)> consume_r)
Simple lineparser: Call functor consume_r for each line.
std::ostream & operator<<(std::ostream &str, const CommitPackageCache &obj)
std::vector< std::string > ModaliasList
int readdir(std::list< std::string > &retlist_r, const Pathname &path_r, bool dots_r)
Return content of directory via retlist.
static Modalias & instance()
Singleton access.
static shared_ptr< Impl > nullimpl()
Offer default Impl.
std::ostream & operator<<(std::ostream &str, const Modalias::Impl &obj)
Hardware abstaction layer singleton.
bool query(const char *cap_r) const