From: Victor Julien Date: Tue, 9 Jul 2013 15:47:58 +0000 (+0200) Subject: Yaml: give a more detailed error if the user supplies a directory instead of a yaml... X-Git-Tag: suricata-2.0beta1~33 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=164d60e8cdcd3117228f9c0f1bd50eb1f684d97e;p=thirdparty%2Fsuricata.git Yaml: give a more detailed error if the user supplies a directory instead of a yaml file. Bug #803. --- diff --git a/src/conf-yaml-loader.c b/src/conf-yaml-loader.c index eb76286505..b90a29af46 100644 --- a/src/conf-yaml-loader.c +++ b/src/conf-yaml-loader.c @@ -236,13 +236,22 @@ ConfYamlLoadFile(const char *filename) ConfNode *root = ConfGetRootNode(); if (yaml_parser_initialize(&parser) != 1) { - fprintf(stderr, "Failed to initialize yaml parser.\n"); + SCLogError(SC_ERR_FATAL, "failed to initialize yaml parser."); return -1; } + struct stat stat_buf; + if (stat(filename, &stat_buf) == 0) { + if (stat_buf.st_mode & S_IFDIR) { + SCLogError(SC_ERR_FATAL, "yaml argument is not a file but a directory: %s. " + "Please specify the yaml file in your -c option.", filename); + return -1; + } + } + infile = fopen(filename, "r"); if (infile == NULL) { - fprintf(stderr, "Failed to open file: %s: %s\n", filename, + SCLogError(SC_ERR_FATAL, "failed to open file: %s: %s", filename, strerror(errno)); yaml_parser_delete(&parser); return -1;