From 7dbc0211496dd6e217507293a2579811c7b385c5 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Wed, 20 May 2015 16:16:49 +0300 Subject: [PATCH] Added more logging when a monitor script cannot be executed. --- server/core/externcmd.c | 19 ++++++++++++++++++- server/modules/monitor/galeramon.c | 12 +++++++++++- server/modules/monitor/mmmon.c | 13 +++++++++++-- server/modules/monitor/monitor_common.c | 6 +++++- server/modules/monitor/mysql_mon.c | 12 +++++++++++- server/modules/monitor/ndbclustermon.c | 12 +++++++++++- 6 files changed, 67 insertions(+), 7 deletions(-) diff --git a/server/core/externcmd.c b/server/core/externcmd.c index cc7989fc6..93579faef 100644 --- a/server/core/externcmd.c +++ b/server/core/externcmd.c @@ -97,6 +97,23 @@ EXTERNCMD* externcmd_allocate(char* argstr) free(cmd); return NULL; } + if(access(cmd->parameters[0],F_OK) != 0) + { + skygw_log_write(LE, + "Error: Cannot find file: %s", + cmd->parameters[0]); + externcmd_free(cmd); + return NULL; + } + + if(access(cmd->parameters[0],X_OK) != 0) + { + skygw_log_write(LE, + "Error: Cannot execute file: %s", + cmd->parameters[0]); + externcmd_free(cmd); + return NULL; + } } return cmd; } @@ -138,7 +155,7 @@ int externcmd_execute(EXTERNCMD* cmd) { /** Child process, execute command */ execvp(cmd->parameters[0],cmd->parameters); - exit(1); + _exit(1); } else { diff --git a/server/modules/monitor/galeramon.c b/server/modules/monitor/galeramon.c index a46df8f77..404448d82 100644 --- a/server/modules/monitor/galeramon.c +++ b/server/modules/monitor/galeramon.c @@ -156,7 +156,17 @@ startMonitor(void *arg,void* opt) { if(handle->script) free(handle->script); - handle->script = strdup(params->value); + if(access(params->value,X_OK) == 0) + { + handle->script = strdup(params->value); + } + else + { + skygw_log_write(LE, + "Error: The file cannot be executed: %s", + params->value); + handle->script = NULL; + } } else if(!strcmp(params->name,"events")) { diff --git a/server/modules/monitor/mmmon.c b/server/modules/monitor/mmmon.c index bd1c6bb85..4ca8d6048 100644 --- a/server/modules/monitor/mmmon.c +++ b/server/modules/monitor/mmmon.c @@ -142,8 +142,17 @@ startMonitor(void *arg,void* opt) { free(handle->script); } - - handle->script = strdup(params->value); + if(access(params->value,X_OK) == 0) + { + handle->script = strdup(params->value); + } + else + { + skygw_log_write(LE, + "Error: The file cannot be executed: %s", + params->value); + handle->script = NULL; + } } else if(!strcmp(params->name,"events")) { diff --git a/server/modules/monitor/monitor_common.c b/server/modules/monitor/monitor_common.c index 6f9be583b..fb59eadbd 100644 --- a/server/modules/monitor/monitor_common.c +++ b/server/modules/monitor/monitor_common.c @@ -303,7 +303,11 @@ void monitor_launch_script(MONITOR* mon,MONITOR_SERVERS* ptr, char* script) ptr->server->unique_name); mon_append_node_names(mon->databases,argstr,PATH_MAX + MON_ARG_MAX + 1); - cmd = externcmd_allocate(argstr); + if((cmd = externcmd_allocate(argstr)) == NULL) + { + skygw_log_write(LE,"Failed to execute script: %s",script); + return; + } if(externcmd_execute(cmd)) { diff --git a/server/modules/monitor/mysql_mon.c b/server/modules/monitor/mysql_mon.c index 75f7027c4..1e7fde4e6 100644 --- a/server/modules/monitor/mysql_mon.c +++ b/server/modules/monitor/mysql_mon.c @@ -170,7 +170,17 @@ startMonitor(void *arg, void* opt) { if(handle->script) free(handle->script); - handle->script = strdup(params->value); + if(access(params->value,X_OK) == 0) + { + handle->script = strdup(params->value); + } + else + { + skygw_log_write(LE, + "Error: The file cannot be executed: %s", + params->value); + handle->script = NULL; + } } else if(!strcmp(params->name,"events")) { diff --git a/server/modules/monitor/ndbclustermon.c b/server/modules/monitor/ndbclustermon.c index 88444aaaf..4488786af 100644 --- a/server/modules/monitor/ndbclustermon.c +++ b/server/modules/monitor/ndbclustermon.c @@ -132,7 +132,17 @@ startMonitor(void *arg,void* opt) { if(handle->script) free(handle->script); - handle->script = strdup(params->value); + if(access(params->value,X_OK) == 0) + { + handle->script = strdup(params->value); + } + else + { + skygw_log_write(LE, + "Error: The file cannot be executed: %s", + params->value); + handle->script = NULL; + } } else if(!strcmp(params->name,"events")) {