| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
#ifdef HAVE_CONFIG_H |
|---|
| 20 |
# include <config.h> |
|---|
| 21 |
#endif |
|---|
| 22 |
|
|---|
| 23 |
#include "matchlist.h" |
|---|
| 24 |
#include "util-io.h" |
|---|
| 25 |
|
|---|
| 26 |
#include <dirent.h> |
|---|
| 27 |
#include <string.h> |
|---|
| 28 |
#include <fcntl.h> |
|---|
| 29 |
|
|---|
| 30 |
#define ENSC_WRAPPERS_FCNTL 1 |
|---|
| 31 |
#define ENSC_WRAPPERS_UNISTD 1 |
|---|
| 32 |
#define ENSC_WRAPPERS_STDLIB 1 |
|---|
| 33 |
#include <wrappers.h> |
|---|
| 34 |
|
|---|
| 35 |
static int |
|---|
| 36 |
selectRefserver(struct dirent const *ent) |
|---|
| 37 |
{ |
|---|
| 38 |
return strncmp(ent->d_name, "refserver.", 10)==0; |
|---|
| 39 |
} |
|---|
| 40 |
|
|---|
| 41 |
void |
|---|
| 42 |
MatchList_initRefserverList(struct MatchList **lst, size_t *cnt, |
|---|
| 43 |
char const *dir) |
|---|
| 44 |
{ |
|---|
| 45 |
int cur_dir = Eopen(".", O_RDONLY, 0); |
|---|
| 46 |
struct dirent **entries; |
|---|
| 47 |
int count,i; |
|---|
| 48 |
|
|---|
| 49 |
Echdir(dir); |
|---|
| 50 |
count = scandir(".", &entries, selectRefserver, alphasort); |
|---|
| 51 |
if (count==-1) { |
|---|
| 52 |
perror("scandir()"); |
|---|
| 53 |
exit(1); |
|---|
| 54 |
} |
|---|
| 55 |
|
|---|
| 56 |
if (count==0) { |
|---|
| 57 |
WRITE_MSG(2, "no reference vserver configured\n"); |
|---|
| 58 |
exit(1); |
|---|
| 59 |
} |
|---|
| 60 |
|
|---|
| 61 |
*lst = Emalloc(sizeof(struct MatchList) * count); |
|---|
| 62 |
*cnt = count; |
|---|
| 63 |
for (i=0; i<count; ++i) { |
|---|
| 64 |
char const *tmp = entries[i]->d_name; |
|---|
| 65 |
size_t l = strlen(tmp); |
|---|
| 66 |
char vname[sizeof("./") + l]; |
|---|
| 67 |
struct MatchVserverInfo vserver = { |
|---|
| 68 |
.name = vname, |
|---|
| 69 |
.use_pkgmgmt = true |
|---|
| 70 |
}; |
|---|
| 71 |
|
|---|
| 72 |
memcpy(vname, "./", 2); |
|---|
| 73 |
memcpy(vname+2, tmp, l+1); |
|---|
| 74 |
|
|---|
| 75 |
if (!MatchVserverInfo_init(&vserver)) { |
|---|
| 76 |
WRITE_MSG(2, "failed to initialize unification of reference vserver\n"); |
|---|
| 77 |
exit(1); |
|---|
| 78 |
} |
|---|
| 79 |
|
|---|
| 80 |
if (!MatchList_initByVserver((*lst)+i, &vserver)) { |
|---|
| 81 |
WRITE_MSG(2, "unification for reference vserver not configured\n"); |
|---|
| 82 |
exit(1); |
|---|
| 83 |
} |
|---|
| 84 |
|
|---|
| 85 |
free(entries[i]); |
|---|
| 86 |
MatchVserverInfo_free(&vserver); |
|---|
| 87 |
} |
|---|
| 88 |
free(entries); |
|---|
| 89 |
|
|---|
| 90 |
Efchdir(cur_dir); |
|---|
| 91 |
Eclose(cur_dir); |
|---|
| 92 |
} |
|---|