Skip to content

Commit

Permalink
mx_mysql: Fix warning in mx_mysql_option_set_default_file
Browse files Browse the repository at this point in the history
If the file is not readable, the warning is now saved to be retrievable
by the caller instead of being emitted. The warning text has been
shortened from:

    MySQL ignoring defaults file: euidaccess("/etc/mxq/mysql_ro.cnfX", R_OK) failed: No such file or directory
    MySQL falling back to mysql default config search path.

to

    /etc/mxq/mysql_ro.cnfX: No such file or directory - falling back to mysql default config search path
  • Loading branch information
donald committed Dec 29, 2023
1 parent 9d04546 commit 2e80051
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions mx_mysql.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ static void mx_mysql_save_error(const char *err) {
strncpy(mx_mysql_last_error, err, len+1);
}

__attribute__ ((format (printf, 1, 2)))
static void mx_mysql_save_error_va(const char *restrict fmt, ...) {
char *s;
va_list ap;
va_start(ap, fmt);
int res = vasprintf(&s, fmt, ap);
va_end(ap);
if (res == -1)
return;
mx_mysql_save_error(s);
free(s);
}

char *mx_mysql_error(void) {
return mx_mysql_last_error == NULL ? "no error information" : mx_mysql_last_error;
}
Expand Down Expand Up @@ -614,8 +627,7 @@ int mx_mysql_option_set_default_file(struct mx_mysql *mysql, char *fname)
mx_assert_return_minus_errno(mysql, EINVAL);

if (fname && (*fname == '/') && (euidaccess(fname, R_OK) != 0)) {
mx_log_warning("MySQL ignoring defaults file: euidaccess(\"%s\", R_OK) failed: %m", fname);
mx_log_warning("MySQL falling back to mysql default config search path.");
mx_mysql_save_error_va("%s: %m - falling back to mysql default config search path", fname);
return -errno;
}

Expand Down

0 comments on commit 2e80051

Please sign in to comment.