static void* consumer_operation() { set_signal_mask(); while(status_on) { if(pthread_mutex_lock(&buffer_lock_mtx)!=0) print_log(WARNING,"\nthere is error in lock cons"); while(is_buffer_empty()) { if(pthread_cond_wait(&buffer_not_empty_cond,&buffer_lock_mtx)!=0) print_log(WARNING,"\nthere is error in wait cons"); } int peer_sfd = buffer_get(); if(peer_sfd < 0) { print_log(WARNING,"\nRECIEVED FAILED ACCEPT SOCKET"); pthread_mutex_unlock(&buffer_lock_mtx)!=0; continue; } if(pthread_cond_broadcast(&buffer_not_full_cond)!=0) print_log(WARNING,"\nthere is error in broadcast cons"); if(pthread_mutex_unlock(&buffer_lock_mtx)!=0) print_log(WARNING,"\nthere is error in unlock cons"); manage_single_request(peer_sfd); close(peer_sfd); } pthread_exit(pthread_self); }
static void* manage_request_response_per_thread(void *peer_sfd) { set_signal_mask(); manage_single_request(*(int*)peer_sfd); close(*(int*)peer_sfd); free((int*)peer_sfd); pthread_exit(pthread_self); }
int main(int argc, char* argv[]) { /* Set the signal masks. */ set_signal_mask(); /* FIXME: Load configuration before opening the server. */ int mgr = fp_mgr_open(); if (mgr < 1) return -1; /* Put mgr into the poll loop. */ fp_poll_set[0].fd = mgr; fp_poll_set[0].events = POLLIN; /* Set the poll set size. */ fp_poll_size = 1; running = true; /* Run the main loop. */ while (running) { clear_poll_results(); /* Poll for events. */ if (poll(fp_poll_set, fp_poll_size, 100) < 0) { perror("main/poll"); break; } /* Did we get a message from flowmgr. */ if (fp_poll_set[0].revents &= POLLIN) { int result = fp_mgr_incoming(); if (result <= 0) break; } } fp_mgr_close(); }
bool app_launcher::run(const char *file, const char *const argv[], const char *const envp[], uint flags) { assert(!is_running()); stop(); m_status_code = STATUS_NOTLAUNCHED; m_status = 0; const char *argv_def[2]; if (!argv) { argv_def[0] = file; argv_def[1] = NULL; argv = argv_def; } if (!envp) { envp = __environ; } vogl::vector<char *> new_envp; if (flags & RUN_REMOVE_LD_PRELOAD_ENV) { // Remove LD_PRELOAD. Need to do this to keep glxinfo from preloading us again (for example). static const char ld_preload_str[] = "LD_PRELOAD="; static const size_t ld_preload_len = sizeof(ld_preload_str) - 1; for(int i = 0; environ[i]; i++) { if (strncmp(ld_preload_str, environ[i], ld_preload_len)) new_envp.push_back(environ[i]); } new_envp.push_back(NULL); envp = new_envp.get_ptr(); } // [0]: read end, [1]: write end // Use pipe2 with O_CLOEXEC? O_NONBLK? int ret_stdout = pipe(m_stdout_pipe); int ret_stderr = pipe(m_stderr_pipe); if ((ret_stdout < 0) || (ret_stderr < 0)) return false; sigset_t sigset_full; sigfillset(&sigset_full); const sigset_t sigmask_orig = set_signal_mask(sigset_full); // Careful: fork() can return pid of a script... m_child_pid = fork(); if (m_child_pid != 0) { // Restore sigmask for parent. set_signal_mask(sigmask_orig); } if (m_child_pid < 0) { assert(0); m_status_code = STATUS_ERROR; m_status = m_child_pid; return false; } else if (m_child_pid == 0) { // According to chromium LaunchProcess(), readline processes can block forever // unless we set stdin to /dev/null. int null_fd = HANDLE_EINTR(open("/dev/null", O_RDONLY)); if (null_fd < 0) _exit(127); int new_stdin = HANDLE_EINTR(dup2(null_fd, STDIN_FILENO)); ret_stdout = HANDLE_EINTR(dup2(m_stdout_pipe[1], STDOUT_FILENO)); ret_stderr = HANDLE_EINTR(dup2(m_stderr_pipe[1], STDERR_FILENO)); if ((new_stdin < 0) || (ret_stdout < 0) || (ret_stderr < 0)) _exit(127); close(m_stdout_pipe[0]); // close read pipe close(m_stderr_pipe[0]); // close read pipe m_stdout_pipe[0] = -1; m_stderr_pipe[0] = -1; // exec file execvpe(file, (char * const *)argv, (char * const *)envp); _exit(127); } close(m_stdout_pipe[1]); close(m_stderr_pipe[1]); m_stdout_pipe[1] = -1; m_stderr_pipe[1] = -1; m_status_code = STATUS_RUNNING; return true; }