static pid_t proc_pipe_fath(t_pipe *pip, char **envp, int fd[2], pid_t cpid) { pid_t pid; pid = (pid_t)0; if (pip->next) { if (close(fd[1]) == -1) ft_error(5); pid = process_pipe(pip->next, envp, fd[0]); return (pid); } else { return (cpid); } }
int test_pipe(t_pipe *pip, char **envp, int *lastcmd) { pid_t pid; int status; if (pip && pip->next) { pid = process_pipe(pip, envp, 0); waitpid(pid, &status, WUNTRACED); if (WIFEXITED(status)) (void)status; *lastcmd = status; while (waitpid(-1, &status, 0) > 0) term_initiate(); return (1); } return (0); }
static bool wait_statusd_init(int outfd, int errfd, ExtlFn dh, ExtlFn eh) { fd_set rfds; struct timeval tv, endtime, now; int nfds=MAXOF(outfd, errfd); int retval; bool dummy, doneseen, eagain=FALSE; if(mainloop_gettime(&endtime)!=0){ warn_err(); return FALSE; } now=endtime; endtime.tv_sec+=CF_STATUSD_TIMEOUT_SEC; while(1){ FD_ZERO(&rfds); /* Calculate remaining time */ if(now.tv_sec>endtime.tv_sec){ goto timeout; }else if(now.tv_sec==endtime.tv_sec){ if(now.tv_usec>=endtime.tv_usec) goto timeout; tv.tv_sec=0; tv.tv_usec=endtime.tv_usec-now.tv_usec; }else{ tv.tv_usec=USEC+endtime.tv_usec-now.tv_usec; tv.tv_sec=-1+endtime.tv_sec-now.tv_sec; /* Kernel lameness tuner: */ tv.tv_sec+=tv.tv_usec/USEC; tv.tv_usec%=USEC; } FD_SET(outfd, &rfds); FD_SET(errfd, &rfds); retval=select(nfds+1, &rfds, NULL, NULL, &tv); if(retval>0){ if(FD_ISSET(errfd, &rfds)){ if(!process_pipe(errfd, eh, &dummy, &eagain)) return FALSE; } if(FD_ISSET(outfd, &rfds)){ if(!process_pipe(outfd, dh, &doneseen, &eagain)) return FALSE; if(doneseen){ /* Read rest of errors. */ bool ok; do{ ok=process_pipe(errfd, eh, &dummy, &eagain); }while(ok && !eagain); return TRUE; } } }else if(retval==0){ goto timeout; } if(mainloop_gettime(&now)!=0){ warn_err(); return FALSE; } } return TRUE; timeout: /* Just complain to stderr, not startup error log, and do not fail. * The system might just be a bit slow. We can continue, but without * initial values for the meters, geometry adjustments may be necessary * when we finally get that information. */ ioncore_warn_nolog(TR("ion-statusd timed out.")); return TRUE; }
int main(int argc, char *argv[]) { char cmd [MAXCMD]; char* arg [MAXARG]; int* arg_count = new int(0), * current_count = new int(0); char the_path[256]; getcwd(the_path, 255); name_shell(the_path); signal(SIGINT, signalHandler); system("clear"); do { strcpy(cmd , ""); //clears the input (solves a problem I was having). printf("%s", shell_name.c_str()); //reprint shell name std::cin.getline(cmd, MAXCMD, '\n'); // get input parse(cmd, arg, arg_count); // Only processes stuff that was entered into the shell if(strcmp(cmd, "\0") != 0) { if(is_there_next_pipe(arg, *current_count, *arg_count)) { // TODO: Fix handling more than one pipe process_pipe(current_count); // seperate commands for piping char *cmd1[MAXARG], *cmd2[MAXARG]; // Left program for(int i=0;i<*current_count;++i) { cmd1[i] = arg[i];//cmd1[i] = arg[i]; } // Right program for(int i=*current_count;i<*arg_count;++i) { cmd2[i-(*current_count)] = arg[i];//cmd2[i-(*current_count)] = arg[i-(*current_count)]; } pipe_cmd(cmd1, cmd2); //printf("Pipe: %s into %s\n", arg[*current_count-2], arg[*current_count]); } // Check if these are internal commands, which do not need forking else if(is_internal_cmd(cmd)) process_internal_cmd(cmd, arg); // Run process else run_cmd(arg, arg_count); } } while(true); // "exit" will stop the shell return 0; }