bmsd/mysql.c

changeset 558
a8e065a9f851
parent 505
c09b67fd8323
child 567
6bf0afc33e70
--- a/bmsd/mysql.c	Mon Dec 02 16:53:56 2019 +0100
+++ b/bmsd/mysql.c	Mon Dec 02 20:56:01 2019 +0100
@@ -397,18 +397,20 @@
 int bms_mysql_query(const char *query)
 {
     int		rc = mysql_query(con, query);
+    int		err = mysql_errno(con);
 
     if (rc) {
-        syslog(LOG_NOTICE, "MySQL: error %u (%s)", mysql_errno(con), mysql_error(con));
+        syslog(LOG_NOTICE, "MySQL: error %u (%s)", err, mysql_error(con));
         syslog(LOG_NOTICE, query);
     } else {
 	return 0;
     }
 
     /* Any error execpt server gone away */
-    if (rc != 2006)
+    if (err != 2006)
 	return rc;
 
+    syslog(LOG_NOTICE, "Trying to reconnect");
     /* Try to reconnect and do the query again */
     mysql_close(con);
     if (mysql_real_connect(con, Config.mysql_host, Config.mysql_user, Config.mysql_pass, Config.mysql_database, Config.mysql_port, NULL, 0) == NULL) {
@@ -434,14 +436,14 @@
 
 void node_mysql_insert(sys_node_list *node)
 {
-    char	*query = malloc(1024), first[21], last[21];
+    char	*query = malloc(1024), first[73], last[73];
     struct tm	*mytime;
 
     mytime = localtime(&node->firstseen);
-    snprintf(first, 20, "%04d-%02d-%02d %02d:%02d:%02d", 
+    snprintf(first, 72, "%04d-%02d-%02d %02d:%02d:%02d",
 		    mytime->tm_year + 1900, mytime->tm_mon + 1, mytime->tm_mday, mytime->tm_hour, mytime->tm_min, mytime->tm_sec);
     mytime = localtime(&node->lastseen);
-    snprintf(last, 20, "%04d-%02d-%02d %02d:%02d:%02d",
+    snprintf(last, 72, "%04d-%02d-%02d %02d:%02d:%02d",
 		mytime->tm_year + 1900, mytime->tm_mon + 1, mytime->tm_mday, mytime->tm_hour, mytime->tm_min, mytime->tm_sec);
 
     snprintf(query, 1023,
@@ -465,11 +467,11 @@
 
 void node_mysql_update(sys_node_list *node)
 {
-    char        *query = malloc(1024), last[21];
+    char        *query = malloc(1024), last[65];
     struct tm   *mytime;
 
     mytime = localtime(&node->lastseen);
-    snprintf(last, 20, "%04d-%02d-%02d %02d:%02d:%02d",
+    snprintf(last, 64, "%04d-%02d-%02d %02d:%02d:%02d",
     	mytime->tm_year + 1900, mytime->tm_mon + 1, mytime->tm_mday, mytime->tm_hour, mytime->tm_min, mytime->tm_sec);
 
     snprintf(query, 1023,

mercurial