| 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.h" |
|---|
| 25 |
|
|---|
| 26 |
#include <pathconfig.h> |
|---|
| 27 |
|
|---|
| 28 |
#include <string.h> |
|---|
| 29 |
#include <unistd.h> |
|---|
| 30 |
#include <stdlib.h> |
|---|
| 31 |
#include <assert.h> |
|---|
| 32 |
#include <sys/param.h> |
|---|
| 33 |
|
|---|
| 34 |
static bool |
|---|
| 35 |
exists(char *path, size_t len, char const *name) |
|---|
| 36 |
{ |
|---|
| 37 |
if (name) strcpy(path + len, name); |
|---|
| 38 |
|
|---|
| 39 |
return access(path, R_OK)!=-1; |
|---|
| 40 |
} |
|---|
| 41 |
|
|---|
| 42 |
#define EXISTS(X) exists(X, sizeof(X)-1, 0) |
|---|
| 43 |
#define DEFAULT_EXISTS(X) EXISTS(CONFDIR "/.defaults/apps/vunify/" X) |
|---|
| 44 |
|
|---|
| 45 |
bool |
|---|
| 46 |
MatchVserverInfo_init(struct MatchVserverInfo *info) |
|---|
| 47 |
{ |
|---|
| 48 |
assert(info->name!=0); |
|---|
| 49 |
assert(info->vdir.d==0 && info->appdir.d==0); |
|---|
| 50 |
|
|---|
| 51 |
info->style = vc_getVserverCfgStyle(info->name); |
|---|
| 52 |
info->vdir.d = vc_getVserverVdir (info->name, info->style, true); |
|---|
| 53 |
info->appdir.d = vc_getVserverAppDir (info->name, info->style, "vunify"); |
|---|
| 54 |
|
|---|
| 55 |
if (info->vdir.d==0 || info->appdir.d==0) { |
|---|
| 56 |
free(const_cast(char *)(info->vdir.d)); |
|---|
| 57 |
free(const_cast(char *)(info->appdir.d)); |
|---|
| 58 |
|
|---|
| 59 |
return false; |
|---|
| 60 |
} |
|---|
| 61 |
|
|---|
| 62 |
info->vdir.l = strlen(info->vdir.d); |
|---|
| 63 |
info->appdir.l = strlen(info->appdir.d); |
|---|
| 64 |
|
|---|
| 65 |
size_t const l = info->appdir.l; |
|---|
| 66 |
char tmp[l + MAX(sizeof("/pkgmgmt-ignore"),sizeof("/pkgmgmt-force"))]; |
|---|
| 67 |
|
|---|
| 68 |
memcpy(tmp, info->appdir.d, l); |
|---|
| 69 |
|
|---|
| 70 |
if (exists(tmp, l, "/pkgmgmt-ignore")) info->use_pkgmgmt = false; |
|---|
| 71 |
else if (exists(tmp, l, "/pkgmgmt-force")) info->use_pkgmgmt = true; |
|---|
| 72 |
else if (DEFAULT_EXISTS ("pkgmgmt-ignore")) info->use_pkgmgmt = false; |
|---|
| 73 |
else if (DEFAULT_EXISTS ("pkgmgmt-force")) info->use_pkgmgmt = true; |
|---|
| 74 |
|
|---|
| 75 |
return true; |
|---|
| 76 |
} |
|---|