Merge 2.1 in 2.2

Merge 2.1 in 2.2
This commit is contained in:
MassimilianoPinto
2017-11-29 11:30:33 +01:00
parent ba22e3b1db
commit 8a10b72e4d
8 changed files with 195 additions and 25 deletions

View File

@ -2567,7 +2567,7 @@ int maxscale_getline(char** dest, int* size, FILE* file)
char* destptr = *dest;
int offset = 0;
if (feof(file))
if (feof(file) || ferror(file))
{
return 0;
}
@ -2590,11 +2590,18 @@ int maxscale_getline(char** dest, int* size, FILE* file)
}
}
if ((destptr[offset] = fgetc(file)) == '\n' || feof(file))
int c = fgetc(file);
if ((c == '\n') || (c == EOF))
{
destptr[offset] = '\0';
break;
}
else
{
destptr[offset] = c;
}
offset++;
}

View File

@ -153,8 +153,9 @@ static bool file_write_header(FILE* outfile);
static bool file_write_footer(FILE* outfile);
static void write_footer(void);
static int ntfw_cb(const char*, const struct stat*, int, struct FTW*);
static bool file_is_readable(const char* absolute_pathname);
static bool file_is_writable(const char* absolute_pathname);
static bool is_file_and_readable(const char* absolute_pathname);
static bool path_is_readable(const char* absolute_pathname);
static bool path_is_writable(const char* absolute_pathname);
bool handle_path_arg(char** dest, const char* path, const char* arg, bool rd, bool wr);
static bool handle_debug_args(char* args);
static void set_log_augmentation(const char* value);
@ -733,7 +734,7 @@ static bool resolve_maxscale_conf_fname(char** cnf_full_path,
*cnf_full_path = get_expanded_pathname(NULL, home_dir, default_cnf_fname);
}
return *cnf_full_path && file_is_readable(*cnf_full_path);
return *cnf_full_path && is_file_and_readable(*cnf_full_path);
}
/**
@ -762,7 +763,7 @@ static char* check_dir_access(char* dirname, bool rd, bool wr)
goto retblock;
}
if (rd && !file_is_readable(dirname))
if (rd && !path_is_readable(dirname))
{
snprintf(errbuf, PATH_MAX * 2 - 1, "MaxScale doesn't have read permission "
"to '%s'.", dirname);
@ -771,7 +772,7 @@ static char* check_dir_access(char* dirname, bool rd, bool wr)
goto retblock;
}
if (wr && !file_is_writable(dirname))
if (wr && !path_is_writable(dirname))
{
snprintf(errbuf, PATH_MAX * 2 - 1, "MaxScale doesn't have write permission "
"to '%s'.", dirname);
@ -827,12 +828,54 @@ static void print_log_n_stderr(
}
}
/**
* Check that a path refers to a readable file.
*
* @param absolute_pathname The path to check.
* @return True if the path refers to a readable file. is readable
*/
static bool is_file_and_readable(const char* absolute_pathname)
{
bool rv = false;
struct stat info;
if (stat(absolute_pathname, &info) == 0)
{
if ((info.st_mode & S_IFMT) == S_IFREG)
{
// There is a race here as the file can be deleted and a directory
// created in its stead between the stat() call here and the access()
// call in file_is_readable().
rv = path_is_readable(absolute_pathname);
}
else
{
const char FORMAT[] = "'%s' does not refer to a regular file.";
char buff[sizeof(FORMAT) + strlen(absolute_pathname)];
snprintf(buff, sizeof(buff), FORMAT, absolute_pathname);
print_log_n_stderr(true, true, buff, buff, 0);
}
}
else
{
int eno = errno;
errno = 0;
const char FORMAT[] = "Could not access '%s'.";
char buff[sizeof(FORMAT) + strlen(absolute_pathname)];
snprintf(buff, sizeof(buff), FORMAT, absolute_pathname);
print_log_n_stderr(true, true, buff, buff, eno);
}
return rv;
}
/**
* Check if the file or directory is readable
* @param absolute_pathname Path of the file or directory to check
* @return True if file is readable
*/
static bool file_is_readable(const char* absolute_pathname)
static bool path_is_readable(const char* absolute_pathname)
{
bool succp = true;
@ -853,7 +896,7 @@ static bool file_is_readable(const char* absolute_pathname)
* @param absolute_pathname Path of the file or directory to check
* @return True if file is writable
*/
static bool file_is_writable(const char* absolute_pathname)
static bool path_is_writable(const char* absolute_pathname)
{
bool succp = true;
@ -949,7 +992,7 @@ static char* get_expanded_pathname(char** output_path,
}
snprintf(cnf_file_buf, pathlen, "%s/%s", expanded_path, fname);
if (!file_is_readable(cnf_file_buf))
if (!path_is_readable(cnf_file_buf))
{
MXS_FREE(expanded_path);
MXS_FREE(cnf_file_buf);
@ -964,7 +1007,7 @@ static char* get_expanded_pathname(char** output_path,
* If only directory was provided, check that it is
* readable.
*/
if (!file_is_readable(expanded_path))
if (!path_is_readable(expanded_path))
{
MXS_FREE(expanded_path);
expanded_path = NULL;