From afc3e160a717158a0c8b82c3441b34a9c2944d57 Mon Sep 17 00:00:00 2001 From: Matthew Trescott Date: Wed, 21 Mar 2018 11:05:48 -0400 Subject: [PATCH 1/2] Fix the second part of #2064 (#2066) * Fix postinst with mysql. See bug #2064 * Fix mistake --- distros/ubuntu1604/zoneminder.postinst | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/distros/ubuntu1604/zoneminder.postinst b/distros/ubuntu1604/zoneminder.postinst index c462357fd..aa947c09c 100644 --- a/distros/ubuntu1604/zoneminder.postinst +++ b/distros/ubuntu1604/zoneminder.postinst @@ -30,25 +30,27 @@ if [ "$1" = "configure" ]; then # # Get mysql started if it isn't running # - $(systemctl status mysql.service >/dev/null 2>&1); MYSQL_STATUS=$? - $(systemctl status mariadb.service >/dev/null 2>&1); MARIADB_STATUS=$? - # 3 = inactive, 4 = nonexistant - if [ "$MARIADB_STATUS" != "4" ]; then + if [ -e "/lib/systemd/system/mariadb.service" ]; then DBSERVICE="mariadb.service" else DBSERVICE="mysql.service" fi + if systemctl is-failed --quiet $DBSERVICE; then + echo "$DBSERVICE is in a failed state; it will not be started." + echo "If you have already resolved the problem preventing $DBSERVICE from running," + echo "run sudo systemctl restart $DBSERVICE then run sudo dpkg-reconfigure zoneminder." + exit 1 + fi - if [ "$MYSQL_STATUS" != "0" ] && [ "$MARIADB_STATUS" != "0" ]; then - # 3 = inactive, 4 = nonexistant + if ! systemctl is-active --quiet mysql.service mariadb.service; then # Due to /etc/init.d service autogeneration, mysql.service always returns the status of mariadb.service # However, mariadb.service will not return the status of mysql.service. deb-systemd-invoke start $DBSERVICE fi # Make sure systemctl status exit code is 0; i.e. the DB is running - if systemctl status "$DBSERVICE" >/dev/null 2>&1; then + if systemctl is-active --quiet "$DBSERVICE"; then mysqladmin --defaults-file=/etc/mysql/debian.cnf -f reload # test if database if already present... if ! $(echo quit | mysql zm > /dev/null 2> /dev/null) ; then From 06f10e0ed30450dbbc60afb6c32369512c001694 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Thu, 22 Mar 2018 10:04:41 -0400 Subject: [PATCH 2/2] fix double free of mysql_result --- src/zm_db.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/zm_db.cpp b/src/zm_db.cpp index 568f9cd72..3f0c540f6 100644 --- a/src/zm_db.cpp +++ b/src/zm_db.cpp @@ -111,6 +111,10 @@ MYSQL_RES * zmDbFetch( const char * query ) { MYSQL_ROW zmDbFetchOne( const char *query ) { MYSQL_RES *result = zmDbFetch( query ); + if ( ! result ) { + return NULL; + } + int n_rows = mysql_num_rows( result ); if ( n_rows != 1 ) { Error( "Bogus number of lines return from query, %d returned for query %s.", n_rows, query ); @@ -118,8 +122,8 @@ MYSQL_ROW zmDbFetchOne( const char *query ) { } MYSQL_ROW dbrow = mysql_fetch_row( result ); - mysql_free_result( result ); if ( ! dbrow ) { + mysql_free_result( result ); Error("Error getting row from query %s. Error is %s", query, mysql_error( &dbconn ) ); return NULL; }