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 | 37 |
1 files changed, 25 insertions, 12 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 @@ | |||
18 | #include <mysql/mysql.h> | 18 | #include <mysql/mysql.h> |
19 | #undef NDEBUG | 19 | #undef NDEBUG |
20 | #include <assert.h> | 20 | #include <assert.h> |
21 | #include <errno.h> | ||
21 | #include "mysqlstat_mib.h" | 22 | #include "mysqlstat_mib.h" |
22 | 23 | ||
23 | static char *config_file = CONFDIR "/mysqlstat.cnf"; | 24 | static char *config_file = CONFDIR "/mysqlstat.cnf"; |
@@ -182,23 +183,34 @@ process_first(struct process_list **state) | |||
182 | static long | 183 | static long |
183 | val_Slave_IO_Running(char const *val) | 184 | val_Slave_IO_Running(char const *val) |
184 | { | 185 | { |
186 | if (val) { | ||
185 | if (strcmp(val, "Yes") == 0) | 187 | if (strcmp(val, "Yes") == 0) |
186 | return 1; | 188 | return 1; |
187 | else if (strcmp(val, "No") == 0) | 189 | else if (strcmp(val, "No") == 0) |
188 | return 2; | 190 | return 2; |
189 | else if (strcmp(val, "Connected") == 0) | 191 | else if (strcmp(val, "Connected") == 0) |
190 | return 3; | 192 | return 3; |
193 | } | ||
191 | return 4; | 194 | return 4; |
192 | } | 195 | } |
193 | 196 | ||
194 | static long | 197 | static long |
195 | val_bool(char const *val) | 198 | val_bool(char const *val) |
196 | { | 199 | { |
197 | if (strcmp(val, "Yes") == 0) | 200 | if (val && strcmp(val, "Yes") == 0) |
198 | return 1; | 201 | return 1; |
199 | return 2; | 202 | return 2; |
200 | } | 203 | } |
201 | 204 | ||
205 | static u_long | ||
206 | var_num(char const *val, u_long dfl) | ||
207 | { | ||
208 | if (!val) | ||
209 | return dfl; | ||
210 | return strtoul(val, NULL, 10); | ||
211 | } | ||
212 | |||
213 | |||
202 | static void | 214 | static void |
203 | store_slave_status_row(struct replSlaveStatusTable_entry *ent, | 215 | store_slave_status_row(struct replSlaveStatusTable_entry *ent, |
204 | char const *name, char const *value) | 216 | char const *name, char const *value) |
@@ -210,17 +222,17 @@ store_slave_status_row(struct replSlaveStatusTable_entry *ent, | |||
210 | } else if (STREQ(Master_User, name)) { | 222 | } else if (STREQ(Master_User, name)) { |
211 | ASSIGN_STRING(ent, replMasterUser, value); | 223 | ASSIGN_STRING(ent, replMasterUser, value); |
212 | } else if (STREQ(Master_Port, name)) { | 224 | } else if (STREQ(Master_Port, name)) { |
213 | ent->replMasterPort = strtoul(value, NULL, 10); | 225 | ent->replMasterPort = var_num(value, 65536); |
214 | } else if (STREQ(Connect_Retry, name)) { | 226 | } else if (STREQ(Connect_Retry, name)) { |
215 | ent->replConnectRetry = strtoul(value, NULL, 10); | 227 | ent->replConnectRetry = var_num(value, 0); |
216 | } else if (STREQ(Master_Log_File, name)) { | 228 | } else if (STREQ(Master_Log_File, name)) { |
217 | ASSIGN_STRING(ent, replMasterLogFile, value); | 229 | ASSIGN_STRING(ent, replMasterLogFile, value); |
218 | } else if (STREQ(Read_Master_Log_Pos, name)) { | 230 | } else if (STREQ(Read_Master_Log_Pos, name)) { |
219 | ent->replReadMasterLogPos = strtoul(value, NULL, 10); | 231 | ent->replReadMasterLogPos = var_num(value, 0); |
220 | } else if (STREQ(Relay_Log_File, name)) { | 232 | } else if (STREQ(Relay_Log_File, name)) { |
221 | ASSIGN_STRING(ent, replRelayLogFile, value); | 233 | ASSIGN_STRING(ent, replRelayLogFile, value); |
222 | } else if (STREQ(Relay_Log_Pos, name)) { | 234 | } else if (STREQ(Relay_Log_Pos, name)) { |
223 | ent->replRelayLogPos = strtoul(value, NULL, 10); | 235 | ent->replRelayLogPos = var_num(value, 0); |
224 | } else if (STREQ(Relay_Master_Log_File, name)) { | 236 | } else if (STREQ(Relay_Master_Log_File, name)) { |
225 | ASSIGN_STRING(ent, replMasterLogFile, value); | 237 | ASSIGN_STRING(ent, replMasterLogFile, value); |
226 | } else if (STREQ(Slave_IO_Running, name)) { | 238 | } else if (STREQ(Slave_IO_Running, name)) { |
@@ -240,19 +252,19 @@ store_slave_status_row(struct replSlaveStatusTable_entry *ent, | |||
240 | } else if (STREQ(Replicate_Wild_Ignore_Table, name)) { | 252 | } else if (STREQ(Replicate_Wild_Ignore_Table, name)) { |
241 | ASSIGN_STRING(ent, replReplicateWildIgnoreTable, value); | 253 | ASSIGN_STRING(ent, replReplicateWildIgnoreTable, value); |
242 | } else if (STREQ(Last_IO_Errno, name)) { | 254 | } else if (STREQ(Last_IO_Errno, name)) { |
243 | ent->replLastIOErrno = strtoul(value, NULL, 10); | 255 | ent->replLastIOErrno = var_num(value, EINVAL); |
244 | } else if (STREQ(Last_IO_Error, name)) { | 256 | } else if (STREQ(Last_IO_Error, name)) { |
245 | ASSIGN_STRING(ent, replLastIOError, value); | 257 | ASSIGN_STRING(ent, replLastIOError, value); |
246 | } else if (STREQ(Last_SQL_Errno, name)) { | 258 | } else if (STREQ(Last_SQL_Errno, name)) { |
247 | ent->replLastSQLErrno = strtoul(value, NULL, 10); | 259 | ent->replLastSQLErrno = var_num(value, 0); |
248 | } else if (STREQ(Last_SQL_Error, name)) { | 260 | } else if (STREQ(Last_SQL_Error, name)) { |
249 | ASSIGN_STRING(ent, replLastSQLError, value); | 261 | ASSIGN_STRING(ent, replLastSQLError, value); |
250 | } else if (STREQ(Skip_Counter, name)) { | 262 | } else if (STREQ(Skip_Counter, name)) { |
251 | ent->replSkipCounter = strtoul(value, NULL, 10); | 263 | ent->replSkipCounter = var_num(value, 0); |
252 | } else if (STREQ(Exec_Master_Log_Pos, name)) { | 264 | } else if (STREQ(Exec_Master_Log_Pos, name)) { |
253 | ent->replExecMasterLogPos = strtoul(value, NULL, 10); | 265 | ent->replExecMasterLogPos = var_num(value, 0); |
254 | } else if (STREQ(Relay_Log_Space, name)) { | 266 | } else if (STREQ(Relay_Log_Space, name)) { |
255 | ent->replRelayLogSpace = strtoul(value, NULL, 10); | 267 | ent->replRelayLogSpace = var_num(value, 0); |
256 | } else if (STREQ(Until_Condition, name)) { | 268 | } else if (STREQ(Until_Condition, name)) { |
257 | ASSIGN_STRING(ent, replUntilCondition, value); | 269 | ASSIGN_STRING(ent, replUntilCondition, value); |
258 | } else if (STREQ(Until_Log_File, name)) { | 270 | } else if (STREQ(Until_Log_File, name)) { |
@@ -272,7 +284,8 @@ store_slave_status_row(struct replSlaveStatusTable_entry *ent, | |||
272 | } else if (STREQ(Master_SSL_Key, name)) { | 284 | } else if (STREQ(Master_SSL_Key, name)) { |
273 | ASSIGN_STRING(ent, replMasterSSLKey, value); | 285 | ASSIGN_STRING(ent, replMasterSSLKey, value); |
274 | } else if (STREQ(Seconds_Behind_Master, name)) { | 286 | } else if (STREQ(Seconds_Behind_Master, name)) { |
275 | ent->replSecondsBehindMaster = strtoul(value, NULL, 10) * 100; | 287 | /* FIXME: default? */ |
288 | ent->replSecondsBehindMaster = var_num(value, 0) * 100; | ||
276 | } else if (STREQ(Master_SSL_Verify_Server_Cert, name)) { | 289 | } else if (STREQ(Master_SSL_Verify_Server_Cert, name)) { |
277 | ent->replMasterSSLVerifyServerCert = val_bool(value); | 290 | ent->replMasterSSLVerifyServerCert = val_bool(value); |
278 | } else { | 291 | } else { |
@@ -375,7 +388,7 @@ store_master_status_row(struct replMasterStatusTable_entry *ent, | |||
375 | if (STREQ(File, name)) { | 388 | if (STREQ(File, name)) { |
376 | ASSIGN_STRING(ent, replMasterCurrentLogFile, value); | 389 | ASSIGN_STRING(ent, replMasterCurrentLogFile, value); |
377 | } else if (STREQ(Position, name)) { | 390 | } else if (STREQ(Position, name)) { |
378 | ent->replMasterCurrentLogPos = strtoul(value, NULL, 10); | 391 | ent->replMasterCurrentLogPos = var_num(value, 0); |
379 | } else if (STREQ(Binlog_Do_DB, name)) { | 392 | } else if (STREQ(Binlog_Do_DB, name)) { |
380 | ASSIGN_STRING(ent, replMasterBinlogDoDB, value); | 393 | ASSIGN_STRING(ent, replMasterBinlogDoDB, value); |
381 | } else if (STREQ(Binlog_Ignore_DB, name)) { | 394 | } else if (STREQ(Binlog_Ignore_DB, name)) { |