summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Larson <mike@vyatta.com>2010-11-24 23:11:39 -0800
committerMichael Larson <mike@vyatta.com>2010-11-24 23:11:39 -0800
commit792d6aa0dd0ecfd45c9b5ab57c6c0cb71a9b8da6 (patch)
tree3bf70dc29cbcc43ffbc8ec95a028a1a25ead188b /src
parentcc525741b011f70a9841b9f0f6341dfc2d52819b (diff)
downloadvyatta-cfg-792d6aa0dd0ecfd45c9b5ab57c6c0cb71a9b8da6.tar.gz
vyatta-cfg-792d6aa0dd0ecfd45c9b5ab57c6c0cb71a9b8da6.zip
implementation of err location support for commit process. commit failures will now look different (via cli):
vyatta@vyatta# commit [ service nat ] NAT configuration error: rule type not specified/valid [ system domain-search domain ] System configuration error. Both 'domain-name' and 'domain-search' are specified, but only one of these mutually exclusive parameters is allowed. [ load-balancing wan ] WARNING: A valid WAN load-balance configuration requires an interface with a nexthop Commit failed Location of error will now be supplied on each failure, with the option to override the script node location.
Diffstat (limited to 'src')
-rw-r--r--src/cli_new.c61
-rw-r--r--src/commit2.c147
2 files changed, 103 insertions, 105 deletions
diff --git a/src/cli_new.c b/src/cli_new.c
index 1ac99a1..065d62c 100644
--- a/src/cli_new.c
+++ b/src/cli_new.c
@@ -2535,49 +2535,46 @@ old_system_out(const char *command)
}
int
-system_out(const char *cmd, const char **outbuf)
-{
- // fprintf(out_stream,"system out\n");
- if (outbuf == NULL) {
- return old_system_out(cmd);
- }
-
- if (cmd == NULL) {
- return -1;
- }
-
- int cp[2]; // Child to parent pipe
-
- if( pipe(cp) < 0) {
- return -1;
- }
-
- pid_t pid = fork();
- if (pid == 0) {
- //child
- close(1); // Close current stdout./
- dup2( cp[1],1); // Make stdout go to write end of pipe.
- dup2( cp[1],2); // Make stderr go to write end of pipe.
- close(0); // Close current stdin.
- close( cp[0]);
-
- int ret = 0;
- if (execl("/bin/sh","sh","-c",cmd,NULL) == -1) {
+system_out(const char *cmd, const char **outbuf)
+{
+ // fprintf(out_stream,"system out\n");
+ if (outbuf == NULL) {
+ return old_system_out(cmd);
+ }
+ if (cmd == NULL) {
+ return -1;
+ }
+
+ int cp[2]; // Child to parent pipe
+ if( pipe(cp) < 0) { return -1;
+ }
+
+ pid_t pid = fork();
+ if (pid == 0) {
+ //child
+ close(1); // Close current stdout./
+ dup2(cp[1],1); // Make stdout go to write end of pipe.
+ dup2(cp[1],2); // Make stderr go to write end of pipe.
+ close(0); // Close current stdin.
+ close(cp[0]);
+ close(cp[1]);
+ int ret = 0;
+ if (execl("/bin/sh","sh","-c",cmd,NULL) == -1) {
ret = errno;
}
- close( cp[1]);
+ close(cp[1]);
exit(ret);
}
else {
- //parent
+ //parent
char buf[1025];
memset(buf,'\0',1025);
close(cp[1]);
- if (read(cp[0], &buf, 1024) > 0) {
+ while (read(cp[0], &buf, 1024) > 0) {
strcat((char*)*outbuf,buf);
}
- //now wait on child to kick the bucket
+ //now wait on child to kick the bucket
int status;
wait(&status);
close(cp[0]);
diff --git a/src/commit2.c b/src/commit2.c
index aeb9ce7..0a91a9f 100644
--- a/src/commit2.c
+++ b/src/commit2.c
@@ -98,6 +98,9 @@ execute_hook_compare_func(gconstpointer a, gconstpointer b, gpointer data);
static gboolean
execute_hook_func(GNode *node, gpointer data);
+char*
+process_script_path(char* in);
+
/*
NOTES: reverse: use the n-nary tree in commit2.c and only encapuslate data store. pass in func pointer for processing of commands below.
@@ -658,49 +661,28 @@ process_func(GNode *node, gpointer data)
char *outbuf = NULL;
if (g_dump_actions == FALSE) {
- if (g_print_error_location_all == TRUE) {
- outbuf = malloc(8192);
- outbuf[0] = '\0';
- status = execute_list(c->_def.actions[result->_action].vtw_list_head,&c->_def,(const char**)&outbuf);
- }
- else {
- status = execute_list(c->_def.actions[result->_action].vtw_list_head,&c->_def,NULL);
- }
- if (!status && g_print_error_location_all == TRUE) { //EXECUTE_LIST RETURNS FALSE ON FAILURE....
- if (strstr(outbuf,"_errloc_:[") != NULL) {
- fprintf(out_stream,"%s\n",outbuf);
+ outbuf = malloc(8192);
+ outbuf[0] = '\0';
+ status = execute_list(c->_def.actions[result->_action].vtw_list_head,&c->_def,(const char**)&outbuf);
+ if (strlen(outbuf) > 0) {
+ if (strstr(outbuf,"_errloc_:[") != NULL) {
+ if (g_print_error_location_all == FALSE) { //EXECUTE_LIST RETURNS FALSE ON FAILURE....
+ fprintf(out_stream,"%s\n",outbuf+strlen("_errloc_:"));
+ }
+ else {
+ fprintf(out_stream,"%s\n",outbuf);
+ }
}
else {
- //just need to convert slashes into spaces here
- char path_buf[1024];
- char tmp[1024];
- char *ptr;
- path_buf[0] = '\0';
-
- strcpy(tmp,d->_path);
- ptr = (char*)tmp;
- char *slash = strchr(tmp,'/');
- if (slash == NULL) {
- strcat(path_buf,d->_path);
- }
- else {
- do { //convert '/' to ' '
- strncat(path_buf,ptr,slash - ptr);
- strcat(path_buf," ");
- ++slash;
- ptr = slash;
- } while ((slash = strchr(slash,'/')) != NULL);
- }
- if (strncmp(ptr,"value:",6) == 0) {
- if (strlen(ptr)-6 > 0) {
- strncat(path_buf,ptr+6,strlen(ptr)-6);
+ //currently set to format option for GUI client.
+ char *p = process_script_path(d->_path);
+ if (p != NULL) {
+ if (g_print_error_location_all == FALSE) { //EXECUTE_LIST RETURNS FALSE ON FAILURE....
+ fprintf(out_stream,"[%s]\n%s\n",p,outbuf);
}
- }
- char *p = clind_unescape(path_buf);
-
- if (strlen(outbuf) > 0) {
- //currently set to format option for GUI client.
- fprintf(out_stream,"_errloc_:[%s]\n%s\n",p,outbuf);
+ else {
+ fprintf(out_stream,"_errloc_:[%s]\n%s\n",p,outbuf);
+ }
}
}
}
@@ -750,6 +732,48 @@ process_func(GNode *node, gpointer data)
/**
*
**/
+char*
+process_script_path(char* in)
+{
+ if (in == NULL) {
+ return NULL;
+ }
+
+ //just need to convert slashes into spaces here
+ char path_buf[4096];
+ char tmp[4096];
+ char *ptr;
+ path_buf[0] = '\0';
+
+ strcpy(tmp,in);
+ ptr = (char*)tmp;
+ char *slash = strchr(tmp,'/');
+ if (slash == NULL) {
+ strcat(path_buf,in);
+ }
+ else {
+ do { //convert '/' to ' '
+ strncat(path_buf,ptr,slash - ptr);
+ strcat(path_buf," ");
+ ++slash;
+ ptr = slash;
+ } while ((slash = strchr(slash,'/')) != NULL);
+ }
+ if (strncmp(ptr,"value:",6) == 0) {
+ if (strlen(ptr)-6 > 0) {
+ strncat(path_buf,ptr+6,strlen(ptr)-6);
+ strcat(path_buf," ");
+ }
+ }
+ return clind_unescape(path_buf);
+}
+
+
+
+
+/**
+ *
+ **/
boolean
complete(GSList *node_coll, boolean test_mode)
{
@@ -1548,40 +1572,17 @@ validate_func(GNode *node, gpointer data)
gettimeofday(&t,NULL);
fprintf(out_stream,"[END] %lu:%lu\n",t.tv_sec,t.tv_usec);
}
-
+
if (!status) { //EXECUTE_LIST RETURNS FALSE ON FAILURE....
- //just need to convert slashes into spaces here
- char path_buf[1024];
- char tmp[1024];
- char *ptr;
- path_buf[0] = '\0';
-
- strcpy(tmp,d->_path);
- ptr = (char*)tmp;
- char *slash = strchr(tmp,'/');
- if (slash == NULL) {
- strcat(path_buf,d->_path);
- }
- else {
- do { //convert '/' to ' '
- strncat(path_buf,ptr,slash - ptr);
- strcat(path_buf," ");
- ++slash;
- ptr = slash;
- } while ((slash = strchr(slash,'/')) != NULL);
- }
- if (strncmp(ptr,"value:",6) == 0) {
- if (strlen(ptr)-6 > 0) {
- strncat(path_buf,ptr+6,strlen(ptr)-6);
- }
- }
- char *p = clind_unescape(path_buf);
- if (strlen(outbuf) > 0) {
- if (g_print_error_location_all == TRUE) {
- fprintf(out_stream,"_errloc_:[%s]\n %s\n",p,outbuf);
- }
- else {
- fprintf(out_stream,"[ %s ] \n %s\n",p,outbuf);
+ char *p = process_script_path(d->_path);
+ if (p != NULL) {
+ if (strlen(outbuf) > 0) {
+ if (g_print_error_location_all == TRUE) {
+ fprintf(out_stream,"_errloc_:[%s]\n %s\n",p,outbuf);
+ }
+ else {
+ fprintf(out_stream,"[%s] \n %s\n",p,outbuf);
+ }
}
}
syslog(LOG_ERR,"commit error for %s:[%s]\n",ActionNames[result->_action],d->_path);