diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2017-07-10 22:31:05 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2017-07-10 22:31:05 +0300 |
commit | 70a86be6c01f123cb166715ee03c21a5a5ded34b (patch) | |
tree | 7478a7759d547106ca7b49515ee840bb5d106907 | |
parent | 2e876f3eba3b02ef2e51cb00c9e65a55b59d3019 (diff) | |
download | mysqlstat-70a86be6c01f123cb166715ee03c21a5a5ded34b.tar.gz mysqlstat-70a86be6c01f123cb166715ee03c21a5a5ded34b.tar.bz2 |
Provide default values for NULL columns
-rw-r--r-- | src/mysqlstat.c | 49 |
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 @@ -15,12 +15,13 @@ * along with Mysqlstat. If not, see <http://www.gnu.org/licenses/>. */ #include <mysqlstat.h> #include <mysql/mysql.h> #undef NDEBUG #include <assert.h> +#include <errno.h> #include "mysqlstat_mib.h" static char *config_file = CONFDIR "/mysqlstat.cnf"; struct mysqlstat_connection { MYSQL mysql; @@ -179,51 +180,62 @@ process_first(struct process_list **state) return process_next(p); } 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) { if (STREQ(Slave_IO_State, name)) { ASSIGN_STRING(ent, replSlaveIOState, value); } else if (STREQ(Master_Host, name)) { ASSIGN_STRING(ent, replMasterHost, value); } 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)) { ent->replSlaveIORunning = val_Slave_IO_Running(value); } else if (STREQ(Slave_SQL_Running, name)) { ent->replSlaveSQLRunning = val_bool(value); @@ -237,25 +249,25 @@ store_slave_status_row(struct replSlaveStatusTable_entry *ent, ASSIGN_STRING(ent, replReplicateIgnoreTable, value); } else if (STREQ(Replicate_Wild_Do_Table, name)) { ASSIGN_STRING(ent, replReplicateWildDoTable, value); } 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)) { ASSIGN_STRING(ent, replUntilLogFile, value); } else if (STREQ(Until_Log_Pos, name)) { ASSIGN_STRING(ent, replUntilLogPos, value); @@ -269,13 +281,14 @@ store_slave_status_row(struct replSlaveStatusTable_entry *ent, ASSIGN_STRING(ent, replMasterSSLCert, value); } else if (STREQ(Master_SSL_Cipher, name)) { ASSIGN_STRING(ent, replMasterSSLCipher, value); } 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 { snmp_log(LOG_ERR, "unrecognized slave status column: %s\n", name); } @@ -372,13 +385,13 @@ static void store_master_status_row(struct replMasterStatusTable_entry *ent, char const *name, char const *value) { 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)) { ASSIGN_STRING(ent, replMasterBinlogIgnoreDB, value); } else { snmp_log(LOG_ERR, "unrecognized master status column: %s\n", |