#include "vserver.h"
-
+#include <assert.h>
bool
MatchList_initByVserver(struct MatchList *list,
- struct MatchVserverInfo const *vserver,
- char const **res_appdir)
+ struct MatchVserverInfo const *vserver)
{
- vcCfgStyle style;
- char const *vdir;
- char const *appdir;
-
- style = vc_getVserverCfgStyle(vserver->name);
- vdir = vc_getVserverVdir( vserver->name, style, true);
- appdir = vc_getVserverAppDir(vserver->name, style, "vunify");
-
- if (vdir==0 || appdir==0) {
- free((char *)appdir);
- free((char *)vdir);
- return false;
- }
-
- {
- size_t l1 = strlen(appdir);
- char tmp[l1 + sizeof("/exclude")];
- char const * excl_list;
-
- memcpy(tmp, appdir, l1);
- memcpy(tmp+l1, "/exclude", 9);
+ assert(vserver->appdir!=0 && vserver->vdir!=0);
+
+ size_t const l = vserver->appdir.l;
+ char tmp[l + sizeof("/exclude")];
+ char const * excl_list;
- excl_list = tmp;
- if (access(excl_list, R_OK)==-1) excl_list = CONFDIR "/.defaults/apps/vunify/exclude";
- if (access(excl_list, R_OK)==-1) excl_list = PKGLIBDIR "/defaults/vunify-exclude";
+ memcpy(tmp, vserver->appdir.d, l);
+ memcpy(tmp+l, "/exclude", 9);
- // 'vdir' is transferred to matchlist and must not be free'ed here
- MatchList_initManually(list, vserver, vdir, excl_list);
- }
+ excl_list = tmp;
+ if (access(excl_list, R_OK)==-1) excl_list = CONFDIR "/.defaults/apps/vunify/exclude";
+ if (access(excl_list, R_OK)==-1) excl_list = PKGLIBDIR "/defaults/vunify-exclude";
- if (res_appdir!=0)
- *res_appdir = appdir;
- else
- free((char *)appdir);
+ MatchList_initManually(list, vserver, 0, excl_list);
return true;
}
char **expr_files = 0;
size_t expr_count = 0;
+ size_t len;
+ assert((vdir==0 && vserver!=0) || (vdir!=0 && vserver==0));
+
+ if (vserver) {
+ vdir = vserver->vdir.d;
+ len = vserver->vdir.l;
+ }
+ else
+ len = strlen(vdir);
+
if (Global_getVerbosity()>=1) {
WRITE_MSG(1, "Initializing exclude-list for ");
- WRITE_STR(1, vdir);
+ (void)write(1, vdir, len);
if (vserver!=0) {
WRITE_MSG(1, " (");
WRITE_STR(1, vserver->name);
buf+1);
}
- MatchList_init(list, vdir, fixed_count + expr_count);
+ MatchList_init(list, strdup(vdir), fixed_count + expr_count);
list->buf = Emalloc(sizeof(void *) * 3);
list->buf[0] = buf[0];
list->buf[1] = buf[1];
- list->buf[2] = vdir;
+ list->buf[2] = list->root.d;
list->buf_count = 3;
MatchList_appendFiles(list, 0, fixed_files, fixed_count, false);
char const *tmp = entries[i]->d_name;
size_t l = strlen(tmp);
char vname[sizeof("./") + l];
- struct MatchVserverInfo vserver = { vname, true };
+ struct MatchVserverInfo vserver = {
+ .name = vname,
+ .use_pkgmgmt = true
+ };
+
+ if (!MatchVserverInfo_init(&vserver)) {
+ WRITE_MSG(2, "failed to initialize unification of reference vserver\n");
+ exit(1);
+ }
memcpy(vname, "./", 2);
memcpy(vname+2, tmp, l+1);
- if (!MatchList_initByVserver((*lst)+i, &vserver, 0)) {
+ if (!MatchList_initByVserver((*lst)+i, &vserver)) {
WRITE_MSG(2, "unification for reference vserver not configured\n");
exit(1);
}
free(entries[i]);
+ MatchVserverInfo_free(&vserver);
}
free(entries);
#include "pathinfo.h"
#include "string.h"
+#include "pathinfo.h"
+
+#include <lib/vserver.h>
#include <stdlib.h>
#include <stdbool.h>
struct MatchVserverInfo
{
char const *name;
+
+ vcCfgStyle style;
+ PathInfo vdir;
+ PathInfo appdir;
+
bool use_pkgmgmt;
};
void MatchList_init(struct MatchList *, char const *root,
size_t count) NONNULL((1,2));
bool MatchList_initByVserver(struct MatchList *,
- struct MatchVserverInfo const *vserver,
- char const **res_appdir) NONNULL((1,2));
+ struct MatchVserverInfo const *vserver) NONNULL((1,2));
void MatchList_initManually(struct MatchList *list,
struct MatchVserverInfo const *vserver,
char const *vdir,
- char const *exclude_file) NONNULL((1,3,4));
+ char const *exclude_file) NONNULL((1,4));
void MatchList_initRefserverList(struct MatchList **, size_t *cnt,
char const *dir) NONNULL((1,2,3));
void MatchList_destroy(struct MatchList *) NONNULL((1));
void MatchList_printId(struct MatchList const *, int fd) NONNULL((1));
+
+bool MatchVserverInfo_init(struct MatchVserverInfo *);
+void MatchVserverInfo_free(struct MatchVserverInfo *);
+
#endif // H_UTIL_VSERVER_LIB_INTERNAL_MATCHLIST_H