static int exec_process_list(process *pr_list) { process *pr; pid_t pid, pgid; const char *cmd; if (open_pipes(pr_list) < 0) { return -1; } pgid = -1; for (pr = pr_list; pr != NULL; pr = pr->next) { if ((pid = fork()) == -1) { return -1; } else if (pid == 0) { /* child process */ dup2(pr->fd0, 0); dup2(pr->fd1, 1); cmd = find_command(pr->program_name); if (cmd == NULL) { fprintf(stderr, "program not found: %s\n", pr->program_name); return -1; } execve(cmd, pr->argument_list, environ); close(pr->fd0); close(pr->fd1); exit(0); } else { /* parent process */ if (pr->fd0 != 0) close(pr->fd0); if (pr->fd1 != 1) close(pr->fd1); pr->pid = pid; if (pgid == -1) { pgid = pid; } setpgid(pid, pgid); } } return pgid; }
void *parse_wine_stdout(void *arg) { char sname[MAX_PATH]; TPARSER *tp = (TPARSER *)arg; FILE *pfile = tp->pfile; AVS_PIPES copy_pipes [CMD_PIPE_NUM]; int i; for (i = 0; i < CMD_PIPE_NUM; i++) { memcpy (©_pipes[i], &tp->avs_pipes[i], sizeof(AVS_PIPES)); if ((copy_pipes[i].flags & O_ACCMODE) == O_RDONLY) copy_pipes[i].flags = (copy_pipes[i].flags & ~O_ACCMODE) | O_WRONLY; else if ((copy_pipes[i].flags & O_ACCMODE) == O_WRONLY) copy_pipes[i].flags = (copy_pipes[i].flags & ~O_ACCMODE) | O_RDONLY; DEBUG_PRINTF("avsfilter : new.flags %X, old.flags %X\n", copy_pipes[i].flags, tp->avs_pipes[i].flags); } wine_loader_down = false; if (pfile) { time_t t = time(NULL); DEBUG_PRINTF("avsfilter : pthread time %s\n", ctime(&t)); DEBUG_PRINTF("pthread start ok\n"); while(fgets(sname, MAX_PATH, pfile) != NULL) #ifdef DEBUGMSG printf("%s", sname); #else ; #endif DEBUG_PRINTF("End parse\n"); pclose(pfile); wine_loader_down = true; // if pipes not open completely, then simple open from thread for close if (!open_pipes_ok) { DEBUG_PRINTF("avsfilter : loader down, try to close waiting (for open) main thread\n"); if (open_pipes((AVS_PIPES*)©_pipes, CMD_PIPE_NUM)) { DEBUG_PRINTF("avsfilter : open ok, try to deinit\n"); //deinit_pipes((AVS_PIPES*)©_pipes, CMD_PIPE_NUM); DEBUG_PRINTF("avsfilter : deinit done\n"); } } } }
void setup_fds(void) { /* If we have victim files, don't worry about sockets. */ if (victim_path == NULL) open_sockets(); open_pipes(); open_perf_fds(); open_epoll_fds(); open_eventfd_fds(); if (no_files == FALSE) { generate_filelist(); if (files_in_index == 0) /* Something bad happened. Crappy -V maybe? */ return; // FIXME: We should log something here probably. open_files(); } }
unsigned int setup_fds(void) { int ret = TRUE; /* If we have victim files, don't worry about sockets. */ if (victim_path == NULL) { ret = open_sockets(); if (ret == FALSE) return FALSE; } open_pipes(); open_perf_fds(); open_epoll_fds(); open_eventfd_fds(); if (no_files == FALSE) ret = open_files(); return ret; }
bool wine_start(char *wine_app, char *avsloader, AVS_PIPES *avs_pipes, int pipe_timeout) { char sname[MAX_PATH]; struct stat st; sprintf(sname, "%s %s %d", wine_app, avsloader, pipe_timeout); FILE *pfile = popen(sname, "r"); if (!pfile) { DEBUG_PRINTF_RED("avsfilter : popen failed, errno %d, failed start app is : [%s]\n", errno, sname); return false; } if (fscanf(pfile, "%s\n", sname) != 1 || stat(sname, &st) || !S_ISDIR(st.st_mode)) { DEBUG_PRINTF_RED("avsfilter : tmpdirname [%s] failed, errno %d[stat %d isdir %d]\n", sname, errno, stat(sname, &st), S_ISDIR(st.st_mode)); pclose(pfile); return false; } DEBUG_PRINTF("avsfilter : good tmpdirname %s\n", sname); if (!init_pipes(avs_pipes, CMD_PIPE_NUM, pfile)) { DEBUG_PRINTF_RED("init_pipes failed\n"); pclose(pfile); return false; } time_t t = time(NULL); DEBUG_PRINTF("avsfilter : precreate thread time %s\n", ctime(&t)); pthread_t thread; TPARSER tp = { avs_pipes, pfile }; open_pipes_ok = false; if (pthread_create(&thread, NULL, parse_wine_stdout, &tp)) { DEBUG_PRINTF_RED("Cannot pthread started...Errno %d\n",errno); deinit_pipes(avs_pipes, CMD_PIPE_NUM); return false; } t = time(NULL); DEBUG_PRINTF("avsfilter : preopen time %s\n", ctime(&t)); if (!open_pipes(avs_pipes, CMD_PIPE_NUM) || wine_loader_down) { open_pipes_ok = true; DEBUG_PRINTF_RED("open_pipes failed\n"); deinit_pipes(avs_pipes, CMD_PIPE_NUM); return false; } open_pipes_ok = true; if (pipe_test_filter (avs_pipes[PIPE_LOADER_READ].hpipe, avs_pipes[PIPE_FILTER_WRITE].hpipe)) { DEBUG_PRINTF("avsfilter : test pipe to filter ok\n"); if (pipe_test_filter (avs_pipes[PIPE_LOADER_READ].hpipe, avs_pipes[PIPE_LOADER_WRITE].hpipe)) { DEBUG_PRINTF("avsfilter : test pipe to loader ok\n"); } else goto error_pipe_test; } else { error_pipe_test: DEBUG_PRINTF_RED("Error test read/write pipes\n"); deinit_pipes(avs_pipes, CMD_PIPE_NUM); return false; } DEBUG_PRINTF("wine start is ok\n"); return true; }
void SignalHandler::after_fork_child(STATE) { exit_ = false; open_pipes(); start_thread(state); }