int parsing(char *str, t_shenv *shenv, int n) { char **cmd; int ret; int i; i = -1; if (!(init_parsing(&str, shenv, &ret, &cmd))) return (EXIT_SUCCESS); while (cmd && cmd[++i]) { if (!strncmp(cmd[i], ";", 1) && cmd[i + 1] && strncmp(cmd[i + 1], ";", 1)) ret = parse_cmd(cmd[++i], shenv, n); if (!strncmp(cmd[i], "&&", 2) && cmd[i + 1] && strncmp(cmd[i + 1], "&&", 2)) (!ret) ? (ret = parse_cmd(cmd[++i], shenv, n)) : ++i; if (!strncmp(cmd[i], "||", 2) && cmd[i + 1] && strncmp(cmd[i + 1], "||", 2)) (ret == EXIT_FAILURE) ? (ret = parse_cmd(cmd[++i], shenv, n)) : ++i; if (ret == -1) return (EXIT_FAILURE); n = 0; } my_free_tab(cmd); return (EXIT_SUCCESS); }
/* * run the program */ int main() { // holds the directories in the path char path_dirs[ MAX_PATHS ][ MAX_PATH_LEN ]; int num_dirs = parse_path( path_dirs ); char line[ LINE_LEN ]; command_t cmd; // get input print_prompt(); read_cmd( line ); parse_cmd( line, &cmd ); // until we get a line that starts with exit or quit while( !cmd.argv[0] || ( strcmp( cmd.argv[0], "quit" ) && strcmp( cmd.argv[0], "exit" ) ) ) { if( cmd.argv[0] ) cmd.name = lookup_path( cmd.argv, path_dirs, num_dirs ); if( cmd.name && cmd.argc > 0 ) { // create the child pid_t child_pid = fork(); if( child_pid < 0 ) perror( "fork" ); else if( child_pid == 0 ) // child execv( cmd.name, cmd.argv ); else // parent { if( !cmd.concurrent ) { int status; waitpid( child_pid, &status, 0 ); } } } cleanup_cmd( &cmd ); // get input print_prompt(); read_cmd( line ); parse_cmd( line, &cmd ); } return 0; }
static int main_thread(SceSize args, void *argp) { char cmdbuf[128]; int cpos; int retv; cpos = 0; while(1){ if(usbAsyncRead(ASYNC_STDOUT, (unsigned char*)&cmdbuf[cpos], 1)<1){ sceKernelDelayThread(250000); continue; } if(cmdbuf[cpos]=='\n'){ cmdbuf[cpos] = 0; retv = parse_cmd(cmdbuf); cpos = 0; }else{ if(cpos<127) cpos++; } } sceKernelExitDeleteThread(0); return 0; }
MuConfig* mu_config_new (int *argcp, char ***argvp) { MuConfig *config; g_return_val_if_fail (argcp && argvp, NULL); config = g_new0 (MuConfig, 1); if (!parse_cmd (config, argcp, argvp) || !parse_params(config, argcp, argvp)) { mu_config_destroy (config); return NULL; } /* fill in the defaults if user did not specify */ set_group_mu_defaults (config); set_group_index_defaults (config); set_group_find_defaults (config); set_group_cfind_defaults (config); set_group_view_defaults (config); /* set_group_mkdir_defaults (config); */ return config; }
int run_script(FILE *script) { int scripting = 1; int size; char **args, cmd[100]; while (scripting && !feof(script)) { size = 0; redirect_in = 0; dup2(defin, STDIN_FILENO); dup2(defout, STDOUT_FILENO); /* get the input from user. */ fgets(cmd, 100, script); args = parse_cmd(cmd, &size); if (pipeFlag) { scripting = run_pipe_cmd(size, args); pipeFlag = 0; } else { scripting = run_cmd(size, args); } } return cmd_exit_status; }
int wait_for_input(t_socket *socket) { char *in[2]; t_buffs buffs; fd_set fs[2]; char *cmd; struct timeval tv; if (!create_buffer(&buffs) || !(in[0] = malloc(4097)) || !(in[1] = malloc(4097)) || !memset(in[0], 0, 4097) || !memset(in[1], 0, 4097) || gethostname(in[1], 4096) == -1) return (-1); while (1) { tv.tv_sec = 1; tv.tv_usec = 0; set_fds(&fs[1], &fs[0], socket->fd, &buffs); if (select(socket->fd != -1 ? socket->fd + 1 : 1, &fs[0], &fs[1], NULL, &tv) == -1) return (puterr_int(ERR_SELECT, -1)); if (!(cmd = read_all(socket->fd, &fs[0], &buffs, in)) || write_all(&fs[1], &buffs, socket->fd) == -1 || (cmd && strcmp(cmd, "") && parse_cmd(cmd, socket, &buffs, in[0]) == -1)) return (free(in[0]), free(in[1]), -1); } }
static void manage_stdin(char **env, char **path, int count) { int i; char *line; char **cmd; cmd = NULL; line = NULL; while (1) { prompt(env, count); if (get_next_line(0, &line) > 0) { i = -1; cmd = ft_strsplit(line, ';'); ft_strdel(&line); while (cmd[++i]) env = parse_cmd(env, cmd, cmd[i], path); free(cmd); cmd = NULL; free_tab(path); ft_putchar('\n'); } count++; } free_tab(env); }
void main(void) { UCHAR cmd[0x8000]; BOOL exitflag; log_init(); hello(); log(greeting); log("DosLogWrite address: %x\n", DosLogWrite); exitflag=FALSE; // Ok. Here we just in endless loop. Except for EXIT command. // create the global env. array env_create(); while (!exitflag) { showpath(); read_cmd (cmd); exitflag = parse_cmd (cmd); } // destroy the global env. array env_destroy(); exit(0); }
void prompt() { char line[MAX_PROMPT_LINE]; Command_Info* cmd_info = newCommand_Info(MAX_PROMPT_LINE); pid_t child = 0; int status = 0; while (1) { printf("msh$ "); fflush(stdout); fgets(line, MAX_PROMPT_LINE, stdin); if (feof(stdin) || ferror(stdin)) break; if (parse_cmd(line, cmd_info) != 0) { if (!cmd_empty(cmd_info)) fprintf(stderr, "Syntax error!\n"); continue; } if (strcmp(cmd_info->arg[0], "exit") == 0) // builtin command exit break; if ((child = exec_simple(cmd_info)) > 0) { waitpid(child, &status, 0); if (WIFEXITED(status) && WEXITSTATUS(status) == 1) fprintf(stderr, "Command Not Found!\n"); } } deleteCommand_Info(cmd_info); }
int main(void) { char *argv[MAX_ARGC]; int i, argc; char buf[2040]; printf("\n\rEnter the interative mode, please make your command as follow.\n\n\r"); for(i = 0; i < sizeof(cmd_table) / sizeof(cmd_table[0]); i ++) printf("\n\r %s", cmd_table[i].command); printf("\n\n\r"); do{ printf("Wlan: "); gets(buf); printf("The command entered is : %s\n\r", buf); strcpy(cmd_buf, buf); if((argc = parse_cmd(buf, argv)) > 0) { int found = 0; for(i = 0; i < sizeof(cmd_table) / sizeof(cmd_table[0]); i ++) { if(strcmp((const char *)argv[0], (const char *)(cmd_table[i].command)) == 0) { cmd_table[i].function(argc, argv); found = 1; break; } } if(!found) printf("unknown command '%s'\n\r", argv[0]); } }while(global_exit); return 0; }
static void usbshell_task (void *pvParameters) { static portCHAR buf[128], c, *p = buf; shell_print (PROMPT); for (;;) { if (!vUSBRecvByte (&c, sizeof (c), 100)) continue; if (c == '\n' || c == '\r') { *p = '\0'; parse_cmd (buf); p = buf; shell_print (PROMPT); continue; } else if (c < ' ') continue; if (p == buf + sizeof (buf) - 1) { p = buf; *p = '\0'; } /* local echo */ vUSBSendByte (c); *p++ = c; } }
MuConfig* mu_config_init (int *argcp, char ***argvp, GError **err) { g_return_val_if_fail (argcp && argvp, NULL); memset (&MU_CONFIG, 0, sizeof(MU_CONFIG)); MU_CONFIG.maxnum = -1; /* By default, output all matching entries. */ if (!parse_cmd (argcp, argvp, err)) goto errexit; if (!parse_params(argcp, argvp, err)) goto errexit; /* fill in the defaults if user did not specify */ set_group_mu_defaults(); set_group_index_defaults(); set_group_find_defaults(); set_group_cfind_defaults(); set_group_view_defaults(); set_group_extract_defaults(); /* set_group_mkdir_defaults (config); */ return &MU_CONFIG; errexit: mu_config_uninit (&MU_CONFIG); return NULL; }
static void parse_pipe(cmds* cmd, prog_args* prog) { prog_args* elem = NULL; /* parse a command */ parse_cmd(cmd, prog); /* not in pipe? */ if (lookahead.kind!=STROKE) { return; } /* builtin and starting pipe? */ if( !(cmd->kind==PROG || cmd->kind==PIPE) ) { raise_error(PARSER_ILLEGAL_COMBINATION); } /* in pipe */ cmd->kind=PIPE; /* output redirection? */ if (prog->output != NULL) { raise_error(PARSER_ILLEGAL_REDIRECTION); } /* skip pipe symbol and parse next command */ scan(); elem = prog_new(); prog->next=elem; parse_pipe(cmd,elem); }
int main(int argc, char* argv[]) { char* cmd = NULL; MEM_POOL* mem_pool = mem_pool_init(MB_SIZE); int socket_fd; signal(SIGPIPE, SIG_IGN); signal(SIGHUP, SIG_IGN); signal(SIGINT, sign_handler); signal(SIGTERM, sign_handler); if((socket_fd = parse_cmd_line(argc, argv, mem_pool)) <= 0) { mem_pool_destroy(mem_pool); return 0; } while (global_start) { if ((cmd = readline("MILE>")) == NULL) { break; } parse_cmd(cmd,socket_fd,mem_pool); mem_pool_reset(mem_pool); if(cmd != NULL) { free(cmd); cmd = NULL; } } mem_pool_destroy(mem_pool); return 0; }
MuConfig* mu_config_init (int *argcp, char ***argvp) { g_return_val_if_fail (argcp && argvp, NULL); memset (&MU_CONFIG, 0, sizeof(MU_CONFIG)); if (!parse_cmd (argcp, argvp)) goto errexit; if (!parse_params(argcp, argvp)) goto errexit; /* fill in the defaults if user did not specify */ set_group_mu_defaults(); set_group_index_defaults(); set_group_find_defaults(); set_group_cfind_defaults(); set_group_view_defaults(); /* set_group_mkdir_defaults (config); */ return &MU_CONFIG; errexit: mu_config_uninit (&MU_CONFIG); return NULL; }
static void shm_set_variables(SynapticsSHM *synshm, int argc, char *argv[], int first_cmd) { int i; struct Parameter *par; double val; for (i = first_cmd; i < argc; i++) { val = parse_cmd(argv[i], &par); if (!par) continue; switch (par->type) { case PT_INT: *(int*)((char*)synshm + par->offset) = (int)rint(val); break; case PT_BOOL: *(Bool*)((char*)synshm + par->offset) = (Bool)rint(val); break; case PT_DOUBLE: *(double*)((char*)synshm + par->offset) = val; break; } } }
int cvs_trigger_handle(int type, char *repo, char *in, struct trigger_list *list, struct file_info_list *files) { int r; char *cmd; struct trigger_line *line; TAILQ_FOREACH(line, list, flist) { if ((cmd = parse_cmd(type, line->line, repo, files)) == NULL) return (1); switch(type) { case CVS_TRIGGER_COMMITINFO: case CVS_TRIGGER_TAGINFO: case CVS_TRIGGER_VERIFYMSG: if ((r = cvs_exec(cmd, NULL, 1)) != 0) { free(cmd); return (r); } break; default: (void)cvs_exec(cmd, in, 1); break; } free(cmd); } return (0); }
int run_bsigs(int argc, char *argv[]) { int ret=1; fzp *fzp=NULL; struct iobuf rbuf; struct blk blk; memset(&rbuf, 0, sizeof(struct iobuf)); if(argc!=2) return usage(); path=argv[1]; if(!(fzp=fzp_gzopen(path, "rb"))) goto end; while(1) { iobuf_free_content(&rbuf); switch(iobuf_fill_from_fzp(&rbuf, fzp)) { case 1: ret=0; // Finished OK. case -1: goto end; // Error. } if(parse_cmd(&rbuf, &blk)) goto end; } end: iobuf_free_content(&rbuf); fzp_close(&fzp); return ret; }
int read_task(const char *filename) { log_d("read_task filename:%s", filename); FILE *fp = fopen(filename, "r"); if (fp == NULL) { fprintf(stderr, "cannot open %s\n", filename); return 0; } char str_line[1024] = { }; //每行最大读取的字符数 while (!feof(fp)) { if (fgets(str_line, 1024, fp) == NULL) //读取一行 { break; } if (strlen(str_line) > 0) { trim(str_line); add_task(parse_cmd(str_line)); log_d("%s", str_line); //输出 } memset(str_line, 0, 1024); } fclose(fp); return 1; }
static void echo_read_cb(struct bufferevent *bev, void *ctx) { struct evbuffer *input = bufferevent_get_input(bev); size_t str_len = 0; char* str_input = evbuffer_readln(input,&str_len,EVBUFFER_EOL_ANY); char* val = NULL; enum CMD_TYPE cmdtype = parse_cmd(str_input, str_len, &val); if (cmdtype == CMD_QUIT){ bufferevent_free(bev); return; } struct evbuffer *ret = evbuffer_new(); switch (cmdtype) { case CMD_GET: case CMD_ECHO: evbuffer_add(ret,val,strlen(val)); break; case CMD_ERR: evbuffer_add(ret,"(ERR)",5); break; case CMD_OK: evbuffer_add(ret,"(OK)",4); break; case CMD_NULL: evbuffer_add(ret,"(NULL)",6);break; default: evbuffer_add(ret,"(UNKNOWN)",9);break; } evbuffer_add(ret,"\n",1); evbuffer_add_buffer(bufferevent_get_output(bev), ret); }
void parse_args(FILE *f, unsigned char *cmd) { static char *argv[MAXARGS]; unsigned char *parse = cmd; int argc = 0, t = 0; // Don't mess with anything that doesn't exist... if(!*parse) return; bzero(argv, sizeof(argv)); while(*parse) { if(*parse < 33 || *parse > 128) { *parse = 0, t++; if(t > MAXARG) { fprintf(f, "Warning: Argument exceeds maximum argument size, command ignored!\n"); return; } } else if(t || !argc) { if(argc == MAXARGS) { fprintf(f, "Warning: Command ignored, too many arguments\n"); return; } argv[argc++] = parse; t = 0; } parse++; } if(argc) parse_cmd(f, argc, argv); }
static int process_cmds(int fd, int max_cmd_length){ FILE *f; char cmd[MAX_COMMAND_LENGTH]; iddqd_cmd pcmd;// p stands for "parsed" f = fdopen (fd, COMM_FILE_OPEN_MODE); if (f == NULL){ ALOGE("Unable to open io stream (%s)\n", strerror(errno)); return -1; } while (fgets(cmd, MAX_COMMAND_LENGTH - 1, f) != NULL){ ALOGI("%s\n", cmd); if (!parse_cmd(cmd, &pcmd)){ ALOGI("Command is %s\n", pcmd.cmd); ALOGI("Argument is %s\n", pcmd.arg); } // TODO: Clear the array } // TODO: Process return code fclose (f); ALOGI("Returning from process_cmds"); return 0; }
//============================================================================= int main(int argc, const char** argv) { //parse command line arguments char ftFile[256],conFile[256],triFile[256]; bool fcheck = false; double scale = 1; int fpd = -1; bool show = true; if(parse_cmd(argc,argv,ftFile,conFile,triFile,fcheck,scale,fpd)<0)return 0; //set other tracking parameters std::vector<int> wSize1(1); wSize1[0] = 7; std::vector<int> wSize2(3); wSize2[0] = 11; wSize2[1] = 9; wSize2[2] = 7; int nIter = 5; double clamp=3,fTol=0.01; FACETRACKER::Tracker model(ftFile); cv::Mat tri=FACETRACKER::IO::LoadTri(triFile); cv::Mat con=FACETRACKER::IO::LoadCon(conFile); //initialize camera and display window cv::Mat frame,gray,im; double fps=0; char sss[256]; std::string text; CvCapture* camera = cvCreateCameraCapture(CV_CAP_ANY); if(!camera)return -1; int64 t1,t0 = cvGetTickCount(); int fnum=0; cvNamedWindow("Face Tracker",1); std::cout << "Hot keys: " << std::endl << "\t ESC - quit" << std::endl << "\t d - Redetect" << std::endl; //loop until quit (i.e user presses ESC) bool failed = true; while(1){ //grab image, resize and flip IplImage* I = cvQueryFrame(camera); if(!I)continue; frame = I; if(scale == 1)im = frame; else cv::resize(frame,im,cv::Size(scale*frame.cols,scale*frame.rows)); cv::flip(im,im,1); cv::cvtColor(im,gray,CV_BGR2GRAY); //track this image std::vector<int> wSize; if(failed)wSize = wSize2; else wSize = wSize1; if(model.Track(gray,wSize,fpd,nIter,clamp,fTol,fcheck) == 0){ int idx = model._clm.GetViewIdx(); failed = false; Draw(im,model._shape,con,tri,model._clm._visi[idx]); }else{ if(show){cv::Mat R(im,cvRect(0,0,150,50)); R = cv::Scalar(0,0,255);} model.FrameReset(); failed = true; } //draw framerate on display image if(fnum >= 9){ t1 = cvGetTickCount(); fps = 10.0/((double(t1-t0)/cvGetTickFrequency())/1e+6); t0 = t1; fnum = 0; }else fnum += 1; if(show){ sprintf(sss,"%d frames/sec",(int)round(fps)); text = sss; cv::putText(im,text,cv::Point(10,20), CV_FONT_HERSHEY_SIMPLEX,0.5,CV_RGB(255,255,255)); } //show image and check for user input imshow("Face Tracker",im); int c = cvWaitKey(10); if(c == 27)break; else if(char(c) == 'd')model.FrameReset(); }return 0; }
/** main */ int32_t main(int32_t argc, char *argv[]) { char iname[MNCN]; /**< input file name */ char oname[MNCN]; /**< report file name */ char rname[MNCN]; /**< output EDF/BDF file name */ FILE *fp; /**< file pointer for input EDF file and output timing file */ edf_t edf; /**< EDF struct */ int32_t cnt=0; /**< respiration period counter */ int32_t nc=0; /**< bytes written to EDF/BDF output file */ parse_cmd(argc, argv, iname, oname, rname); edf_set_vb(vb>>8); fprintf(stderr,"# Info: open EDF/BDF file %s\n",iname); if ((fp=fopen(iname,"r"))==NULL) { perror(""); return(-1); } /* read EDF/BDF main and signal headers */ edf_rd_hdr(fp,&edf); /* read EDF/BDF samples */ edf_rd_samples(fp,&edf); fclose(fp); /* chech ranges on all channels */ edf_range_chk(&edf); /* show range check results */ edf_range_cnt(&edf); fprintf(stderr,"# Info: write respiration timing file to %s\n",rname); if ((fp=fopen(rname,"w"))==NULL) { perror(""); return(-1); } cnt = rsp_detect(fp, &edf, "Resp"); /* print edf header */ if (vb&0x01) { edf_prt_hdr(stderr, &edf); } fprintf(stderr,"# Info: found %d respiration periods\n",cnt); fclose(fp); fprintf(stderr,"# Info: write filtered respiraton + annotations to file %s\n", oname); nc = edf_wr_file(oname, &edf, 0, edf.NrOfDataRecords-1); if (nc <= 0) { fprintf(stderr,"# Error: writing problems to file %s\n",oname); } else { fprintf(stderr,"# Info: writing %d bytes to file %s\n", nc, oname); } /* remove all edf struct */ edf_free(&edf); return(0); }
int main(int argc, char **argv ) { char path[MAX_PATH]; BurnLibInit(); // init Burn core BurnPathsInit(); // init paths or create them if needed /* if (argc < 2) { int c; printf ("Usage: %s <path to rom><shortname>.zip\n" " ie: %s ./uopoko.zip\n" " Note: Path and .zip extension are mandatory.\n\n", argv[0], argv[0]); printf ("Supported (but not necessarily working) roms:\n\n"); for(nBurnDrvSelect[0] = 0; nBurnDrvSelect[0] < nBurnDrvCount; nBurnDrvSelect[0]++) { nBurnDrvActive = nBurnDrvSelect[0]; printf("%-20s ", BurnDrvGetTextA(DRV_NAME)); c++; if(c == 3) { c = 0; printf("\n"); } } printf ("\n\n"); CreateCapexLists(); // generate rominfo.fba and zipname.fba return 0; } */ ConfigGameDefault(); // alter cfg if any param is given if (argc >= 2) parse_cmd(argc, argv, path); ConfigAppLoad(); if((SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE)) < 0) { printf("Sdl failed to init\n"); exit(0); } if (argc < 2) GuiRun(); else { int drv; if((drv = FindDrvByFileName(path)) >= 0) RunEmulator(drv); } BurnLibExit(); if (argc < 2) ConfigAppSave(); SDL_Quit(); return 0; }
int main(int argc, char *argv[]) { if (parse_cmd(argc, argv)<0) { printf("illegal command: %s [-f] [-n] id ...\n",argv[0]); return -1; } return 0; }
int main(void){ char cmd[MAX_CMD_LENGTH]=""; //Command entered by the user including arguments,pipes,redirections,etc. char *tokens[MAX_CMD_LENGTH]={NULL}; //Stores the parsed command(Eg: token[0]=ls, token[1]=-l) char *commands[PATH_MAX]={NULL}; //Pathname of the actual commands. Commands may be more than one due to piping. char *target_cmd; int cpid,child_err_code; //Initialize PS1 content init_ps1(); while(1){ printf("%s",PS1); //Display prompt(PS1) if(!fgets(cmd,MAX_CMD_LENGTH,stdin)){ //Get input perror("fgets"); exit(EXIT_FAILURE); } if(strcmp(cmd,"\n") == 0) //If Empty command then new prompt again continue; cmd[strlen(cmd)-1] = '\0'; //Replace '\n' with a '\0' if(strcmp(cmd,"exit") == 0) //Exit code exit(0); //Tokenize the command if(tokenize_cmd(cmd,tokens) == -1){ fprintf(stderr,"Shell Error: Too may tokens in command.\n"); continue; } //Extract command names if(parse_cmd(tokens,commands) == -1){ fprintf(stderr,"Shell Error: Unable to parse command.\n"); continue; } target_cmd = search_cmd(commands[0]); //TODO....Modify this code for every commands //This is the core function of a shell. Rest are features. //Execute command by invoking the respective program for it using exec() //TODO.... cpid = fork(); if(cpid == -1){ perror("fork"); exit(EXIT_FAILURE); } if(cpid == 0){ //Child process if(execv(target_cmd,tokens) == -1){ //TODO...Extract command pathname and argument list perror("execv"); exit(EXIT_FAILURE); //Child exits if failed } } wait(&child_err_code); } return 0; }
int main() { char buf[BUF_SIZE]; fd = serial_init(); if(fih_spi_init() >= 0) spi_init_flag = 1; else { spi_init_flag = 0; PRINT_LOG("fih_spi_init fail\n"); } PRINT_LOG("g_ftm_cmds_num=%d\n", g_ftm_cmds_num); wait_for_connected(); while(1) { /* Foxconn/WillHuang, 20130705, MKD, SCR { */ /* For Wireless charging current test in MT station */ #if 1 if(get_loop_status() == 0) { serial_read(buf); chomp(buf); parse_cmd(buf); } #else serial_read(buf); chomp(buf); parse_cmd(buf); #endif /* Foxconn/WillHuang, 20130705, MKD, SCR } */ } fih_spi_uninit(); serial_uninit(); return 0; }
int run_pipe_cmd(int argc, char* argv[]) { int i, size; pid_t pid; char **command; int **pipes; pipes = (int**)malloc(argc*sizeof(int*)); /* initialize pipes */ for(i=0;i<argc;i++) { pipes[i] = (int*)malloc(2*sizeof(int)); } /* Create argc child processes. */ for (i = 0; i < argc; i ++) { if (i < argc - 1) { if ((pipe(pipes[i])) < 0) { perror("Fail to set up the pipe."); } } if((pid = fork()) < 0) { perror("Fork failed."); } if (pid == 0) { command = parse_cmd(argv[i], &size); if (i == 0) { close(pipes[i][0]); /*dup2(defin, STDIN_FILENO);*/ dup2(pipes[i][1], STDOUT_FILENO); close(pipes[i][1]); } else if (i == argc - 1) { close(pipes[i - 1][1]); /*dup2(defout, STDOUT_FILENO);*/ dup2(pipes[i - 1][0], STDIN_FILENO); close(pipes[i - 1][0]); } else { close(pipes[i - 1][1]); close(pipes[i][0]); dup2(pipes[i - 1][0], STDIN_FILENO); close(pipes[i - 1][0]); dup2(pipes[i][1], STDOUT_FILENO); close(pipes[i][1]); } pipeFlag = 1; run_cmd(size, command); } else { /* parent process*/ waitpid(pid, NULL, WNOHANG); } } return 1; }
int sudo_cmd(int argc, char **argv) { session_sudoStart(); char *buffer = strjoin(argv, " ", argc); int cmd = parse_cmd(buffer); if (cmd != -1) { excecuteCmd(cmd, buffer); } session_sudoEnd(); free(buffer); return 0; }