/** * Pipe: TODO */ static int do_pipe(CommandNode *node) { int pipefd[2]; if (pipe(pipefd) == 0) { int readfd = pipefd[0]; int writefd = pipefd[1]; pid_t source_pid; pid_t target_pid; if (((source_pid = fork())) == 0) { /* source child */ int retval; close(readfd); redirect_stream(writefd, STDOUT_FILENO); retval = execute(node->op1); close(writefd); exit(retval); } else { /* parent */ close(writefd); if (((target_pid = fork())) == 0) { /* target child */ int retval; redirect_stream(readfd, STDIN_FILENO); retval = execute(node->op2); close(readfd); exit(retval); } else { /* parent */ close(readfd); check_wait(source_pid); return check_wait(target_pid); } } } else { perror("do_pipe"); return 1; } }
/** * Subshell node: fork synchronously and setup environment for subshell */ static int do_subshell(CommandNode *node) { pid_t pid; if (((pid = fork())) == 0) { /* child */ setup_redirections(node); exit(do_execute(node->op1)); /* noreturn */ } else if (pid > 0) { /* parent */ return check_wait(pid); } /* else */ perror("do_subshell"); exit(1); }
/** * Command node: fork synchronously and call exec */ static int do_command(CommandNode *node) { pid_t child; if (strcmp(node->command, "cd") == 0) return builtin_cd(node->arguments); if (((child = fork())) == 0) { /* child process */ setup_redirections(node); replace_process(node->command, node->arguments); /* noreturn */ } else { /* parent process */ return check_wait(child); } return 1; }
void __init check_bugs32(void) { check_wait(); }
NTSTATUS thread_impl_t::wait_on_handles( ULONG count, PHANDLE handles, WAIT_TYPE type, BOOLEAN alert, PLARGE_INTEGER timeout) { NTSTATUS r = STATUS_SUCCESS; Alertable = alert; WaitType = type; // iterate the array and wait on each handle for (ULONG i=0; i<count; i++) { dprintf("handle[%ld] = %08lx\n", i, (ULONG) handles[i]); object_t *any = 0; r = object_from_handle( any, handles[i], SYNCHRONIZE ); if (r < STATUS_SUCCESS) { end_wait(); return r; } sync_object_t *obj = dynamic_cast<sync_object_t*>( any ); if (!obj) { end_wait(); return STATUS_INVALID_HANDLE; } r = wait_on( obj ); if (r < STATUS_SUCCESS) { end_wait(); return r; } } // make sure we wait for a little bit every time LARGE_INTEGER t; if (timeout && timeout->QuadPart <= 0 && timeout->QuadPart> -100000LL) { t.QuadPart = -100000LL; timeout = &t; } set_timeout( timeout ); while (1) { r = check_wait(); if (r != STATUS_PENDING) break; if (alerted) { alerted = FALSE; r = STATUS_ALERTED; break; } if (timeout && has_expired()) { r = STATUS_TIMEOUT; break; } in_wait = TRUE; wait(); assert( in_wait == FALSE ); } end_wait(); set_timeout( 0 ); return r; }