# HG changeset patch # User Michiel Broek # Date 1578252843 -3600 # Node ID 93848540442ce878b2dc6949d8c538aee53f6c37 # Parent fc276025d0476fb3ffb88c7498b831872ccac852 Try to solve the MySQL 2014 error. diff -r fc276025d047 -r 93848540442c bmsd/mysql.c --- a/bmsd/mysql.c Sun Jan 05 20:17:48 2020 +0100 +++ b/bmsd/mysql.c Sun Jan 05 20:34:03 2020 +0100 @@ -768,46 +768,65 @@ +/* + * Check using a new MySQL connection because we are running from another thread. + */ void ispindel_mysql_check(void) { sys_ispindel_list *tmpp; + MYSQL *con2 = NULL; + MYSQL_RES *res_set2; + MYSQL_ROW row2; if (ispindels == NULL) return; - if (mysql_query(con, "SELECT uuid,alias,beercode,beername,beeruuid,mode FROM mon_ispindels;")) { - syslog(LOG_NOTICE, "MySQL: SELECT uuid,alias,beercode,beername,beeruuid,mode FROM mon_ispindels error %u (%s))", mysql_errno(con), mysql_error(con)); + con2 = mysql_init(NULL); + if (con2 == NULL) { + syslog(LOG_NOTICE, "MySQL: mysql_init() failed"); + return; + } + + if (mysql_real_connect(con2, Config.mysql_host, Config.mysql_user, Config.mysql_pass, Config.mysql_database, Config.mysql_port, NULL, 0) == NULL) { + syslog(LOG_NOTICE, "MySQL: mysql_real_connect() %s", mysql_error(con2)); + return; + } + + if (mysql_query(con2, "SELECT uuid,alias,beercode,beername,beeruuid,mode FROM mon_ispindels;")) { + syslog(LOG_NOTICE, "MySQL: SELECT uuid,alias,beercode,beername,beeruuid,mode FROM mon_ispindels error %u (%s))", mysql_errno(con2), mysql_error(con2)); } else { - res_set = mysql_store_result(con); - if (res_set == NULL) { - syslog(LOG_NOTICE, "MySQL: mysq_store_result error %u (%s))", mysql_errno(con), mysql_error(con)); + res_set2 = mysql_store_result(con2); + if (res_set2 == NULL) { + syslog(LOG_NOTICE, "MySQL: mysq_store_result error %u (%s))", mysql_errno(con2), mysql_error(con2)); } else { - while ((row = mysql_fetch_row(res_set)) != NULL) { + while ((row2 = mysql_fetch_row(res_set2)) != NULL) { for (tmpp = ispindels; tmpp; tmpp = tmpp->next) { - if (strcmp(tmpp->uuid, row[0]) == 0) { - if (strcmp(tmpp->beercode, row[2]) || strcmp(tmpp->beername, row[3]) || strcmp(tmpp->beeruuid, row[4])) { - syslog(LOG_NOTICE, "ispindel `%s` change beer to `%s %s`", row[1], row[2], row[3]); + if (strcmp(tmpp->uuid, row2[0]) == 0) { + if (strcmp(tmpp->beercode, row2[2]) || strcmp(tmpp->beername, row2[3]) || strcmp(tmpp->beeruuid, row2[4])) { + syslog(LOG_NOTICE, "ispindel `%s` change beer to `%s %s`", row2[1], row2[2], row2[3]); if (tmpp->beercode) free(tmpp->beercode); - tmpp->beercode = xstrcpy(row[2]); + tmpp->beercode = xstrcpy(row2[2]); if (tmpp->beername) free(tmpp->beername); - tmpp->beername = xstrcpy(row[3]); + tmpp->beername = xstrcpy(row2[3]); if (tmpp->beeruuid) free(tmpp->beeruuid); - tmpp->beeruuid = xstrcpy(row[4]); + tmpp->beeruuid = xstrcpy(row2[4]); } - if (strcmp(tmpp->mode, row[5])) { - syslog(LOG_NOTICE, "ispindel `%s` change mode `%s`", row[1], row[5]); + if (strcmp(tmpp->mode, row2[5])) { + syslog(LOG_NOTICE, "ispindel `%s` change mode `%s`", row2[1], row2[5]); if (tmpp->mode) free(tmpp->mode); - tmpp->mode = xstrcpy(row[5]); + tmpp->mode = xstrcpy(row2[5]); } } } } - mysql_free_result(res_set); + mysql_free_result(res_set2); } } + + mysql_close(con2); }