[MPlayer-cvslog] r34260 - in trunk: gui/cfg.c mencoder.c mpcommon.c mplayer.c parser-cfg.c parser-cfg.h

reimar subversion at mplayerhq.hu
Tue Oct 25 22:45:09 CEST 2011


Author: reimar
Date: Tue Oct 25 22:45:09 2011
New Revision: 34260

Log:
Sanitize include option behaviour.
If the file could not be opened/read/processed, print a message and
quit instead of completely silently ignoring it.

Modified:
   trunk/gui/cfg.c
   trunk/mencoder.c
   trunk/mpcommon.c
   trunk/mplayer.c
   trunk/parser-cfg.c
   trunk/parser-cfg.h

Modified: trunk/gui/cfg.c
==============================================================================
--- trunk/gui/cfg.c	Tue Oct 25 22:42:50 2011	(r34259)
+++ trunk/gui/cfg.c	Tue Oct 25 22:45:09 2011	(r34260)
@@ -260,7 +260,7 @@ int cfg_gui_include(m_option_t *conf, co
 {
     (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 @@ int cfg_read(void)
 
     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);
     }

Modified: trunk/mencoder.c
==============================================================================
--- trunk/mencoder.c	Tue Oct 25 22:42:50 2011	(r34259)
+++ trunk/mencoder.c	Tue Oct 25 22:45:09 2011	(r34260)
@@ -259,14 +259,14 @@ static void parse_cfgfiles( m_config_t* 
 {
   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);
     }

Modified: trunk/mpcommon.c
==============================================================================
--- trunk/mpcommon.c	Tue Oct 25 22:42:50 2011	(r34259)
+++ trunk/mpcommon.c	Tue Oct 25 22:45:09 2011	(r34260)
@@ -418,7 +418,7 @@ int cfg_inc_verbose(m_option_t *conf)
 
 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[] = {

Modified: trunk/mplayer.c
==============================================================================
--- trunk/mplayer.c	Tue Oct 25 22:42:50 2011	(r34259)
+++ trunk/mplayer.c	Tue Oct 25 22:45:09 2011	(r34260)
@@ -859,7 +859,7 @@ static void parse_cfgfiles(m_config_t *c
     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 @@ static void parse_cfgfiles(m_config_t *c
                 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 @@ static int try_load_config(m_config_t *c
     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;
 }
 

Modified: trunk/parser-cfg.c
==============================================================================
--- trunk/parser-cfg.c	Tue Oct 25 22:42:50 2011	(r34259)
+++ trunk/parser-cfg.c	Tue Oct 25 22:45:09 2011	(r34260)
@@ -50,9 +50,10 @@ static int recursion_depth = 0;
 /// 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 @@ int m_config_parse_config_file(m_config_
 	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;
 	}
 

Modified: trunk/parser-cfg.h
==============================================================================
--- trunk/parser-cfg.h	Tue Oct 25 22:42:50 2011	(r34259)
+++ trunk/parser-cfg.h	Tue Oct 25 22:45:09 2011	(r34260)
@@ -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);
 


More information about the MPlayer-cvslog mailing list