From 2641f638c2ce4b4c3ae1df3bc0464784d9829894 Mon Sep 17 00:00:00 2001 From: Enrico Scholz Date: Fri, 18 Mar 2005 00:20:02 +0000 Subject: [PATCH] applied lot of API changes git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@1912 94cd875c-1c1d-0410-91d2-eb244daf1a30 --- .../lib_internal/matchlist-initbyvserver.c | 47 ++++++---------------- util-vserver/lib_internal/matchlist-initmanually.c | 16 ++++++-- .../lib_internal/matchlist-initrefserverlist.c | 13 +++++- util-vserver/lib_internal/matchlist.h | 17 ++++++-- 4 files changed, 51 insertions(+), 42 deletions(-) diff --git a/util-vserver/lib_internal/matchlist-initbyvserver.c b/util-vserver/lib_internal/matchlist-initbyvserver.c index 20c3d64..14584c9 100644 --- a/util-vserver/lib_internal/matchlist-initbyvserver.c +++ b/util-vserver/lib_internal/matchlist-initbyvserver.c @@ -26,47 +26,26 @@ #include "vserver.h" - +#include 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; } diff --git a/util-vserver/lib_internal/matchlist-initmanually.c b/util-vserver/lib_internal/matchlist-initmanually.c index 7ce0b8e..8f29abb 100644 --- a/util-vserver/lib_internal/matchlist-initmanually.c +++ b/util-vserver/lib_internal/matchlist-initmanually.c @@ -157,10 +157,20 @@ MatchList_initManually(struct MatchList *list, 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); @@ -182,11 +192,11 @@ MatchList_initManually(struct MatchList *list, 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); diff --git a/util-vserver/lib_internal/matchlist-initrefserverlist.c b/util-vserver/lib_internal/matchlist-initrefserverlist.c index ddf7509..2656671 100644 --- a/util-vserver/lib_internal/matchlist-initrefserverlist.c +++ b/util-vserver/lib_internal/matchlist-initrefserverlist.c @@ -64,17 +64,26 @@ MatchList_initRefserverList(struct MatchList **lst, size_t *cnt, 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); diff --git a/util-vserver/lib_internal/matchlist.h b/util-vserver/lib_internal/matchlist.h index f625f38..49a60ff 100644 --- a/util-vserver/lib_internal/matchlist.h +++ b/util-vserver/lib_internal/matchlist.h @@ -21,6 +21,9 @@ #include "pathinfo.h" #include "string.h" +#include "pathinfo.h" + +#include #include #include @@ -50,18 +53,22 @@ struct MatchList 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)); @@ -77,4 +84,8 @@ const * MatchList_find(struct MatchList const *, 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 -- 1.8.1.5