Added more logging when a monitor script cannot be executed.

This commit is contained in:
Markus Makela
2015-05-20 16:16:49 +03:00
parent b815a79628
commit 7dbc021149
6 changed files with 67 additions and 7 deletions

View File

@ -97,6 +97,23 @@ EXTERNCMD* externcmd_allocate(char* argstr)
free(cmd); free(cmd);
return NULL; 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; return cmd;
} }
@ -138,7 +155,7 @@ int externcmd_execute(EXTERNCMD* cmd)
{ {
/** Child process, execute command */ /** Child process, execute command */
execvp(cmd->parameters[0],cmd->parameters); execvp(cmd->parameters[0],cmd->parameters);
exit(1); _exit(1);
} }
else else
{ {

View File

@ -156,8 +156,18 @@ startMonitor(void *arg,void* opt)
{ {
if(handle->script) if(handle->script)
free(handle->script); free(handle->script);
if(access(params->value,X_OK) == 0)
{
handle->script = strdup(params->value); 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")) else if(!strcmp(params->name,"events"))
{ {
mon_parse_event_string(&handle->events,sizeof(handle->events),params->value); mon_parse_event_string(&handle->events,sizeof(handle->events),params->value);

View File

@ -142,9 +142,18 @@ startMonitor(void *arg,void* opt)
{ {
free(handle->script); free(handle->script);
} }
if(access(params->value,X_OK) == 0)
{
handle->script = strdup(params->value); 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")) else if(!strcmp(params->name,"events"))
{ {
mon_parse_event_string((bool*)&handle->events,sizeof(handle->events),params->value); mon_parse_event_string((bool*)&handle->events,sizeof(handle->events),params->value);

View File

@ -303,7 +303,11 @@ void monitor_launch_script(MONITOR* mon,MONITOR_SERVERS* ptr, char* script)
ptr->server->unique_name); ptr->server->unique_name);
mon_append_node_names(mon->databases,argstr,PATH_MAX + MON_ARG_MAX + 1); 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)) if(externcmd_execute(cmd))
{ {

View File

@ -170,8 +170,18 @@ startMonitor(void *arg, void* opt)
{ {
if(handle->script) if(handle->script)
free(handle->script); free(handle->script);
if(access(params->value,X_OK) == 0)
{
handle->script = strdup(params->value); 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")) else if(!strcmp(params->name,"events"))
{ {
mon_parse_event_string(handle->events,sizeof(handle->events),params->value); mon_parse_event_string(handle->events,sizeof(handle->events),params->value);

View File

@ -132,8 +132,18 @@ startMonitor(void *arg,void* opt)
{ {
if(handle->script) if(handle->script)
free(handle->script); free(handle->script);
if(access(params->value,X_OK) == 0)
{
handle->script = strdup(params->value); 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")) else if(!strcmp(params->name,"events"))
{ {
mon_parse_event_string(&handle->events,sizeof(handle->events),params->value); mon_parse_event_string(&handle->events,sizeof(handle->events),params->value);