summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Larson <mike@vyatta.com>2010-11-12 20:20:13 -0800
committerMichael Larson <mike@vyatta.com>2010-11-12 20:20:13 -0800
commit9d70c0897cd20b0488b8fdfc563ceaa608d9f798 (patch)
tree3916028e64289acd2b46b7d3d4c530d06a7cc22c
parentaf53886cff07672d6e7d2b0940be5e66be90999b (diff)
downloadvyatta-cfg-9d70c0897cd20b0488b8fdfc563ceaa608d9f798.tar.gz
vyatta-cfg-9d70c0897cd20b0488b8fdfc563ceaa608d9f798.zip
remove extra process layer--required before this command is expanded to handle other commit actions (i.e. ones that rely on consistent parent process id in scripts).
-rw-r--r--src/cli_new.c70
1 files changed, 34 insertions, 36 deletions
diff --git a/src/cli_new.c b/src/cli_new.c
index a047f36..41afb5f 100644
--- a/src/cli_new.c
+++ b/src/cli_new.c
@@ -2534,42 +2534,42 @@ old_system_out(const char *command)
return ret;
}
-
-
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 = system(cmd);
-
+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) {
+ ret = errno;
+ }
close( cp[1]);
- exit(WEXITSTATUS(ret));
+ exit(ret);
}
else {
- //parent
+ //parent
char buf[1025];
memset(buf,'\0',1025);
close(cp[1]);
@@ -2577,16 +2577,14 @@ system_out(const char *cmd, const char **outbuf)
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]);
-
- return WEXITSTATUS(status);
+ return WEXITSTATUS(status);
}
}
-
/**********************************************************/