changeset 34172:5761a9a31bcb

Sanitize include option behaviour. If the file could not be opened/read/processed, print a message and quit instead of completely silently ignoring it.
author reimar
date Tue, 25 Oct 2011 20:45:09 +0000
parents cca4f430b0f4
children a5d8b198c214
files gui/cfg.c mencoder.c mpcommon.c mplayer.c parser-cfg.c parser-cfg.h
diffstat 6 files changed, 13 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/gui/cfg.c	Tue Oct 25 20:42:50 2011 +0000
+++ b/gui/cfg.c	Tue Oct 25 20:45:09 2011 +0000
@@ -260,7 +260,7 @@
 {
     (void)conf;
 
-    return m_config_parse_config_file(gui_conf, filename);
+    return m_config_parse_config_file(gui_conf, filename, 0);
 }
 
 int cfg_read(void)
@@ -285,7 +285,7 @@
 
     m_config_register_options(gui_conf, gui_opts);
 
-    if (!disable_gui_conf && (m_config_parse_config_file(gui_conf, cfg) < 0)) {
+    if (!disable_gui_conf && (m_config_parse_config_file(gui_conf, cfg, 1) < 0)) {
         gmp_msg(MSGT_GPLAYER, MSGL_ERR, MSGTR_ConfigFileError);
 // mplayer(MPLAYER_EXIT_GUI, 1, 0);
     }
--- a/mencoder.c	Tue Oct 25 20:42:50 2011 +0000
+++ b/mencoder.c	Tue Oct 25 20:45:09 2011 +0000
@@ -259,14 +259,14 @@
 {
   char *conffile;
   if (!disable_system_conf &&
-      m_config_parse_config_file(conf, MPLAYER_CONFDIR "/mencoder.conf") < 0)
+      m_config_parse_config_file(conf, MPLAYER_CONFDIR "/mencoder.conf", 1) < 0)
     mencoder_exit(1,MSGTR_ConfigFileError);
 
   if (!disable_user_conf) {
     if ((conffile = get_path("mencoder.conf")) == NULL) {
       mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_GetpathProblem);
     } else {
-      if (m_config_parse_config_file(conf, conffile) < 0)
+      if (m_config_parse_config_file(conf, conffile, 1) < 0)
         mencoder_exit(1,MSGTR_ConfigFileError);
       free(conffile);
     }
--- a/mpcommon.c	Tue Oct 25 20:42:50 2011 +0000
+++ b/mpcommon.c	Tue Oct 25 20:45:09 2011 +0000
@@ -418,7 +418,7 @@
 
 int cfg_include(m_option_t *conf, const char *filename)
 {
-    return m_config_parse_config_file(mconfig, filename);
+    return m_config_parse_config_file(mconfig, filename, 0);
 }
 
 const m_option_t noconfig_opts[] = {
--- a/mplayer.c	Tue Oct 25 20:42:50 2011 +0000
+++ b/mplayer.c	Tue Oct 25 20:45:09 2011 +0000
@@ -859,7 +859,7 @@
     char *conffile;
     int conffile_fd;
     if (!disable_system_conf &&
-        m_config_parse_config_file(conf, MPLAYER_CONFDIR "/mplayer.conf") < 0)
+        m_config_parse_config_file(conf, MPLAYER_CONFDIR "/mplayer.conf", 1) < 0)
         exit_player(EXIT_NONE);
     if ((conffile = get_path("")) == NULL) {
         mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_NoHomeDir);
@@ -879,7 +879,7 @@
                 close(conffile_fd);
             }
             if (!disable_user_conf &&
-                m_config_parse_config_file(conf, conffile) < 0)
+                m_config_parse_config_file(conf, conffile, 1) < 0)
                 exit_player(EXIT_NONE);
             free(conffile);
         }
@@ -956,7 +956,7 @@
     if (stat(file, &st))
         return 0;
     mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_LoadingConfig, file);
-    m_config_parse_config_file(conf, file);
+    m_config_parse_config_file(conf, file, 0);
     return 1;
 }
 
--- a/parser-cfg.c	Tue Oct 25 20:42:50 2011 +0000
+++ b/parser-cfg.c	Tue Oct 25 20:45:09 2011 +0000
@@ -50,9 +50,10 @@
 /// Setup the \ref Config from a config file.
 /** \param config The config object.
  *  \param conffile Path to the config file.
+ *  \param silent print message when failing to open file only at verbose level
  *  \return 1 on sucess, -1 on error.
  */
-int m_config_parse_config_file(m_config_t* config, const char *conffile)
+int m_config_parse_config_file(m_config_t* config, const char *conffile, int silent)
 {
 #define PRINT_LINENUM	mp_msg(MSGT_CFGPARSER,MSGL_V,"%s(%d): ", conffile, line_num)
 #define MAX_LINE_LEN	10000
@@ -96,9 +97,9 @@
 	mp_msg(MSGT_CFGPARSER,MSGL_V,"\n");
 
 	if ((fp = fopen(conffile, "r")) == NULL) {
-	  mp_msg(MSGT_CFGPARSER,MSGL_V,": %s\n", strerror(errno));
+	  mp_msg(MSGT_CFGPARSER,silent?MSGL_V:MSGL_ERR,"Failed to read %s: %s\n", conffile, strerror(errno));
 		free(line);
-		ret = 0;
+		ret = silent ? 0 : -1;
 		goto out;
 	}
 
--- a/parser-cfg.h	Tue Oct 25 20:42:50 2011 +0000
+++ b/parser-cfg.h	Tue Oct 25 20:45:09 2011 +0000
@@ -21,7 +21,7 @@
 
 #include "m_config.h"
 
-int m_config_parse_config_file(m_config_t* config, const char *conffile);
+int m_config_parse_config_file(m_config_t* config, const char *conffile, int silent);
 
 int m_config_preparse_command_line(m_config_t *config, int argc, char **argv);