4 * Copyright (c) 2006-2011 Pacman Development Team <pacman-dev@archlinux.org>
5 * Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 #include <fcntl.h> /* open */
29 #include <string.h> /* strdup */
31 #include <sys/types.h>
32 #include <sys/utsname.h> /* uname */
41 /* global config variable */
42 config_t
*config
= NULL
;
44 config_t
*config_new(void)
46 config_t
*newconfig
= calloc(1, sizeof(config_t
));
48 pm_printf(ALPM_LOG_ERROR
,
49 _("malloc failure: could not allocate %zd bytes\n"),
53 /* defaults which may get overridden later */
54 newconfig
->op
= PM_OP_MAIN
;
55 newconfig
->logmask
= ALPM_LOG_ERROR
| ALPM_LOG_WARNING
;
56 newconfig
->configfile
= strdup(CONFFILE
);
57 if(alpm_capabilities() & ALPM_CAPABILITY_SIGNATURES
) {
58 newconfig
->siglevel
= ALPM_SIG_PACKAGE
| ALPM_SIG_PACKAGE_OPTIONAL
|
59 ALPM_SIG_DATABASE
| ALPM_SIG_DATABASE_OPTIONAL
;
65 int config_free(config_t
*oldconfig
)
67 if(oldconfig
== NULL
) {
71 alpm_list_free(oldconfig
->explicit_adds
);
72 alpm_list_free(oldconfig
->explicit_removes
);
74 FREELIST(oldconfig
->holdpkg
);
75 FREELIST(oldconfig
->syncfirst
);
76 FREELIST(oldconfig
->ignorepkg
);
77 FREELIST(oldconfig
->ignoregrp
);
78 FREELIST(oldconfig
->noupgrade
);
79 FREELIST(oldconfig
->noextract
);
80 free(oldconfig
->configfile
);
81 free(oldconfig
->rootdir
);
82 free(oldconfig
->dbpath
);
83 free(oldconfig
->logfile
);
84 free(oldconfig
->gpgdir
);
85 FREELIST(oldconfig
->cachedirs
);
86 free(oldconfig
->xfercommand
);
87 free(oldconfig
->print_format
);
88 free(oldconfig
->arch
);
94 /** Helper function for download_with_xfercommand() */
95 static char *get_filename(const char *url
) {
96 char *filename
= strrchr(url
, '/');
97 if(filename
!= NULL
) {
103 /** Helper function for download_with_xfercommand() */
104 static char *get_destfile(const char *path
, const char *filename
) {
106 /* len = localpath len + filename len + null */
107 size_t len
= strlen(path
) + strlen(filename
) + 1;
108 destfile
= calloc(len
, sizeof(char));
109 snprintf(destfile
, len
, "%s%s", path
, filename
);
114 /** Helper function for download_with_xfercommand() */
115 static char *get_tempfile(const char *path
, const char *filename
) {
117 /* len = localpath len + filename len + '.part' len + null */
118 size_t len
= strlen(path
) + strlen(filename
) + 6;
119 tempfile
= calloc(len
, sizeof(char));
120 snprintf(tempfile
, len
, "%s%s.part", path
, filename
);
125 /** External fetch callback */
126 static int download_with_xfercommand(const char *url
, const char *localpath
,
132 char *parsedcmd
,*tempcmd
;
133 char *destfile
, *tempfile
, *filename
;
135 if(!config
->xfercommand
) {
139 filename
= get_filename(url
);
143 destfile
= get_destfile(localpath
, filename
);
144 tempfile
= get_tempfile(localpath
, filename
);
146 if(force
&& stat(tempfile
, &st
) == 0) {
149 if(force
&& stat(destfile
, &st
) == 0) {
153 tempcmd
= strdup(config
->xfercommand
);
154 /* replace all occurrences of %o with fn.part */
155 if(strstr(tempcmd
, "%o")) {
157 parsedcmd
= strreplace(tempcmd
, "%o", tempfile
);
161 /* replace all occurrences of %u with the download URL */
162 parsedcmd
= strreplace(tempcmd
, "%u", url
);
165 /* save the cwd so we can restore it later */
167 cwdfd
= open(".", O_RDONLY
);
168 } while(cwdfd
== -1 && errno
== EINTR
);
170 pm_printf(ALPM_LOG_ERROR
, _("could not get current working directory\n"));
173 /* cwd to the download directory */
174 if(chdir(localpath
)) {
175 pm_printf(ALPM_LOG_WARNING
, _("could not chdir to download directory %s\n"), localpath
);
179 /* execute the parsed command via /bin/sh -c */
180 pm_printf(ALPM_LOG_DEBUG
, "running command: %s\n", parsedcmd
);
181 retval
= system(parsedcmd
);
184 pm_printf(ALPM_LOG_WARNING
, _("running XferCommand: fork failed!\n"));
186 } else if(retval
!= 0) {
187 /* download failed */
188 pm_printf(ALPM_LOG_DEBUG
, "XferCommand command returned non-zero status "
189 "code (%d)\n", retval
);
192 /* download was successful */
195 if(rename(tempfile
, destfile
)) {
196 pm_printf(ALPM_LOG_ERROR
, _("could not rename %s to %s (%s)\n"),
197 tempfile
, destfile
, strerror(errno
));
204 /* restore the old cwd if we have it */
207 if(fchdir(cwdfd
) != 0) {
208 pm_printf(ALPM_LOG_ERROR
, _("could not restore working directory (%s)\n"),
213 } while(ret
== -1 && errno
== EINTR
);
217 /* hack to let an user the time to cancel a download */
228 int config_set_arch(const char *arch
)
230 if(strcmp(arch
, "auto") == 0) {
233 config
->arch
= strdup(un
.machine
);
235 config
->arch
= strdup(arch
);
237 pm_printf(ALPM_LOG_DEBUG
, "config: arch: %s\n", config
->arch
);
242 * Parse a signature verification level line.
243 * @param values the list of parsed option values
244 * @param storage location to store the derived signature level; any existing
245 * value here is used as a starting point
246 * @param file path to the config file
247 * @param linenum current line number in file
248 * @return 0 on success, 1 on any parsing error
250 static int process_siglevel(alpm_list_t
*values
, alpm_siglevel_t
*storage
,
251 const char *file
, int linenum
)
253 alpm_siglevel_t level
= *storage
;
257 /* Collapse the option names into a single bitmasked value */
258 for(i
= values
; i
; i
= alpm_list_next(i
)) {
259 const char *original
= i
->data
, *value
;
260 int package
= 0, database
= 0;
262 if (strncmp(original
, "Package", strlen("Package")) == 0) {
263 /* only packages are affected, don't flip flags for databases */
264 value
= original
+ strlen("Package");
266 } else if (strncmp(original
, "Database", strlen("Database")) == 0) {
267 /* only databases are affected, don't flip flags for packages */
268 value
= original
+ strlen("Database");
271 /* no prefix, so anything found will affect both packages and dbs */
273 package
= database
= 1;
276 /* now parse out and store actual flag if it is valid */
277 if(strcmp(value
, "Never") == 0) {
279 level
&= ~ALPM_SIG_PACKAGE
;
282 level
&= ~ALPM_SIG_DATABASE
;
284 } else if(strcmp(value
, "Optional") == 0) {
286 level
|= ALPM_SIG_PACKAGE
;
287 level
|= ALPM_SIG_PACKAGE_OPTIONAL
;
290 level
|= ALPM_SIG_DATABASE
;
291 level
|= ALPM_SIG_DATABASE_OPTIONAL
;
293 } else if(strcmp(value
, "Required") == 0) {
295 level
|= ALPM_SIG_PACKAGE
;
296 level
&= ~ALPM_SIG_PACKAGE_OPTIONAL
;
299 level
|= ALPM_SIG_DATABASE
;
300 level
&= ~ALPM_SIG_DATABASE_OPTIONAL
;
302 } else if(strcmp(value
, "TrustedOnly") == 0) {
304 level
&= ~ALPM_SIG_PACKAGE_MARGINAL_OK
;
305 level
&= ~ALPM_SIG_PACKAGE_UNKNOWN_OK
;
308 level
&= ~ALPM_SIG_DATABASE_MARGINAL_OK
;
309 level
&= ~ALPM_SIG_DATABASE_UNKNOWN_OK
;
311 } else if(strcmp(value
, "TrustAll") == 0) {
313 level
|= ALPM_SIG_PACKAGE_MARGINAL_OK
;
314 level
|= ALPM_SIG_PACKAGE_UNKNOWN_OK
;
317 level
|= ALPM_SIG_DATABASE_MARGINAL_OK
;
318 level
|= ALPM_SIG_DATABASE_UNKNOWN_OK
;
321 pm_printf(ALPM_LOG_ERROR
,
322 _("config file %s, line %d: invalid value for '%s' : '%s'\n"),
323 file
, linenum
, "SigLevel", original
);
326 level
&= ~ALPM_SIG_USE_DEFAULT
;
329 /* ensure we have sig checking ability and are actually turning it on */
330 if(!(alpm_capabilities() & ALPM_CAPABILITY_SIGNATURES
) &&
331 level
& (ALPM_SIG_PACKAGE
| ALPM_SIG_DATABASE
)) {
332 pm_printf(ALPM_LOG_ERROR
,
333 _("config file %s, line %d: '%s' option invalid, no signature support\n"),
334 file
, linenum
, "SigLevel");
344 static int process_cleanmethods(alpm_list_t
*values
,
345 const char *file
, int linenum
)
348 for(i
= values
; i
; i
= alpm_list_next(i
)) {
349 const char *value
= i
->data
;
350 if(strcmp(value
, "KeepInstalled") == 0) {
351 config
->cleanmethod
|= PM_CLEAN_KEEPINST
;
352 } else if(strcmp(value
, "KeepCurrent") == 0) {
353 config
->cleanmethod
|= PM_CLEAN_KEEPCUR
;
355 pm_printf(ALPM_LOG_ERROR
,
356 _("config file %s, line %d: invalid value for '%s' : '%s'\n"),
357 file
, linenum
, "CleanMethod", value
);
364 /** Add repeating options such as NoExtract, NoUpgrade, etc to libalpm
365 * settings. Refactored out of the parseconfig code since all of them did
366 * the exact same thing and duplicated code.
367 * @param ptr a pointer to the start of the multiple options
368 * @param option the string (friendly) name of the option, used for messages
369 * @param list the list to add the option to
371 static void setrepeatingoption(char *ptr
, const char *option
,
376 while((q
= strchr(ptr
, ' '))) {
378 *list
= alpm_list_add(*list
, strdup(ptr
));
379 pm_printf(ALPM_LOG_DEBUG
, "config: %s: %s\n", option
, ptr
);
383 *list
= alpm_list_add(*list
, strdup(ptr
));
384 pm_printf(ALPM_LOG_DEBUG
, "config: %s: %s\n", option
, ptr
);
387 static int _parse_options(const char *key
, char *value
,
388 const char *file
, int linenum
)
391 /* options without settings */
392 if(strcmp(key
, "UseSyslog") == 0) {
393 config
->usesyslog
= 1;
394 pm_printf(ALPM_LOG_DEBUG
, "config: usesyslog\n");
395 } else if(strcmp(key
, "ILoveCandy") == 0) {
397 pm_printf(ALPM_LOG_DEBUG
, "config: chomp\n");
398 } else if(strcmp(key
, "VerbosePkgLists") == 0) {
399 config
->verbosepkglists
= 1;
400 pm_printf(ALPM_LOG_DEBUG
, "config: verbosepkglists\n");
401 } else if(strcmp(key
, "UseDelta") == 0) {
402 config
->usedelta
= 1;
403 pm_printf(ALPM_LOG_DEBUG
, "config: usedelta\n");
404 } else if(strcmp(key
, "TotalDownload") == 0) {
405 config
->totaldownload
= 1;
406 pm_printf(ALPM_LOG_DEBUG
, "config: totaldownload\n");
407 } else if(strcmp(key
, "CheckSpace") == 0) {
408 config
->checkspace
= 1;
410 pm_printf(ALPM_LOG_WARNING
,
411 _("config file %s, line %d: directive '%s' in section '%s' not recognized.\n"),
412 file
, linenum
, key
, "options");
415 /* options with settings */
416 if(strcmp(key
, "NoUpgrade") == 0) {
417 setrepeatingoption(value
, "NoUpgrade", &(config
->noupgrade
));
418 } else if(strcmp(key
, "NoExtract") == 0) {
419 setrepeatingoption(value
, "NoExtract", &(config
->noextract
));
420 } else if(strcmp(key
, "IgnorePkg") == 0) {
421 setrepeatingoption(value
, "IgnorePkg", &(config
->ignorepkg
));
422 } else if(strcmp(key
, "IgnoreGroup") == 0) {
423 setrepeatingoption(value
, "IgnoreGroup", &(config
->ignoregrp
));
424 } else if(strcmp(key
, "HoldPkg") == 0) {
425 setrepeatingoption(value
, "HoldPkg", &(config
->holdpkg
));
426 } else if(strcmp(key
, "SyncFirst") == 0) {
427 setrepeatingoption(value
, "SyncFirst", &(config
->syncfirst
));
428 } else if(strcmp(key
, "CacheDir") == 0) {
429 setrepeatingoption(value
, "CacheDir", &(config
->cachedirs
));
430 } else if(strcmp(key
, "Architecture") == 0) {
432 config_set_arch(value
);
434 } else if(strcmp(key
, "DBPath") == 0) {
435 /* don't overwrite a path specified on the command line */
436 if(!config
->dbpath
) {
437 config
->dbpath
= strdup(value
);
438 pm_printf(ALPM_LOG_DEBUG
, "config: dbpath: %s\n", value
);
440 } else if(strcmp(key
, "RootDir") == 0) {
441 /* don't overwrite a path specified on the command line */
442 if(!config
->rootdir
) {
443 config
->rootdir
= strdup(value
);
444 pm_printf(ALPM_LOG_DEBUG
, "config: rootdir: %s\n", value
);
446 } else if(strcmp(key
, "GPGDir") == 0) {
447 if(!config
->gpgdir
) {
448 config
->gpgdir
= strdup(value
);
449 pm_printf(ALPM_LOG_DEBUG
, "config: gpgdir: %s\n", value
);
451 } else if(strcmp(key
, "LogFile") == 0) {
452 if(!config
->logfile
) {
453 config
->logfile
= strdup(value
);
454 pm_printf(ALPM_LOG_DEBUG
, "config: logfile: %s\n", value
);
456 } else if(strcmp(key
, "XferCommand") == 0) {
457 config
->xfercommand
= strdup(value
);
458 pm_printf(ALPM_LOG_DEBUG
, "config: xfercommand: %s\n", value
);
459 } else if(strcmp(key
, "CleanMethod") == 0) {
460 alpm_list_t
*methods
= NULL
;
461 setrepeatingoption(value
, "CleanMethod", &methods
);
462 if(process_cleanmethods(methods
, file
, linenum
)) {
467 } else if(strcmp(key
, "SigLevel") == 0) {
468 alpm_list_t
*values
= NULL
;
469 setrepeatingoption(value
, "SigLevel", &values
);
470 if(process_siglevel(values
, &config
->siglevel
, file
, linenum
)) {
476 pm_printf(ALPM_LOG_WARNING
,
477 _("config file %s, line %d: directive '%s' in section '%s' not recognized.\n"),
478 file
, linenum
, key
, "options");
485 static int _add_mirror(alpm_db_t
*db
, char *value
)
487 const char *dbname
= alpm_db_get_name(db
);
488 /* let's attempt a replacement for the current repo */
489 char *temp
= strreplace(value
, "$repo", dbname
);
490 /* let's attempt a replacement for the arch */
491 const char *arch
= config
->arch
;
494 server
= strreplace(temp
, "$arch", arch
);
497 if(strstr(temp
, "$arch")) {
499 pm_printf(ALPM_LOG_ERROR
,
500 _("mirror '%s' contains the '%s' variable, but no '%s' is defined.\n"),
501 value
, "$arch", "Architecture");
507 if(alpm_db_add_server(db
, server
) != 0) {
508 /* pm_errno is set by alpm_db_setserver */
509 pm_printf(ALPM_LOG_ERROR
, _("could not add server URL to database '%s': %s (%s)\n"),
510 dbname
, server
, alpm_strerror(alpm_errno(config
->handle
)));
519 /** Sets up libalpm global stuff in one go. Called after the command line
520 * and inital config file parsing. Once this is complete, we can see if any
521 * paths were defined. If a rootdir was defined and nothing else, we want all
522 * of our paths to live under the rootdir that was specified. Safe to call
523 * multiple times (will only do anything the first time).
525 static int setup_libalpm(void)
529 alpm_handle_t
*handle
;
531 pm_printf(ALPM_LOG_DEBUG
, "setup_libalpm called\n");
533 /* Configure root path first. If it is set and dbpath/logfile were not
534 * set, then set those as well to reside under the root. */
535 if(config
->rootdir
) {
537 if(!config
->dbpath
) {
538 snprintf(path
, PATH_MAX
, "%s/%s", config
->rootdir
, DBPATH
+ 1);
539 config
->dbpath
= strdup(path
);
541 if(!config
->logfile
) {
542 snprintf(path
, PATH_MAX
, "%s/%s", config
->rootdir
, LOGFILE
+ 1);
543 config
->logfile
= strdup(path
);
546 config
->rootdir
= strdup(ROOTDIR
);
547 if(!config
->dbpath
) {
548 config
->dbpath
= strdup(DBPATH
);
552 /* initialize library */
553 handle
= alpm_initialize(config
->rootdir
, config
->dbpath
, &err
);
555 pm_printf(ALPM_LOG_ERROR
, _("failed to initialize alpm library (%s)\n"),
557 if(err
== ALPM_ERR_DB_VERSION
) {
558 pm_printf(ALPM_LOG_ERROR
, _(" try running pacman-db-upgrade\n"));
562 config
->handle
= handle
;
564 alpm_option_set_logcb(handle
, cb_log
);
565 alpm_option_set_dlcb(handle
, cb_dl_progress
);
566 alpm_option_set_eventcb(handle
, cb_event
);
567 alpm_option_set_questioncb(handle
, cb_question
);
568 alpm_option_set_progresscb(handle
, cb_progress
);
570 config
->logfile
= config
->logfile
? config
->logfile
: strdup(LOGFILE
);
571 ret
= alpm_option_set_logfile(handle
, config
->logfile
);
573 pm_printf(ALPM_LOG_ERROR
, _("problem setting logfile '%s' (%s)\n"),
574 config
->logfile
, alpm_strerror(alpm_errno(handle
)));
578 /* Set GnuPG's home directory. This is not relative to rootdir, even if
579 * rootdir is defined. Reasoning: gpgdir contains configuration data. */
580 config
->gpgdir
= config
->gpgdir
? config
->gpgdir
: strdup(GPGDIR
);
581 ret
= alpm_option_set_gpgdir(handle
, config
->gpgdir
);
583 pm_printf(ALPM_LOG_ERROR
, _("problem setting gpgdir '%s' (%s)\n"),
584 config
->gpgdir
, alpm_strerror(alpm_errno(handle
)));
588 /* add a default cachedir if one wasn't specified */
589 if(config
->cachedirs
== NULL
) {
590 alpm_option_add_cachedir(handle
, CACHEDIR
);
592 alpm_option_set_cachedirs(handle
, config
->cachedirs
);
595 alpm_option_set_default_siglevel(handle
, config
->siglevel
);
597 if(config
->xfercommand
) {
598 alpm_option_set_fetchcb(handle
, download_with_xfercommand
);
599 } else if(!(alpm_capabilities() & ALPM_CAPABILITY_DOWNLOADER
)) {
600 pm_printf(ALPM_LOG_WARNING
, _("no '%s' configured"), "XferCommand");
603 if(config
->totaldownload
) {
604 alpm_option_set_totaldlcb(handle
, cb_dl_total
);
607 alpm_option_set_arch(handle
, config
->arch
);
608 alpm_option_set_checkspace(handle
, config
->checkspace
);
609 alpm_option_set_usesyslog(handle
, config
->usesyslog
);
610 alpm_option_set_usedelta(handle
, config
->usedelta
);
612 alpm_option_set_ignorepkgs(handle
, config
->ignorepkg
);
613 alpm_option_set_ignoregroups(handle
, config
->ignoregrp
);
614 alpm_option_set_noupgrades(handle
, config
->noupgrade
);
615 alpm_option_set_noextracts(handle
, config
->noextract
);
621 * Allows parsing in advance of an entire config section before we start
622 * calling library methods.
625 /* useful for all sections */
628 /* db section option gathering */
629 alpm_siglevel_t siglevel
;
630 alpm_list_t
*servers
;
634 * Wrap up a section once we have reached the end of it. This should be called
635 * when a subsequent section is encountered, or when we have reached the end of
636 * the root config file. Once called, all existing saved config pieces on the
637 * section struct are freed.
638 * @param section the current parsed and saved section data
639 * @param parse_options whether we are parsing options or repo data
640 * @return 0 on success, 1 on failure
642 static int finish_section(struct section_t
*section
, int parse_options
)
648 pm_printf(ALPM_LOG_DEBUG
, "config: finish section '%s'\n", section
->name
);
650 /* parsing options (or nothing)- nothing to do except free the pieces */
651 if(!section
->name
|| parse_options
|| section
->is_options
) {
655 /* if we are not looking at options sections only, register a db */
656 db
= alpm_db_register_sync(config
->handle
, section
->name
, section
->siglevel
);
658 pm_printf(ALPM_LOG_ERROR
, _("could not register '%s' database (%s)\n"),
659 section
->name
, alpm_strerror(alpm_errno(config
->handle
)));
664 for(i
= section
->servers
; i
; i
= alpm_list_next(i
)) {
665 char *value
= i
->data
;
666 if(_add_mirror(db
, value
) != 0) {
667 pm_printf(ALPM_LOG_ERROR
,
668 _("could not add mirror '%s' to database '%s' (%s)\n"),
669 value
, section
->name
, alpm_strerror(alpm_errno(config
->handle
)));
677 alpm_list_free(section
->servers
);
678 section
->servers
= NULL
;
679 section
->siglevel
= ALPM_SIG_USE_DEFAULT
;
681 section
->name
= NULL
;
685 /** The "real" parseconfig. Each "Include" directive will recall this method so
686 * recursion and stack depth are limited to 10 levels. The publicly visible
687 * parseconfig calls this with a NULL section argument so we can recall from
688 * within ourself on an include.
689 * @param file path to the config file
690 * @param section the current active section
691 * @param parse_options whether to parse and call methods for the options
692 * section; if 0, parse and call methods for the repos sections
693 * @param depth the current recursion depth
694 * @return 0 on success, 1 on failure
696 static int _parseconfig(const char *file
, struct section_t
*section
,
697 int parse_options
, int depth
)
703 const int max_depth
= 10;
705 if(depth
>= max_depth
) {
706 pm_printf(ALPM_LOG_ERROR
,
707 _("config parsing exceeded max recursion depth of %d.\n"), max_depth
);
712 pm_printf(ALPM_LOG_DEBUG
, "config: attempting to read file %s\n", file
);
713 fp
= fopen(file
, "r");
715 pm_printf(ALPM_LOG_ERROR
, _("config file %s could not be read.\n"), file
);
720 while(fgets(line
, PATH_MAX
, fp
)) {
721 char *key
, *value
, *ptr
;
726 line_len
= strlen(line
);
728 /* ignore whole line and end of line comments */
729 if(line_len
== 0 || line
[0] == '#') {
732 if((ptr
= strchr(line
, '#'))) {
736 if(line
[0] == '[' && line
[line_len
- 1] == ']') {
738 /* only possibility here is a line == '[]' */
740 pm_printf(ALPM_LOG_ERROR
, _("config file %s, line %d: bad section name.\n"),
745 /* new config section, skip the '[' */
746 name
= strdup(line
+ 1);
747 name
[line_len
- 2] = '\0';
748 /* we're at a new section; perform any post-actions for the prior */
749 if(finish_section(section
, parse_options
)) {
753 pm_printf(ALPM_LOG_DEBUG
, "config: new section '%s'\n", name
);
754 section
->name
= name
;
755 section
->is_options
= (strcmp(name
, "options") == 0);
760 /* strsep modifies the 'line' string: 'key \0 value' */
768 pm_printf(ALPM_LOG_ERROR
, _("config file %s, line %d: syntax error in config file- missing key.\n"),
773 /* For each directive, compare to the camelcase string. */
774 if(section
->name
== NULL
) {
775 pm_printf(ALPM_LOG_ERROR
, _("config file %s, line %d: All directives must belong to a section.\n"),
780 /* Include is allowed in both options and repo sections */
781 if(strcmp(key
, "Include") == 0) {
787 pm_printf(ALPM_LOG_ERROR
, _("config file %s, line %d: directive '%s' needs a value\n"),
792 /* Ignore include failures... assume non-critical */
793 globret
= glob(value
, GLOB_NOCHECK
, NULL
, &globbuf
);
796 pm_printf(ALPM_LOG_DEBUG
,
797 "config file %s, line %d: include globbing out of space\n",
801 pm_printf(ALPM_LOG_DEBUG
,
802 "config file %s, line %d: include globbing read error for %s\n",
803 file
, linenum
, value
);
806 pm_printf(ALPM_LOG_DEBUG
,
807 "config file %s, line %d: no include found for %s\n",
808 file
, linenum
, value
);
811 for(gindex
= 0; gindex
< globbuf
.gl_pathc
; gindex
++) {
812 pm_printf(ALPM_LOG_DEBUG
, "config file %s, line %d: including %s\n",
813 file
, linenum
, globbuf
.gl_pathv
[gindex
]);
814 _parseconfig(globbuf
.gl_pathv
[gindex
], section
, parse_options
, depth
+ 1);
821 if(parse_options
&& section
->is_options
) {
822 /* we are either in options ... */
823 if((ret
= _parse_options(key
, value
, file
, linenum
)) != 0) {
826 } else if (!parse_options
&& !section
->is_options
) {
827 /* ... or in a repo section */
828 if(strcmp(key
, "Server") == 0) {
830 pm_printf(ALPM_LOG_ERROR
, _("config file %s, line %d: directive '%s' needs a value\n"),
835 section
->servers
= alpm_list_add(section
->servers
, strdup(value
));
836 } else if(strcmp(key
, "SigLevel") == 0) {
837 alpm_list_t
*values
= NULL
;
838 setrepeatingoption(value
, "SigLevel", &values
);
840 if(section
->siglevel
== ALPM_SIG_USE_DEFAULT
) {
841 section
->siglevel
= config
->siglevel
;
843 if(process_siglevel(values
, §ion
->siglevel
, file
, linenum
)) {
851 pm_printf(ALPM_LOG_WARNING
,
852 _("config file %s, line %d: directive '%s' in section '%s' not recognized.\n"),
853 file
, linenum
, key
, section
->name
);
859 ret
= finish_section(section
, parse_options
);
866 pm_printf(ALPM_LOG_DEBUG
, "config: finished parsing %s\n", file
);
870 /** Parse a configuration file.
871 * @param file path to the config file
872 * @return 0 on success, non-zero on error
874 int parseconfig(const char *file
)
877 struct section_t section
;
878 memset(§ion
, 0, sizeof(struct section_t
));
879 section
.siglevel
= ALPM_SIG_USE_DEFAULT
;
880 /* the config parse is a two-pass affair. We first parse the entire thing for
881 * the [options] section so we can get all default and path options set.
882 * Next, we go back and parse everything but [options]. */
884 /* call the real parseconfig function with a null section & db argument */
885 pm_printf(ALPM_LOG_DEBUG
, "parseconfig: options pass\n");
886 if((ret
= _parseconfig(file
, §ion
, 1, 0))) {
889 if((ret
= setup_libalpm())) {
892 /* second pass, repo section parsing */
893 pm_printf(ALPM_LOG_DEBUG
, "parseconfig: repo pass\n");
894 return _parseconfig(file
, §ion
, 0, 0);
897 /* vim: set ts=2 sw=2 noet: */