- posr=read(child_stdout[0],&buffout,4096);
- // fprintf(stderr,"got %d chars\n",posr);
- if (posr<0 && errno!=EINTR && errno!=EAGAIN) {
- perror("Error while reading output of child");
- exit(4);
- }
- if (posr>0) {
- buffout[posr]='\0';
- buff_append(output_got,buffout);
- }
-
- if (got <= 0 && posr <= 0)
- usleep(100);
- }
- input->data[0]='\0';
- input->used=0;
- close(child_stdin[1]);
-
- timeouted = 0;
- alarm(timeout_value);
- do {
- posr=read(child_stdout[0],&buffout,4096);
- if (posr<0 && errno!=EINTR && errno!=EAGAIN) {
- perror("Error while reading output of child");
- exit(4);
- }
- if (posr>0) {
- buffout[posr]='\0';
- buff_append(output_got,buffout);
- } else {
- usleep(100);
- }
- } while (!timeouted && posr!=0);
-
- /* Check for broken pipe */
- if (brokenpipe && verbose) {
- fprintf(stderr,"Warning: Child did not consume all its input (I got broken pipe)\n");
- }
-
- /* Check for timeouts */
- if (timeouted) {
- fprintf(stderr,"Child timeouted (waited %d sec)\n",timeout_value);
- exit(3);
- }
- alarm(0);
-
-
- /* Wait for child, and check why it terminated */
- wait(&status);
-
- if (WIFSIGNALED(status) && WTERMSIG(status) != expected_signal) {
- fprintf(stderr,"Child got signal %d instead of signal %d\n",
- WTERMSIG(status), expected_signal);
- exit(WTERMSIG(status)+4);
- }
- if (!WIFSIGNALED(status) && expected_signal != 0) {
- fprintf(stderr,"Child didn't got expected signal %d\n",
- expected_signal);
- exit(5);
- }
-
- if (WIFEXITED(status) && WEXITSTATUS(status) != expected_return ) {
- if (expected_return)
- fprintf(stderr,"Child returned code %d instead of %d\n",
- WEXITSTATUS(status), expected_return);
- else
- fprintf(stderr,"Child returned code %d\n", WEXITSTATUS(status));
- exit(40+WEXITSTATUS(status));
- }
- expected_return = expected_signal = 0;
-
- } else { /* child */
-
- close(child_stdin[1]);
- close(child_stdout[0]);
- dup2(child_stdin[0],0);
- close(child_stdin[0]);
- dup2(child_stdout[1],1);
- dup2(child_stdout[1],2);
- close(child_stdout[1]);
-
- execlp ("/bin/sh", "sh", "-c", cmd, NULL);
- }
-}
-
-static void run_cmd(char *cmd) {
- if (cmd[0] == 'c' && cmd[1] == 'd' && cmd[2] == ' ') {
- int pos = 2;
- /* Search end */
- pos = strlen(cmd)-1;
- while (cmd[pos] == '\n' || cmd[pos] == ' ' || cmd[pos] == '\t')
- cmd[pos--] = '\0';
- /* search begining */
- pos = 2;
- while (cmd[pos++] == ' ');
- pos--;
- // fprintf(stderr,"Saw cd '%s'\n",cmd+pos);
- if (chdir(cmd+pos)) {
- perror("Chdir failed");
- exit(4);
- }
-
- } else {
- exec_cmd(cmd);
- }
-}
+ /*
+ XBT_DEBUG("rctx={%s,in={%d,>>%10s<<},exp={%d,>>%10s<<},got={%d,>>%10s<<}}",
+ rctx->cmd,
+ rctx->input->used, rctx->input->data,
+ rctx->output_wanted->used,rctx->output_wanted->data,
+ rctx->output_got->used, rctx->output_got->data);
+ */
+ XBT_DEBUG("[%s] %s", filepos, line);