1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-30 16:24:05 +03:00

MDEV-3816 init-file stops getting executed if a long enough line is encountered; on a debug version, assertion `! is_set() || can_overwrite_status' fails

backport improved bootstrap error handling from 5.6

Was:
  revno: 3768.1.1
  committer: Christopher Powers <chris.powers@oracle.com>
  timestamp: Wed 2012-05-02 22:16:40 -0500
  message:
    Bug#11766342 INITIAL DB CREATION FAILS ON WINDOWS WITH AN ASSERT IN SQL_ERROR.CC
    Improved bootstrap error handling:
    - Detect and report file i/o errors
    - Report query size errors with nearest query text
This commit is contained in:
Sergei Golubchik
2012-12-16 21:11:24 +01:00
parent 1679fe1c3e
commit fe7c2aaeea
9 changed files with 127 additions and 30 deletions

View File

@ -65,9 +65,12 @@ static void die(const char *fmt, ...)
exit(1);
}
char *fgets_fn(char *buffer, size_t size, fgets_input_t input)
char *fgets_fn(char *buffer, size_t size, fgets_input_t input, int *error)
{
return fgets(buffer, size, (FILE*) input);
char *line= fgets(buffer, size, (FILE*) input);
if (error)
*error= (line == NULL) ? ferror((FILE*)input) : 0;
return line;
}
static void print_query(FILE *out, const char *query)
@ -116,6 +119,8 @@ int main(int argc, char *argv[])
char* outfile_name= argv[3];
int rc;
int query_length;
int error= 0;
char *err_ptr;
if (argc != 4)
die("Usage: comp_sql <struct_name> <sql_filename> <c_filename>");
@ -136,14 +141,34 @@ int main(int argc, char *argv[])
for ( ; ; )
{
rc= read_bootstrap_query(query, &query_length,
(fgets_input_t) in, fgets_fn);
(fgets_input_t) in, fgets_fn, &error);
if (rc == READ_BOOTSTRAP_ERROR)
die("Failed to read the bootstrap input file.\n");
if (rc == READ_BOOTSTRAP_EOF)
break;
if (rc != READ_BOOTSTRAP_SUCCESS)
{
/* Get the most recent query text for reference. */
err_ptr= query + (query_length <= MAX_BOOTSTRAP_ERROR_LEN ?
0 : (query_length - MAX_BOOTSTRAP_ERROR_LEN));
switch (rc)
{
case READ_BOOTSTRAP_ERROR:
die("Failed to read the bootstrap input file. Return code (%d).\n"
"Last query: '%s'\n", error, err_ptr);
break;
case READ_BOOTSTRAP_QUERY_SIZE:
die("Failed to read the boostrap input file. Query size exceeded %d bytes.\n"
"Last query: '%s'.\n", MAX_BOOTSTRAP_LINE_SIZE, err_ptr);
break;
default:
die("Failed to read the boostrap input file. Unknown error.\n");
break;
}
}
print_query(out, query);
}