26 #include <sys/utsname.h>
27 #include <sys/types.h>
35 #include "xbps_api_impl.h"
53 if (strcmp(xh->
rootdir,
"/") == 0)
65 if (strcmp(xh->
rootdir,
"/") == 0)
86 vpkgdir = strdup(
"/etc/xbps/virtualpkg.d");
88 if ((dirp = opendir(vpkgdir)) == NULL) {
89 xbps_dbg_printf(xh,
"config: failed to open %s: %s\n",
90 vpkgdir, strerror(errno));
94 while ((dp = readdir(dirp)) != NULL) {
95 if ((strcmp(dp->d_name,
"..") == 0) ||
96 (strcmp(dp->d_name,
".") == 0))
99 if ((ext = strrchr(dp->d_name,
'.')) == NULL)
101 if (strcmp(ext,
".conf") == 0) {
105 fp = fopen(path,
"r");
108 if (cfg_parse_fp(xh->cfg, fp) != 0) {
109 xbps_error_printf(
"Failed to parse "
110 "vpkg conf file %s:\n", dp->d_name);
120 cb_validate_virtual(cfg_t *cfg, cfg_opt_t *opt)
124 for (i = 0; i < cfg_size(cfg,
"virtual-package"); i++) {
125 cfg_t *sec = cfg_opt_getnsec(opt, i);
126 if (cfg_getstr(sec,
"targets") == 0) {
127 cfg_error(cfg,
"targets must be set for "
128 "virtual-package %s", cfg_title(sec));
138 cfg_opt_t vpkg_opts[] = {
139 CFG_STR_LIST(__UNCONST(
"targets"), NULL, CFGF_NONE),
144 CFG_STR(__UNCONST(
"rootdir"), __UNCONST(
"/"), CFGF_NONE),
145 CFG_STR(__UNCONST(
"cachedir"),
146 __UNCONST(XBPS_CACHE_PATH), CFGF_NONE),
147 CFG_INT(__UNCONST(
"FetchCacheConnections"),
148 XBPS_FETCH_CACHECONN, CFGF_NONE),
149 CFG_INT(__UNCONST(
"FetchCacheConnectionsPerHost"),
150 XBPS_FETCH_CACHECONN_HOST, CFGF_NONE),
151 CFG_INT(__UNCONST(
"FetchTimeoutConnection"),
152 XBPS_FETCH_TIMEOUT, CFGF_NONE),
153 CFG_BOOL(__UNCONST(
"syslog"),
true, CFGF_NONE),
154 CFG_STR_LIST(__UNCONST(
"repositories"), NULL, CFGF_MULTI),
155 CFG_STR_LIST(__UNCONST(
"PackagesOnHold"), NULL, CFGF_MULTI),
156 CFG_SEC(__UNCONST(
"virtual-package"),
157 vpkg_opts, CFGF_MULTI|CFGF_TITLE),
158 CFG_FUNC(__UNCONST(
"include"), &cfg_include),
163 bool syslog_enabled =
false;
167 if (xhp->initialized)
174 xhp->cfg = cfg_init(opts, CFGF_NOCASE);
175 cfg_set_validate_func(xhp->cfg,
"virtual-package", &cb_validate_virtual);
177 if ((rv = cfg_parse(xhp->cfg, xhp->
conffile)) != CFG_SUCCESS) {
178 if (rv == CFG_FILE_ERROR) {
188 if (xhp->repository) {
193 if ((rv = cfg_parse_buf(xhp->cfg, buf)) != 0)
197 }
else if (rv == CFG_PARSE_ERROR) {
205 xbps_dbg_printf(xhp,
"Configuration file: %s\n",
212 if (xhp->cfg == NULL)
215 xhp->
rootdir = cfg_getstr(xhp->cfg,
"rootdir");
219 char *buf, path[PATH_MAX-1];
221 if (getcwd(path,
sizeof(path)) == NULL)
230 if (xhp->cfg == NULL)
233 xhp->
cachedir = cfg_getstr(xhp->cfg,
"cachedir");
235 if ((xhp->cachedir_priv = set_cachedir(xhp)) == NULL)
239 if ((xhp->metadir_priv = set_metadir(xhp)) == NULL)
241 xhp->
metadir = xhp->metadir_priv;
244 xhp->un_machine = strdup(un.machine);
245 assert(xhp->un_machine);
247 if (xhp->cfg == NULL) {
248 xhp->
flags |= XBPS_FLAG_SYSLOG;
250 cc = XBPS_FETCH_CACHECONN;
251 cch = XBPS_FETCH_CACHECONN_HOST;
253 if (cfg_getbool(xhp->cfg,
"syslog"))
254 xhp->
flags |= XBPS_FLAG_SYSLOG;
255 xhp->
fetch_timeout = cfg_getint(xhp->cfg,
"FetchTimeoutConnection");
256 cc = cfg_getint(xhp->cfg,
"FetchCacheConnections");
257 cch = cfg_getint(xhp->cfg,
"FetchCacheConnectionsPerHost");
259 if (xhp->
flags & XBPS_FLAG_SYSLOG)
260 syslog_enabled =
true;
263 config_inject_vpkgs(xhp);
265 xbps_fetch_set_cache_connection(cc, cch);
267 xbps_dbg_printf(xhp,
"Rootdir=%s\n", xhp->
rootdir);
268 xbps_dbg_printf(xhp,
"Metadir=%s\n", xhp->
metadir);
269 xbps_dbg_printf(xhp,
"Cachedir=%s\n", xhp->
cachedir);
270 xbps_dbg_printf(xhp,
"FetchTimeout=%u\n", xhp->
fetch_timeout);
271 xbps_dbg_printf(xhp,
"FetchCacheconn=%u\n", cc);
272 xbps_dbg_printf(xhp,
"FetchCacheconnHost=%u\n", cch);
273 xbps_dbg_printf(xhp,
"Syslog=%u\n", syslog_enabled);
274 xbps_dbg_printf(xhp,
"Architecture: %s\n", xhp->un_machine);
276 xhp->initialized =
true;
286 if (!xhp->initialized)
289 xbps_pkgdb_release(xhp);
290 xbps_rpool_release(xhp);
291 xbps_fetch_unset_cache_connection();
292 if (xhp->pkgdb_revdeps != NULL)
293 prop_object_release(xhp->pkgdb_revdeps);
296 free(xhp->cachedir_priv);
297 free(xhp->metadir_priv);
298 free(xhp->un_machine);
300 xhp->initialized =
false;
305 common_printf(FILE *f,
const char *msg,
const char *fmt, va_list ap)
308 fprintf(f,
"%s", msg);
310 vfprintf(f, fmt, ap);
314 xbps_dbg_printf_append(
struct xbps_handle *xhp,
const char *fmt, ...)
318 if ((xhp->
flags & XBPS_FLAG_DEBUG) == 0)
322 common_printf(stderr, NULL, fmt, ap);
327 xbps_dbg_printf(
struct xbps_handle *xhp,
const char *fmt, ...)
331 if ((xhp->
flags & XBPS_FLAG_DEBUG) == 0)
335 common_printf(stderr,
"[DEBUG] ", fmt, ap);
340 xbps_error_printf(
const char *fmt, ...)
345 common_printf(stderr,
"ERROR: ", fmt, ap);
350 xbps_warn_printf(
const char *fmt, ...)
355 common_printf(stderr,
"WARNING: ", fmt, ap);