Skip to content

Commit 2153aaf

Browse files
committed
mariabackup : use die() macro for fatal exit with error message.
1 parent a8a27e6 commit 2153aaf

File tree

9 files changed

+63
-90
lines changed

9 files changed

+63
-90
lines changed

extra/mariabackup/backup_copy.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2221,7 +2221,7 @@ static void copy_or_move_dir(const char *from, const char *to, bool do_copy, boo
22212221
to, 1));
22222222
}
22232223
if (!rc)
2224-
exit(EXIT_FAILURE);
2224+
die("copy or move file failed");
22252225
}
22262226
datadir_iter_free(it);
22272227
datadir_node_free(&node);
@@ -2323,8 +2323,7 @@ static void rocksdb_backup_checkpoint()
23232323
if (backup_to_directory)
23242324
{
23252325
if (my_mkdir(rocksdb_backup_dir, 0777, MYF(0))){
2326-
msg("Can't create rocksdb backup directory %s", rocksdb_backup_dir);
2327-
exit(EXIT_FAILURE);
2326+
die("Can't create rocksdb backup directory %s", rocksdb_backup_dir);
23282327
}
23292328
}
23302329
copy_or_move_dir(rocksdb_checkpoint_dir, ROCKSDB_BACKUP_DIR, true, backup_to_directory);

extra/mariabackup/backup_mysql.cc

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,19 +167,19 @@ xb_mysql_query(MYSQL *connection, const char *query, bool use_result,
167167
MYSQL_RES *mysql_result = NULL;
168168

169169
if (mysql_query(connection, query)) {
170-
msg("Error: failed to execute query %s: %s", query, mysql_error(connection));
171170
if (die_on_error) {
172-
exit(EXIT_FAILURE);
171+
die("failed to execute query %s: %s", query, mysql_error(connection));
172+
} else {
173+
msg("Error: failed to execute query %s: %s", query, mysql_error(connection));
173174
}
174175
return(NULL);
175176
}
176177

177178
/* store result set on client if there is a result */
178179
if (mysql_field_count(connection) > 0) {
179180
if ((mysql_result = mysql_store_result(connection)) == NULL) {
180-
msg("Error: failed to fetch query result %s: %s",
181+
die("failed to fetch query result %s: %s",
181182
query, mysql_error(connection));
182-
exit(EXIT_FAILURE);
183183
}
184184

185185
if (!use_result) {
@@ -910,8 +910,7 @@ DECLARE_THREAD(kill_mdl_waiters_thread(void *))
910910
row[1], row[2], row[0]);
911911
snprintf(query, sizeof(query), "KILL QUERY %s", row[0]);
912912
if (mysql_query(mysql, query) && (mysql_errno(mysql) != ER_NO_SUCH_THREAD)) {
913-
msg("Error: failed to execute query %s: %s", query,mysql_error(mysql));
914-
exit(EXIT_FAILURE);
913+
die("failed to execute query %s: %s", query,mysql_error(mysql));
915914
}
916915
}
917916
mysql_free_result(result);

extra/mariabackup/common.h

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,7 @@ static inline int asprintf(char **strp, const char *fmt,...)
8686

8787
#define XB_DELTA_INFO_SUFFIX ".meta"
8888

89-
90-
static inline int msg1(unsigned int thread_num, const char *fmt, ...) ATTRIBUTE_FORMAT(printf, 2, 3);
91-
static inline int msg1(uint thread_num, const char *fmt, va_list args)
89+
static inline int msg1(uint thread_num, const char *prefix, const char *fmt, va_list args)
9290
{
9391
int result;
9492
time_t t = time(NULL);
@@ -98,35 +96,44 @@ static inline int msg1(uint thread_num, const char *fmt, va_list args)
9896
result = vasprintf(&line, fmt, args);
9997
if (result != -1) {
10098
if (fmt && fmt[strlen(fmt)] != '\n')
101-
result = fprintf(stderr, "[%02u] %s %s\n", thread_num, date, line);
99+
result = fprintf(stderr, "[%02u] %s%s %s\n", thread_num, prefix, date, line);
102100
else
103-
result = fprintf(stderr, "[%02u] %s %s", thread_num, date, line);
101+
result = fprintf(stderr, "[%02u] %s%s %s", thread_num, prefix, date, line);
104102
free(line);
105103
}
106104
return result;
107105
}
108-
static inline int msg(unsigned int, const char *fmt, ...) ATTRIBUTE_FORMAT(printf, 2, 3);
109-
static inline int msg(unsigned int thread_num, const char *fmt, ...)
106+
107+
static inline ATTRIBUTE_FORMAT(printf, 2, 3) int msg(unsigned int thread_num, const char *fmt, ...)
110108
{
111109
int result;
112110
va_list args;
113111
va_start(args, fmt);
114-
result = msg1(thread_num, fmt, args);
112+
result = msg1(thread_num,"", fmt, args);
115113
va_end(args);
116114
return result;
117115
}
118116

119-
static inline int msg(const char *fmt, ...) ATTRIBUTE_FORMAT(printf, 1, 2);
120-
static inline int msg(const char *fmt, ...)
117+
static inline ATTRIBUTE_FORMAT(printf, 1, 2) int msg(const char *fmt, ...)
121118
{
122119
int result;
123120
va_list args;
124121
va_start(args, fmt);
125-
result = msg1(0, fmt, args);
122+
result = msg1(0, "", fmt, args);
126123
va_end(args);
127124
return result;
128125
}
129126

127+
static inline ATTRIBUTE_FORMAT(printf, 1,2) ATTRIBUTE_NORETURN void die(const char *fmt, ...)
128+
{
129+
va_list args;
130+
va_start(args, fmt);
131+
msg1(0, "FATAL ERROR: ", fmt, args);
132+
va_end(args);
133+
fflush(stderr);
134+
_exit(EXIT_FAILURE);
135+
}
136+
130137

131138
/* Use POSIX_FADV_NORMAL when available */
132139

extra/mariabackup/datasink.cc

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ ds_create(const char *root, ds_type_t type)
4848
#ifdef HAVE_LIBARCHIVE
4949
ds = &datasink_archive;
5050
#else
51-
msg("Error : mariabackup was built without libarchive support");
52-
exit(EXIT_FAILURE);
51+
die("mariabackup was built without libarchive support");
5352
#endif
5453
break;
5554
case DS_TYPE_XBSTREAM:
@@ -60,8 +59,7 @@ ds_create(const char *root, ds_type_t type)
6059
break;
6160
case DS_TYPE_ENCRYPT:
6261
case DS_TYPE_DECRYPT:
63-
msg("Error : mariabackup does not support encrypted backups.");
64-
exit(EXIT_FAILURE);
62+
die("mariabackup does not support encrypted backups.");
6563
break;
6664

6765
case DS_TYPE_TMPFILE:
@@ -80,8 +78,7 @@ ds_create(const char *root, ds_type_t type)
8078
if (ctxt != NULL) {
8179
ctxt->datasink = ds;
8280
} else {
83-
msg("Error: failed to initialize datasink.");
84-
exit(EXIT_FAILURE);
81+
die("failed to initialize datasink.");
8582
}
8683

8784
return ctxt;

extra/mariabackup/ds_buffer.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ buffer_open(ds_ctxt_t *ctxt, const char *path, MY_STAT *mystat)
9696

9797
dst_file = ds_open(pipe_ctxt, path, mystat);
9898
if (dst_file == NULL) {
99-
exit(EXIT_FAILURE);
99+
die("ds_open(%s) failed", path);
100100
}
101101

102102
buffer_ctxt = (ds_buffer_ctxt_t *) ctxt->ptr;

extra/mariabackup/ds_tmpfile.cc

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -195,41 +195,37 @@ tmpfile_deinit(ds_ctxt_t *ctxt)
195195
/* Stat the file to replace size and mtime on the original
196196
* mystat struct */
197197
if (my_fstat(tmp_file->fd, &mystat, MYF(0))) {
198-
msg("error: my_fstat() failed.");
199-
exit(EXIT_FAILURE);
198+
die("my_fstat() failed.");
200199
}
201200
tmp_file->mystat.st_size = mystat.st_size;
202201
tmp_file->mystat.st_mtime = mystat.st_mtime;
203202

204203
dst_file = ds_open(pipe_ctxt, tmp_file->orig_path,
205204
&tmp_file->mystat);
206205
if (dst_file == NULL) {
207-
msg("error: could not stream a temporary file to "
206+
die("could not stream a temporary file to "
208207
"'%s'", tmp_file->orig_path);
209-
exit(EXIT_FAILURE);
210208
}
211209

212210
/* copy to the destination datasink */
213211
posix_fadvise(tmp_file->fd, 0, 0, POSIX_FADV_SEQUENTIAL);
214212
if (my_seek(tmp_file->fd, 0, SEEK_SET, MYF(0)) ==
215213
MY_FILEPOS_ERROR) {
216-
msg("error: my_seek() failed for '%s', errno = %d.",
214+
die("my_seek() failed for '%s', errno = %d.",
217215
tmp_file->file->path, my_errno);
218-
exit(EXIT_FAILURE);
219216
}
220217
offset = 0;
221218
while ((bytes = my_read(tmp_file->fd, (unsigned char *)buf, buf_size,
222219
MYF(MY_WME))) > 0) {
223220
posix_fadvise(tmp_file->fd, offset, buf_size, POSIX_FADV_DONTNEED);
224221
offset += buf_size;
225222
if (ds_write(dst_file, buf, bytes)) {
226-
msg("error: cannot write to stream for '%s'.",
223+
die("cannot write to stream for '%s'.",
227224
tmp_file->orig_path);
228-
exit(EXIT_FAILURE);
229225
}
230226
}
231227
if (bytes == (size_t) -1) {
232-
exit(EXIT_FAILURE);
228+
die("my_read failed for %s", tmp_file->orig_path);
233229
}
234230

235231
my_close(tmp_file->fd, MYF(MY_WME));

extra/mariabackup/encryption_plugin.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ static std::string get_encryption_plugin_from_cnf()
4545
FILE *f = fopen("backup-my.cnf", "r");
4646
if (!f)
4747
{
48-
msg("Can't open backup-my.cnf for reading");
49-
exit(EXIT_FAILURE);
48+
die("Can't open backup-my.cnf for reading");
5049
}
5150
char line[512];
5251
std::string plugin_load;

extra/mariabackup/wsrep.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ xb_write_galera_info(bool incremental_prepare)
193193
fp = fopen(XB_GALERA_INFO_FILENAME, "w");
194194
if (fp == NULL) {
195195

196-
msg("mariabackup: error: "
196+
die(
197197
"could not create " XB_GALERA_INFO_FILENAME
198198
", errno = %d\n",
199199
errno);
@@ -207,11 +207,10 @@ xb_write_galera_info(bool incremental_prepare)
207207

208208
if (fprintf(fp, "%s:%lld", uuid_str, (long long) seqno) < 0) {
209209

210-
msg("mariabackup: error: "
210+
die(
211211
"could not write to " XB_GALERA_INFO_FILENAME
212212
", errno = %d\n",
213-
errno);
214-
exit(EXIT_FAILURE);
213+
errno);;
215214
}
216215

217216
fclose(fp);

0 commit comments

Comments
 (0)