14 #include <sys/types.h>
28 #undef ZYPP_BASE_LOGGER_LOGGROUP
29 #define ZYPP_BASE_LOGGER_LOGGROUP "MODALIAS"
65 foreach_file_recursive(
const char *path_rec,
int (*func)(
const char *,
const char *,
void *),
69 struct dirent *dirent;
70 char path_tmp[PATH_MAX];
73 if (!(dir = opendir(path_rec)))
75 while ((dirent =
readdir(dir)) != NULL) {
77 if (strcmp(dirent->d_name,
".") == 0 ||
78 strcmp(dirent->d_name,
"..") == 0)
80 snprintf(path_tmp,
sizeof(path_tmp),
"%s/%s", path_rec, dirent->d_name);
82 PathInfo path(path_tmp, PathInfo::LSTAT);
88 (void) foreach_file_recursive(path_tmp, func, arg);
89 }
else if (path.isFile ()){
90 if ((ret = func(path_rec, dirent->d_name, arg)) != 0)
96 if (closedir(dir) != 0)
106 read_modalias(
const char *dir,
const char *file,
void *arg)
111 char modalias[PATH_MAX];
112 struct modalias_list **list = (
struct modalias_list **)arg, *entry;
114 if (strcmp(file,
"modalias") != 0){
117 snprintf(path,
sizeof(path),
"%s/%s", dir, file);
118 if ((fd = open(path, O_RDONLY|O_CLOEXEC)) == -1)
120 len =
read(fd, modalias,
sizeof(modalias) - 1);
123 while (len > 0 && modalias[len - 1] ==
'\n')
127 if ((entry = (
struct modalias_list *)malloc(
sizeof(*entry))) == NULL)
129 if ((entry->modalias = strdup(modalias)) == NULL) {
135 XXX <<
"system modalias: " << entry->modalias << endl;
162 dir = getenv(
"ZYPP_MODALIAS_SYSFS");
165 DBG <<
"Using /sys directory : " << dir << endl;
167 snprintf(path,
sizeof(path),
"%s", dir);
168 foreach_file_recursive( path, read_modalias, &
_modaliases );
197 bool query(
const char * cap_r )
const
203 if ( fnmatch( cap_r, l->
modalias, 0 ) == 0 )
214 static shared_ptr<Impl> _nullimpl(
new Impl );
228 return str <<
"Modalias::Impl";
243 : _pimpl(
Impl::nullimpl() )
279 return str << *obj.
_pimpl;