summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2011-03-16 19:03:52 -0500
committerDan McGee <dan@archlinux.org>2011-03-16 19:52:54 -0500
commit3707d5bc468dcd8611073d22b24d6f6be19bbe94 (patch)
treecb62ac6373e4ef43bfe2217fcb1d5be161062534
parent40a6c5c5eca05b5f65b1dc0c6d5c87fcd313fb2e (diff)
downloadpacman-3707d5bc468dcd8611073d22b24d6f6be19bbe94.tar.xz
Warn but don't error for unknown pacman.conf directives
This makes all the pacman developers' jobs harder as we have to switch files whenever running multiple pacman versions and are using newly introduced options. Instead of erroring out, print warnings and continue on. This patch also fixes a const-correctness issue. We immediately cast a 'const char *' to a 'char *' in setrepeatingoption(), which is just plain wrong as we manipulate the underlying string. Fix the types and remove the now unnecessary variable. Finally, a few messages change here for consistency and clarity and because we continue parsing rather than bailing out on a problem. Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r--src/pacman/pacman.c50
1 files changed, 24 insertions, 26 deletions
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index 073a0175..55f99a66 100644
--- a/src/pacman/pacman.c
+++ b/src/pacman/pacman.c
@@ -817,21 +817,20 @@ static void option_add_cleanmethod(const char *value) {
* @param option the string (friendly) name of the option, used for messages
* @param optionfunc a function pointer to an alpm_option_add_* function
*/
-static void setrepeatingoption(const char *ptr, const char *option,
+static void setrepeatingoption(char *ptr, const char *option,
void (*optionfunc)(const char*))
{
- char *p = (char*)ptr;
char *q;
- while((q = strchr(p, ' '))) {
+ while((q = strchr(ptr, ' '))) {
*q = '\0';
- (*optionfunc)(p);
- pm_printf(PM_LOG_DEBUG, "config: %s: %s\n", option, p);
- p = q;
- p++;
+ (*optionfunc)(ptr);
+ pm_printf(PM_LOG_DEBUG, "config: %s: %s\n", option, ptr);
+ ptr = q;
+ ptr++;
}
- (*optionfunc)(p);
- pm_printf(PM_LOG_DEBUG, "config: %s: %s\n", option, p);
+ (*optionfunc)(ptr);
+ pm_printf(PM_LOG_DEBUG, "config: %s: %s\n", option, ptr);
}
static char *get_filename(const char *url) {
@@ -954,7 +953,8 @@ cleanup:
return(ret);
}
-static int _parse_options(char *key, char *value)
+static int _parse_options(const char *key, char *value,
+ const char *file, int linenum)
{
if(value == NULL) {
/* options without settings */
@@ -976,8 +976,9 @@ static int _parse_options(char *key, char *value)
} else if(strcmp(key, "CheckSpace") == 0) {
alpm_option_set_checkspace(1);
} else {
- pm_printf(PM_LOG_ERROR, _("directive '%s' without value not recognized\n"), key);
- return(1);
+ pm_printf(PM_LOG_WARNING,
+ _("config file %s, line %d: directive '%s' in section '%s' not recognized.\n"),
+ file, linenum, key, "options");
}
} else {
/* options with settings */
@@ -1028,8 +1029,10 @@ static int _parse_options(char *key, char *value)
} else if (strcmp(key, "CleanMethod") == 0) {
setrepeatingoption(value, "CleanMethod", option_add_cleanmethod);
} else {
- pm_printf(PM_LOG_ERROR, _("directive '%s' with a value not recognized\n"), key);
- return(1);
+
+ pm_printf(PM_LOG_WARNING,
+ _("config file %s, line %d: directive '%s' in section '%s' not recognized.\n"),
+ file, linenum, key, "options");
}
}
@@ -1163,7 +1166,7 @@ static int _parseconfig(const char *file, const char *givensection,
/* Include is allowed in both options and repo sections */
if(strcmp(key, "Include") == 0) {
if(value == NULL) {
- pm_printf(PM_LOG_ERROR, _("config file %s, line %d: directive %s needs a value\n"),
+ pm_printf(PM_LOG_ERROR, _("config file %s, line %d: directive '%s' needs a value\n"),
file, linenum, key);
ret = 1;
goto cleanup;
@@ -1175,12 +1178,12 @@ static int _parseconfig(const char *file, const char *givensection,
switch(globret) {
case GLOB_NOSPACE:
pm_printf(PM_LOG_DEBUG,
- "config file %s, line %d: include globing out of space\n",
+ "config file %s, line %d: include globbing out of space\n",
file, linenum);
break;
case GLOB_ABORTED:
pm_printf(PM_LOG_DEBUG,
- "config file %s, line %d: include globing read error for %s\n",
+ "config file %s, line %d: include globbing read error for %s\n",
file, linenum, value);
break;
case GLOB_NOMATCH:
@@ -1201,18 +1204,14 @@ static int _parseconfig(const char *file, const char *givensection,
}
if(strcmp(section, "options") == 0) {
/* we are either in options ... */
- if((ret = _parse_options(key, value)) != 0) {
- pm_printf(PM_LOG_ERROR, _("config file %s, line %d: problem in options section\n"),
- file, linenum);
- ret = 1;
+ if((ret = _parse_options(key, value, file, linenum)) != 0) {
goto cleanup;
}
- continue;
} else {
/* ... or in a repo section */
if(strcmp(key, "Server") == 0) {
if(value == NULL) {
- pm_printf(PM_LOG_ERROR, _("config file %s, line %d: directive %s needs a value\n"),
+ pm_printf(PM_LOG_ERROR, _("config file %s, line %d: directive '%s' needs a value\n"),
file, linenum, key);
ret = 1;
goto cleanup;
@@ -1222,10 +1221,9 @@ static int _parseconfig(const char *file, const char *givensection,
goto cleanup;
}
} else {
- pm_printf(PM_LOG_ERROR, _("config file %s, line %d: directive '%s' in repository section '%s' not recognized.\n"),
+ pm_printf(PM_LOG_WARNING,
+ _("config file %s, line %d: directive '%s' in section '%s' not recognized.\n"),
file, linenum, key, section);
- ret = 1;
- goto cleanup;
}
}