summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Larson <mike@vyatta.com>2010-12-07 23:12:37 -0800
committerMichael Larson <mike@vyatta.com>2010-12-07 23:12:37 -0800
commite8f44ce0ef28d56b49bce317392589557a1086ad (patch)
tree5fd8ca64df50222888a86cd6b497f43770424a6d /src
parentaaa27225061025e12c50cbff5521dfbb27265f97 (diff)
downloadvyatta-cfg-e8f44ce0ef28d56b49bce317392589557a1086ad.tar.gz
vyatta-cfg-e8f44ce0ef28d56b49bce317392589557a1086ad.zip
Allow _errloc_ to be place on any line in output, not restricted to first line.
Diffstat (limited to 'src')
-rw-r--r--src/cli_new.c29
1 files changed, 21 insertions, 8 deletions
diff --git a/src/cli_new.c b/src/cli_new.c
index 994280b..b4349b2 100644
--- a/src/cli_new.c
+++ b/src/cli_new.c
@@ -2571,11 +2571,10 @@ system_out(const char *cmd, const char *prepend_msg, boolean format)
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(STDIN_FILENO); // Close current stdout./
+ dup2(cp[1],STDOUT_FILENO); // Make stdout go to write end of pipe.
+ dup2(cp[1],STDERR_FILENO); // Make stderr go to write end of pipe.
close(cp[1]);
int ret = 0;
// fprintf(out_stream,"executing: %s\n",cmd);
@@ -2595,20 +2594,27 @@ system_out(const char *cmd, const char *prepend_msg, boolean format)
boolean print = FALSE;
fd_set rfds;
struct timeval tv;
+ char errloc_buf[] = "_errloc_:";
+ size_t errloc_len = strlen(errloc_buf);
FD_ZERO(&rfds);
FD_SET(cp[0], &rfds);
tv.tv_sec = 1;
tv.tv_usec = 0;
+ int flags = fcntl(cp[0], F_GETFL);
+ flags |= O_NONBLOCK; fcntl(cp[0], F_SETFL, flags);
+
while (select(FD_SETSIZE, &rfds, NULL, NULL, &tv) != -1) {
int err = 0;
if ((err = read(cp[0], &buf, 8191)) > 0) {
+
+
print = TRUE;
if (first == TRUE) {
- if (strstr(buf,"_errloc_:[") != NULL) {
+ if (strncmp(buf,errloc_buf,errloc_len) == 0) {
if (format == FALSE) {
- fprintf(out_stream,"%s",buf+strlen("_errloc_:"));
+ fprintf(out_stream,"%s",buf+errloc_len);
}
else {
fprintf(out_stream,"%s",buf);
@@ -2621,14 +2627,21 @@ system_out(const char *cmd, const char *prepend_msg, boolean format)
fprintf(out_stream,"[%s]\n%s",prepend_msg,buf);
}
else {
- fprintf(out_stream,"_errloc_:[%s]\n%s",prepend_msg,buf);
+ fprintf(out_stream,"%s[%s]\n%s",errloc_buf,prepend_msg,buf);
}
}
}
}
else {
- fprintf(out_stream,"%s",buf);
+ if (strncmp(buf,errloc_buf,errloc_len) == 0 && format == FALSE) {
+ fprintf(out_stream,"%s",buf+errloc_len);
+ }
+ else {
+ fprintf(out_stream,"%s",buf);
+ }
}
+
+
first = FALSE;
last_char = buf[strlen(buf)-2];
memset(buf,'\0',8192);