aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2017-07-10 22:31:05 +0300
committerSergey Poznyakoff <gray@gnu.org>2017-07-10 22:31:05 +0300
commit70a86be6c01f123cb166715ee03c21a5a5ded34b (patch)
tree7478a7759d547106ca7b49515ee840bb5d106907
parent2e876f3eba3b02ef2e51cb00c9e65a55b59d3019 (diff)
downloadmysqlstat-70a86be6c01f123cb166715ee03c21a5a5ded34b.tar.gz
mysqlstat-70a86be6c01f123cb166715ee03c21a5a5ded34b.tar.bz2
Provide default values for NULL columns
-rw-r--r--src/mysqlstat.c49
1 files changed, 31 insertions, 18 deletions
diff --git a/src/mysqlstat.c b/src/mysqlstat.c
index 4eb5a18..7db2649 100644
--- a/src/mysqlstat.c
+++ b/src/mysqlstat.c
@@ -18,6 +18,7 @@
#include <mysql/mysql.h>
#undef NDEBUG
#include <assert.h>
+#include <errno.h>
#include "mysqlstat_mib.h"
static char *config_file = CONFDIR "/mysqlstat.cnf";
@@ -182,23 +183,34 @@ process_first(struct process_list **state)
static long
val_Slave_IO_Running(char const *val)
{
- if (strcmp(val, "Yes") == 0)
- return 1;
- else if (strcmp(val, "No") == 0)
- return 2;
- else if (strcmp(val, "Connected") == 0)
- return 3;
+ if (val) {
+ if (strcmp(val, "Yes") == 0)
+ return 1;
+ else if (strcmp(val, "No") == 0)
+ return 2;
+ else if (strcmp(val, "Connected") == 0)
+ return 3;
+ }
return 4;
}
static long
val_bool(char const *val)
{
- if (strcmp(val, "Yes") == 0)
+ if (val && strcmp(val, "Yes") == 0)
return 1;
return 2;
}
+static u_long
+var_num(char const *val, u_long dfl)
+{
+ if (!val)
+ return dfl;
+ return strtoul(val, NULL, 10);
+}
+
+
static void
store_slave_status_row(struct replSlaveStatusTable_entry *ent,
char const *name, char const *value)
@@ -210,17 +222,17 @@ store_slave_status_row(struct replSlaveStatusTable_entry *ent,
} else if (STREQ(Master_User, name)) {
ASSIGN_STRING(ent, replMasterUser, value);
} else if (STREQ(Master_Port, name)) {
- ent->replMasterPort = strtoul(value, NULL, 10);
+ ent->replMasterPort = var_num(value, 65536);
} else if (STREQ(Connect_Retry, name)) {
- ent->replConnectRetry = strtoul(value, NULL, 10);
+ ent->replConnectRetry = var_num(value, 0);
} else if (STREQ(Master_Log_File, name)) {
ASSIGN_STRING(ent, replMasterLogFile, value);
} else if (STREQ(Read_Master_Log_Pos, name)) {
- ent->replReadMasterLogPos = strtoul(value, NULL, 10);
+ ent->replReadMasterLogPos = var_num(value, 0);
} else if (STREQ(Relay_Log_File, name)) {
ASSIGN_STRING(ent, replRelayLogFile, value);
} else if (STREQ(Relay_Log_Pos, name)) {
- ent->replRelayLogPos = strtoul(value, NULL, 10);
+ ent->replRelayLogPos = var_num(value, 0);
} else if (STREQ(Relay_Master_Log_File, name)) {
ASSIGN_STRING(ent, replMasterLogFile, value);
} else if (STREQ(Slave_IO_Running, name)) {
@@ -240,19 +252,19 @@ store_slave_status_row(struct replSlaveStatusTable_entry *ent,
} else if (STREQ(Replicate_Wild_Ignore_Table, name)) {
ASSIGN_STRING(ent, replReplicateWildIgnoreTable, value);
} else if (STREQ(Last_IO_Errno, name)) {
- ent->replLastIOErrno = strtoul(value, NULL, 10);
+ ent->replLastIOErrno = var_num(value, EINVAL);
} else if (STREQ(Last_IO_Error, name)) {
ASSIGN_STRING(ent, replLastIOError, value);
} else if (STREQ(Last_SQL_Errno, name)) {
- ent->replLastSQLErrno = strtoul(value, NULL, 10);
+ ent->replLastSQLErrno = var_num(value, 0);
} else if (STREQ(Last_SQL_Error, name)) {
ASSIGN_STRING(ent, replLastSQLError, value);
} else if (STREQ(Skip_Counter, name)) {
- ent->replSkipCounter = strtoul(value, NULL, 10);
+ ent->replSkipCounter = var_num(value, 0);
} else if (STREQ(Exec_Master_Log_Pos, name)) {
- ent->replExecMasterLogPos = strtoul(value, NULL, 10);
+ ent->replExecMasterLogPos = var_num(value, 0);
} else if (STREQ(Relay_Log_Space, name)) {
- ent->replRelayLogSpace = strtoul(value, NULL, 10);
+ ent->replRelayLogSpace = var_num(value, 0);
} else if (STREQ(Until_Condition, name)) {
ASSIGN_STRING(ent, replUntilCondition, value);
} else if (STREQ(Until_Log_File, name)) {
@@ -272,7 +284,8 @@ store_slave_status_row(struct replSlaveStatusTable_entry *ent,
} else if (STREQ(Master_SSL_Key, name)) {
ASSIGN_STRING(ent, replMasterSSLKey, value);
} else if (STREQ(Seconds_Behind_Master, name)) {
- ent->replSecondsBehindMaster = strtoul(value, NULL, 10) * 100;
+ /* FIXME: default? */
+ ent->replSecondsBehindMaster = var_num(value, 0) * 100;
} else if (STREQ(Master_SSL_Verify_Server_Cert, name)) {
ent->replMasterSSLVerifyServerCert = val_bool(value);
} else {
@@ -375,7 +388,7 @@ store_master_status_row(struct replMasterStatusTable_entry *ent,
if (STREQ(File, name)) {
ASSIGN_STRING(ent, replMasterCurrentLogFile, value);
} else if (STREQ(Position, name)) {
- ent->replMasterCurrentLogPos = strtoul(value, NULL, 10);
+ ent->replMasterCurrentLogPos = var_num(value, 0);
} else if (STREQ(Binlog_Do_DB, name)) {
ASSIGN_STRING(ent, replMasterBinlogDoDB, value);
} else if (STREQ(Binlog_Ignore_DB, name)) {

Return to:

Send suggestions and report system problems to the System administrator.