Skip to content

Commit

Permalink
Sanitize include option behaviour.
Browse files Browse the repository at this point in the history
If the file could not be opened/read/processed, print a message and
quit instead of completely silently ignoring it.


git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@34260 b3059339-0415-0410-9bf9-f77b7e298cf2
  • Loading branch information
reimar committed Oct 25, 2011
1 parent dee97d4 commit 073b1c3
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 12 deletions.
4 changes: 2 additions & 2 deletions gui/cfg.c
Expand Up @@ -260,7 +260,7 @@ int cfg_gui_include(m_option_t *conf, const char *filename)
{
(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)
Expand All @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions mencoder.c
Expand Up @@ -259,14 +259,14 @@ static void parse_cfgfiles( m_config_t* conf )
{
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);
}
Expand Down
2 changes: 1 addition & 1 deletion mpcommon.c
Expand Up @@ -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[] = {
Expand Down
6 changes: 3 additions & 3 deletions mplayer.c
Expand Up @@ -859,7 +859,7 @@ static void parse_cfgfiles(m_config_t *conf)
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);
Expand All @@ -879,7 +879,7 @@ static void parse_cfgfiles(m_config_t *conf)
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);
}
Expand Down Expand Up @@ -956,7 +956,7 @@ static int try_load_config(m_config_t *conf, const char *file)
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;
}

Expand Down
7 changes: 4 additions & 3 deletions parser-cfg.c
Expand Up @@ -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
Expand Down Expand Up @@ -96,9 +97,9 @@ int m_config_parse_config_file(m_config_t* config, const char *conffile)
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;
}

Expand Down
2 changes: 1 addition & 1 deletion parser-cfg.h
Expand Up @@ -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);

Expand Down

0 comments on commit 073b1c3

Please sign in to comment.