Commit ad487518 authored by Marek Vavruša's avatar Marek Vavruša

conf: better handling of inaccessible/nonexistent config file

parent 819d8d5d
...@@ -35,7 +35,7 @@ const error_table_t knot_error_msgs[] = { ...@@ -35,7 +35,7 @@ const error_table_t knot_error_msgs[] = {
{ KNOT_ECONNREFUSED, "Connection refused." }, { KNOT_ECONNREFUSED, "Connection refused." },
{ KNOT_EISCONN, "Already connected." }, { KNOT_EISCONN, "Already connected." },
{ KNOT_EADDRINUSE, "Address already in use." }, { KNOT_EADDRINUSE, "Address already in use." },
{ KNOT_ENOENT, "Resource not found." }, { KNOT_ENOENT, "Not exists." },
{ KNOT_ERANGE, "Value is out of range." }, { KNOT_ERANGE, "Value is out of range." },
/* General errors. */ /* General errors. */
......
...@@ -817,21 +817,15 @@ const char* conf_find_default() ...@@ -817,21 +817,15 @@ const char* conf_find_default()
int conf_open(const char* path) int conf_open(const char* path)
{ {
/* Check path. */
if (!path) {
return KNOT_EINVAL;
}
/* Find real path of the config file */ /* Find real path of the config file */
char *config_realpath = realpath(path, NULL); char *config_realpath = realpath(path, NULL);
if (config_realpath == NULL) { if (config_realpath == NULL) {
return KNOT_ENOMEM; return knot_map_errno(EINVAL, ENOENT);
} }
/* Check if exists. */ /* Check if accessible. */
struct stat st; if (access(path, F_OK | R_OK) != 0) {
if (stat(config_realpath, &st) != 0) { return KNOT_EACCES;
return KNOT_ENOENT;
} }
/* Create new config. */ /* Create new config. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment