summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2014-06-27 11:11:36 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2014-06-27 11:14:32 (GMT)
commit74d7881ffee03618a693e839e3e1224c16526bd7 (patch) (side-by-side diff)
tree0fff4fc4911d525c3a1f294a4e13bb4fa3183a12
parentf42317d4c34b01ef1a78780723ab7445f8e9050c (diff)
downloadnssync-74d7881ffee03618a693e839e3e1224c16526bd7.tar.gz
nssync-74d7881ffee03618a693e839e3e1224c16526bd7.tar.bz2
Fix coredump if mysql is not in slave mode and slave status is requested.
* src/nssync.c (check_slave_status): Return if no status file is defined, or if sql_get_slave_status returned 1 (main): Call check_slave_status unconditionally. It will take care of the rest. * src/sqlop.c (sql_get_slave_status): Fail if any of file or off is NULL.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--src/nssync.c18
-rw-r--r--src/sqlop.c2
2 files changed, 14 insertions, 6 deletions
diff --git a/src/nssync.c b/src/nssync.c
index 75de83c..3eb5540 100644
--- a/src/nssync.c
+++ b/src/nssync.c
@@ -309,13 +309,22 @@ synchronize(struct nssync *sp)
void
check_slave_status()
{
- FILE *fp = fopen(slave_status_file, "r");
+ FILE *fp;
char *saved_file = NULL;
char *saved_off;
char *buf = NULL;
size_t size = 0;
char *sql_file, *sql_off;
+
+ if (!slave_status_file)
+ return;
+ if (sql_get_slave_status(&sql_file, &sql_off)) {
+ unlink(slave_status_file);
+ return;
+ }
+
+ fp = fopen(slave_status_file, "r");
if (fp) {
if (grecs_getline(&buf, &size, fp) > 0) {
buf[strlen(buf)-1] = 0;
@@ -327,9 +336,7 @@ check_slave_status()
fclose(fp);
}
- if (sql_get_slave_status(&sql_file, &sql_off))
- unlink(slave_status_file);
- else if (!force && saved_file && saved_off &&
+ if (!force && saved_file && saved_off &&
strcmp(sql_file, saved_file) == 0 &&
strcmp(sql_off, saved_off) == 0) {
debug(1, ("slave status hasn't changed: nothing to do"));
@@ -429,8 +436,7 @@ main(int argc, char **argv)
check_pidfile();
- if (slave_status_file)
- check_slave_status();
+ check_slave_status();
for (ep = synclist->head; ep; ep = ep->next)
synchronize(ep->data);
diff --git a/src/sqlop.c b/src/sqlop.c
index db53c45..00f4bc6 100644
--- a/src/sqlop.c
+++ b/src/sqlop.c
@@ -113,6 +113,8 @@ sql_get_slave_status(char **pfile, char **poff)
struct slave_status_info ssi = { NULL, NULL };
if (sql_do_query("SHOW SLAVE STATUS", read_slave_status, &ssi))
return 1;
+ if (!ssi.file || !ssi.off)
+ return 1;
*pfile = ssi.file;
*poff = ssi.off;
return 0;

Return to:

Send suggestions and report system problems to the System administrator.