[pacman-dev] [PATCH] Warn but don't error for unknown pacman.conf directives

Dan McGee dan at archlinux.org
Wed Mar 16 20:09:29 EDT 2011


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 at archlinux.org>
---

For maint. Requested by Xavier, +1 from Allan.

-Dan

 src/pacman/pacman.c |   50 ++++++++++++++++++++++++--------------------------
 1 files changed, 24 insertions(+), 26 deletions(-)

diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index 984bd1b..a520338 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;
 			}
 		}
 
-- 
1.7.4.1



More information about the pacman-dev mailing list