bool setupStdio(Pid createdPid, Pid requesterPid, File_t *outStdin, File_t *outStdout, File_t *outStderr, File_t inStdin, File_t inStdout,File_t inStderr) { uint32_t thisPid = GetPid(); if (!createPipe(thisPid, requesterPid, createdPid, inStdin, outStdin, STDIN_FILENO)) return false; if (!createPipe(thisPid, requesterPid, createdPid, inStdout, outStdout, STDOUT_FILENO)) return false; if (!createPipe(thisPid, requesterPid, createdPid, inStderr, outStderr, STDERR_FILENO)) return false; return true; }
void MainWindow::gameRedy() { gamemod=redy; createFloor(); createBird(); createPipe(); }
void osgMain::drawLine(osg::Vec3 NewPt) { __android_log_print(ANDROID_LOG_ERROR,"jni client","in new line point"); if(!DrawLine) return; else __android_log_print(ANDROID_LOG_ERROR,"jni client","in new line point 2"); //newPt=MFPCM->getEye(); newPt=NewPt; getNewPt=true; if(line3Pts->size()==3) { osg::Vec3 pt1=line3Pts->at(0); osg::Vec3 pt2=line3Pts->at(1); osg::Vec3 pt3=line3Pts->at(2); createPipe(pt1,pt2,pt3,mshape,LineStart,currentLineGeode); line3Pts->at(0)=line3Pts->at(1); line3Pts->at(1)=line3Pts->at(2); line3Pts->at(2)=newPt; if(LineStart) LineStart=false; } else line3Pts->push_back(newPt); __android_log_print(ANDROID_LOG_ERROR,"jni client","get new line point"); }
PRBool NTStatsServer::createStatsChannel(void) { HANDLE hPipe = createPipe(); if (hPipe == INVALID_HANDLE_VALUE) { return PR_FALSE; } HANDLE hEvent = CreateEvent(NULL, // Security descriptor TRUE, // Manual Rest TRUE, // Initially Signaled state NULL); // Unnamed if (hEvent == INVALID_HANDLE_VALUE) { CloseHandle(hPipe); return PR_FALSE; } if (addPollItem(hPipe, hEvent) != PR_TRUE) { CloseHandle(hPipe); CloseHandle(hEvent); return PR_FALSE; } int nIndex = nPollItems_ - 1; if (connectPipe(nIndex) == PR_FALSE) { return PR_FALSE; } return PR_TRUE; }
void createController() { FUNCTION_ENTER; createPipe(); createControllerThread(); FUNCTION_EXIT; }
static std::tuple<BoreholeGeometry, RefrigerantProperties, GroutParameters, FlowAndTemperatureControl, PipeConfigurationCoaxial> parseBHECoaxialConfig( BaseLib::ConfigTree const& config, std::map<std::string, std::unique_ptr<MathLib::PiecewiseLinearInterpolation>> const& curves) { auto const borehole_geometry = //! \ogs_file_param{prj__processes__process__HEAT_TRANSPORT_BHE__borehole_heat_exchangers__borehole_heat_exchanger__borehole} createBoreholeGeometry(config.getConfigSubtree("borehole")); //! \ogs_file_param{prj__processes__process__HEAT_TRANSPORT_BHE__borehole_heat_exchangers__borehole_heat_exchanger__pipes} auto const& pipes_config = config.getConfigSubtree("pipes"); //! \ogs_file_param{prj__processes__process__HEAT_TRANSPORT_BHE__borehole_heat_exchangers__borehole_heat_exchanger__pipes__outer} Pipe const outer_pipe = createPipe(pipes_config.getConfigSubtree("outer")); Pipe const inner_pipe = //! \ogs_file_param{prj__processes__process__HEAT_TRANSPORT_BHE__borehole_heat_exchangers__borehole_heat_exchanger__pipes__inner} createPipe(pipes_config.getConfigSubtree("inner")); const auto pipe_longitudinal_dispersion_length = //! \ogs_file_param{prj__processes__process__HEAT_TRANSPORT_BHE__borehole_heat_exchangers__borehole_heat_exchanger__pipes__longitudinal_dispersion_length} pipes_config.getConfigParameter<double>( "longitudinal_dispersion_length"); PipeConfigurationCoaxial const pipes{inner_pipe, outer_pipe, pipe_longitudinal_dispersion_length}; //! \ogs_file_param{prj__processes__process__HEAT_TRANSPORT_BHE__borehole_heat_exchangers__borehole_heat_exchanger__grout} auto const grout = createGroutParameters(config.getConfigSubtree("grout")); auto const refrigerant = //! \ogs_file_param{prj__processes__process__HEAT_TRANSPORT_BHE__borehole_heat_exchangers__borehole_heat_exchanger__refrigerant} createRefrigerantProperties(config.getConfigSubtree("refrigerant")); auto const flowAndTemperatureControl = createFlowAndTemperatureControl( //! \ogs_file_param{prj__processes__process__HEAT_TRANSPORT_BHE__borehole_heat_exchangers__borehole_heat_exchanger__flow_and_temperature_control} config.getConfigSubtree("flow_and_temperature_control"), curves, refrigerant); return {borehole_geometry, refrigerant, grout, flowAndTemperatureControl, pipes}; }
bool Pillow::HttpHandlerProxy::handleRequest(Pillow::HttpConnection *request) { if (_proxiedUrl.isEmpty()) return false; QUrl targetUrl = _proxiedUrl; targetUrl.setEncodedPath(request->requestPath()); if (!request->requestQueryString().isEmpty()) targetUrl.setEncodedQuery(request->requestQueryString()); if (!request->requestFragment().isEmpty()) targetUrl.setEncodedFragment(request->requestFragment()); QNetworkRequest proxiedRequest(targetUrl); foreach (const Pillow::HttpHeader& header, request->requestHeaders()) proxiedRequest.setRawHeader(header.first, header.second); createPipe(request, createProxiedReply(request, proxiedRequest)); return true; }
int main(int argc, char* argv[]) { char *pipeName = NULL; if (argc != 3) { return -1; } else { pipeName = argv[1]; g_sourcePID = atoi(argv[2]); } createPipe(pipeName); getchar(); return 0; }
pipe_t getPipe(char* name){ lockMutex(pipeMutex); int pos=whereIsPipe(name); if(pos!=-1){ unlockMutex(pipeMutex); return pipes[pos]; } pos = nextfreePipe(name); if(pos!=-1){ pipes[pos]=createPipe(name); unlockMutex(pipeMutex); return pipes[pos]; } unlockMutex(pipeMutex); return (pipe_t)0; }
ServerIPC (const StringArray& info) : InterprocessConnection (true), liveCodeBuilder (nullptr) { if (! createPipe (info[0], -1)) { Logger::writeToLog ("*** Couldn't create pipe!"); ProjucerApplication::getApp().systemRequestedQuit(); return; } if (dll.isLoaded()) liveCodeBuilder = dll.projucer_createBuilder (sendMessageCallback, this, info[1].toRawUTF8(), info[2].toRawUTF8()); #if JUCE_WINDOWS setParentProcessID (info[3].getHexValue32()); #endif zombieKiller = new ZombiePatrol (*this); }
int main(void) { PIPE * pipe = NULL; int ret; pid_t pid; ret = createPipe(&pipe); if (ret == -1) { printf("create fail!\n"); return -1; } pid = fork(); if (pid == 0) { setRDWRflag(pipe, WRITE); ret = writePipe(pipe, "Hello world!\n", 13); if (ret == -1) { printf("write pipe fail!\n"); closePipe(pipe); exit(1); } closePipe(pipe); exit(0); } if (pid > 0) { wait(NULL); setRDWRflag(pipe, READ); char buf[32]; bzero(buf, 32); ret = readPipe(pipe, buf, 13); if (ret == -1) { printf("read pipe fail!\n"); closePipe(pipe); exit(1); } printf("%s", buf); closePipe(pipe); exit(0); } }
void drawSprinkler (double width, double height, int xDivisions, double radius, double yzDivisions) { glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); GLfloat light_position[] = { 100.0, -100.0, 100.0, 0.0 }; GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat mat_shininess[] = { 50.0 }; GLfloat mat_ambient[] = {1.0, 0.0, 0.0}; glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient); glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); glLightfv(GL_LIGHT0, GL_POSITION, light_position); double angleDiff = 360.0 / xDivisions; double angle = 90; double x = 0; double xDiff = width / xDivisions; glTranslated(-width / 2.0, -20.0, 0.0); glColor3d(1.0, 1.0, 1.0); glBegin(GL_QUADS); for (int i = 0; i < xDivisions; i++) { double angleLeft = angle; angle += angleDiff; double angleRight = angle; double yLeft = sin(angleLeft * (M_PI / 180)) * height; double yRight = sin(angleRight * (M_PI / 180)) * height; createPipe(x, x + xDiff, yLeft, yRight, radius, yzDivisions); x += xDiff; } glEnd(); glDisable(GL_LIGHT0); glDisable(GL_LIGHTING); }
Status SyslogEventPublisher::setUp() { Status s; if (!pathExists(FLAGS_syslog_pipe_path)) { VLOG(1) << "Pipe does not exist. Creating pipe " << FLAGS_syslog_pipe_path; s = createPipe(FLAGS_syslog_pipe_path); if (!s.ok()) { LOG(WARNING) << RLOG(1964) << "Problems encountered creating pipe: " << s.getMessage(); } } fs::file_status file_status = fs::status(FLAGS_syslog_pipe_path); if (file_status.type() != fs::fifo_file) { return Status(1, "Not a FIFO file: " + FLAGS_syslog_pipe_path); } // Try to acquire a lock on the pipe, to make sure we're the only osquery // related proccess reading from it. s = lockPipe(FLAGS_syslog_pipe_path); if (!s.ok()) { return s; } // Opening with both flags appears to be the only way to open the pipe // without blocking for a writer. We won't ever write to the pipe, but we // don't want to block here and will instead block waiting for a read in the // run() method readStream_.open(FLAGS_syslog_pipe_path, std::ifstream::in | std::ifstream::out); if (!readStream_.good()) { return Status(1, "Error opening pipe for reading: " + FLAGS_syslog_pipe_path); } VLOG(1) << "Successfully opened pipe for syslog ingestion"; return Status(0, "OK"); }
// Decides what the application will do with the input it is given void parseInput(char* input) { char* string = malloc(sizeof(char) * strlen(input)); strcpy(string, input); char pipeDelim = '|'; char* tok = strtok(string, &pipeDelim); char* tok2 = strtok(NULL, &pipeDelim); // If token 2 isn't null then we have a pipe command if(tok2 != NULL) { if(createPipe(tok, tok2) != 0) { fprintf(stderr, "Pipe failed between: %s and %s\n", tok, tok2); } } else { // Check if the exit command was given, limit of 4 due to buffer messing up the compare over 4 letters if(strncmp(input, "exit", 4) == 0) { loop = 1; } else { length = strlen(input); // Check if the process should be run in the background and if so remove the ampersand and the new line and set background to 1 if(input[length-2] == '&') { background = 1; input[length-2] ='\0'; input[length-1] ='\0'; } else { background = 0; } // Find what the command was char* checkString = malloc ((sizeof (char*) * strlen(input)) +1 );; strcpy(checkString, input); char* token = strtok(checkString, " "); // If we're being told to change directory then we don't need to run in a new process if(strncmp(token, "cd", 2) == 0) { token = strtok (NULL, " "); if(changeDir(token) != 0) { fprintf(stderr, "Could not change directory to: %s", token); } } else { // Create a child process pid = fork(); switch(pid) { // Forking returned an error case -1: fprintf(stderr, "Fork failed"); break; // Child process case 0: if(call_system(input) == 1) fprintf(stderr, "System Call failed"); break; // Parent process checks if the child is being run in the background or not default: if(background == 1) waitpid(-1, NULL, 0); else signal(SIGCHLD, SIG_IGN); break; } } } } }
/* * Class: VM_0005fProcess * Method: exec4 * Signature: (Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;)I */ JNIEXPORT jint JNICALL Java_com_ibm_JikesRVM_VM_1Process_exec4 (JNIEnv *env, jobject self, jstring programName, jobjectArray argvArguments, jobjectArray environment, jstring dirPathStr) { // Get the program name StringPtr programString(convertString(env, programName)); #ifdef DEBUG fprintf(stderr, "program name is %s\n", programString.get()); #endif // Build argv array jsize argvLen = env->GetArrayLength((jarray) argvArguments); StringArray argv(argvLen); for (int i = 0; i < argvLen; ++i) { jstring arg = (jstring) env->GetObjectArrayElement(argvArguments, i); assert(arg); char *str = convertString(env, arg); #ifdef DEBUG fprintf(stderr, "arg %d is %s\n", i, str); #endif argv.setAndAdoptString(i, str); } // Build environment array (if any) jsize envpLen = (environment != 0) ? env->GetArrayLength((jarray) environment) : 0; StringArray envp(envpLen); for (int i = 0; i < envpLen; ++i) { jstring arg = (jstring) env->GetObjectArrayElement(environment, i); assert(arg); char *str = convertString(env, arg); #ifdef DEBUG fprintf(stderr, "env %d is %s\n", i, str); #endif envp.setAndAdoptString(i, str); } // Get the directory path (if any) StringPtr dirPath( (dirPathStr != 0) ? convertString(env, dirPathStr) : 0 ); #ifdef DEBUG fprintf(stderr, "working directory is %s\n", (dirPath.get() != 0) ? dirPath.get() : "unspecified, will use current"); #endif // Create pipes to communicate with child process. jclass ProcessClassID = env->FindClass( "com/ibm/JikesRVM/VM_Process" ); assert(ProcessClassID); int inputPipe[2], outputPipe[2], errorPipe[2]; pid_t fid = -1; int ret = createPipe(inputPipe, env, ProcessClassID, self, "inputDescriptor", OUTPUT); if (ret) goto fail; ret = createPipe(outputPipe, env, ProcessClassID, self, "outputDescriptor", INPUT); if (ret) goto close_inputPipe_and_fail; ret = createPipe(errorPipe, env, ProcessClassID, self, "errorDescriptor", INPUT); if (ret) goto close_outputPipe_and_fail; // do the exec fid = fork(); if (fid == 0) { // child // If a working directory was specified, try to // make it the current directory. if (dirPath.get() != 0) { if (chdir(dirPath.get()) != 0) { #ifdef DEBUG fprintf(stderr, "chdir() failed: %s\n", strerror(errno)); #endif // FIXME: // Presumably we should throw some sort of I/O error // (from Runtime.exec()) if we can't change into the // working directory the caller specified. // Instead, we just return this value as the exit code. exit(EXIT_STATUS_BAD_WORKING_DIR); } } #define SHOULD_NEVER_FAIL(cmd) do \ { \ if ((cmd) < 0) { \ perror(#cmd " failed, but should never; aborting"); \ abort(); \ } \ } while(0) /* Attach pipes to stdin, stdout, stderr These absolutely should never fail. */ SHOULD_NEVER_FAIL(dup2(inputPipe[INPUT], 0)); SHOULD_NEVER_FAIL(dup2(outputPipe[OUTPUT], 1)); SHOULD_NEVER_FAIL(dup2(errorPipe[OUTPUT], 2)); /* Close the original file descriptors returned by pipe(). Since they're already open, they should never fail either. */ SHOULD_NEVER_FAIL(closePipe(inputPipe)); SHOULD_NEVER_FAIL(closePipe(outputPipe)); SHOULD_NEVER_FAIL(closePipe(errorPipe)); // Set environment for child process. if (environment != 0) { environ = envp.get(); } #if 0 else { fprintf(stderr, "Current environment:\n"); char **p = environ; while (*p != 0 ) { fprintf(stderr, "\t%s\n", *p); ++p; } } #endif // Execute the program. // XXX See comment below on error handling. // int err = execvp(programString.get(), argv.get()); (void) execvp(programString.get(), argv.get()); // We get here only if an error occurred. #ifdef DEBUG fprintf(stderr, "execvp() failed: %s\n", strerror(errno)); #endif programString.release(); argv.release(); envp.release(); dirPath.release(); // FIXME: // Unfortunately, it's difficult to convey an error code // back to the parent process to let it know that we couldn't // actually execute the program. We could use shared memory // or a special pipe to send the error information. // For now, just exit with a non-zero status. /* However, traditionally the shell and xargs use status 127 to mean that * they were unable to find something to execute. * To quote the bash manpage, "If a command is found * but is not executable, the return status is 126.¨ * We shall adopt those customs here. --Steve Augart*/ if (errno == ENOENT || errno == ENOTDIR) exit(EXIT_STATUS_EXECUTABLE_NOT_FOUND); exit(EXIT_STATUS_COULD_NOT_EXECUTE); // couldn't be executed for some // other reason. } else if (fid > 0) { // parent // Store child's pid jfieldID pidFieldID = env->GetFieldID(ProcessClassID, "pid", "I"); assert(pidFieldID); env->SetIntField(self, pidFieldID, fid); #ifdef DEBUG fprintf(stderr, "child process id is %d\n", fid); #endif // Close unused ends of pipes // input side of child's stdin: SHOULD_NEVER_FAIL(close(inputPipe[INPUT])); // output side of child's stdout: SHOULD_NEVER_FAIL(close(outputPipe[OUTPUT])); // output side of child's stderr SHOULD_NEVER_FAIL(close(errorPipe[OUTPUT])); // Note: memory for programName, argv, and envp will be cleaned // up automatically #ifdef DEBUG fprintf(stderr, "done exec\n"); #endif return fid; } else { // An error occurred in fork() #ifdef DEBUG fprintf(stderr, "fork() failed: %s\n", strerror(errno)); #endif // Close pipes closePipe(errorPipe); close_outputPipe_and_fail: closePipe(outputPipe); close_inputPipe_and_fail: closePipe(inputPipe); fail: return -1; } }
// returns true only if pipes have been initialised successfully bool initStdHandles() { if (initialisedStdHandles) return true; #if 0 // Get I/O redirection arguments from command-line char* stdoutFilename; char* stderrFilename; char* stdinFilename; BOOL stdoutAppend; BOOL stderrAppend; BOOL stdinAppend; if (getRedirArgs(GetCommandLine(), &stdinFilename, &stdoutFilename, &stderrFilename, &stdinAppend, &stdoutAppend, &stderrAppend)) { } #endif TCHAR name[100]; HANDLE hFileMapping = NULL; unsigned char* pBuffer = NULL; _stprintf(name, TEXT("wcecompat.%08x.child_data"), GetCurrentProcessId()); hFileMapping = CreateFileMapping((HANDLE)INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, 1, name); if (hFileMapping == NULL) goto cleanup; else if (GetLastError() != ERROR_ALREADY_EXISTS) { CloseHandle(hFileMapping); hFileMapping = NULL; HANDLE hEvent = CreateEvent(NULL, FALSE, FALSE, TEXT("wcecompat.starting_child")); if (hEvent == NULL) { // failed to create named event } else if (GetLastError() == ERROR_ALREADY_EXISTS) { // we're in DllMain, so do nothing } else { CloseHandle(hEvent); } } else { pBuffer = (unsigned char*)MapViewOfFile(hFileMapping, FILE_MAP_WRITE, 0, 0, 0); if (pBuffer == NULL) { // failed to map buffer } else { g_childData = new ChildData; if (g_childData == NULL) goto cleanup; if (!g_childData->decode(pBuffer))//, 16384); goto cleanup; g_childData->restoreEnvironment(); RedirArg* stdinRedir = g_childData->getRedirArg(0); RedirArg* stdoutRedir = g_childData->getRedirArg(1); RedirArg* stderrRedir = g_childData->getRedirArg(2); if (stdinRedir != NULL && stdinRedir->redirType != RT_NONE) { if (stdinRedir->redirType == RT_PIPE_UNSPEC) { _FD_STRUCT* fds = fds_from_index(STDIN); if (fds == NULL) goto cleanup; fds->pipe = createPipe(stdinRedir->filename, OPEN_EXISTING); if (fds->pipe == NULL) { // failed to open stdin pipe goto cleanup; } fds->pipeChannel = (unsigned char)stdinRedir->fd2; } else if (stdinRedir->redirType == RT_HANDLE) { } else if (stdinRedir->redirType == RT_FILE) { // WCHAR* mode = L"r"; // default to "r" for the cases we don't know how to handle bool r = stdinRedir->openForRead; bool w = stdinRedir->openForWrite; bool a = stdinRedir->append; /* // rwa mode // 010 "w" // 011 "a" // 100 "r" // 110 "r+" // 111 "a+" if (a) { if (r) mode = L"a+"; else mode = L"a"; } else if (r) { if (w) mode = L"r+"; else mode = L"r"; } else if (w) mode = L"w"; FILE* f = _wfopen(stdinRedir->filename, mode); if (f == NULL) goto cleanup; memcpy(&mystdin, f, sizeof(_FD_STRUCT)); free(f); */ // rwa mode // 010 "w" w, CREATE_ALWAYS O_WRONLY O_CREAT|O_TRUNC // 011 "a" w, OPEN_ALWAYS (APPEND DATA) O_WRONLY O_APPEND O_CREAT // 100 "r" r, OPEN_EXISTING O_RDONLY // 110 "r+" r/w, OPEN_EXISTING O_RDWR // 111 "a+" r/w, OPEN_ALWAYS (APPEND DATA) O_RDWR O_APPEND O_CREAT int flags = 0; int mode = 0; if (r && w) flags |= O_RDWR; else if (r) flags |= O_RDONLY; else if (w) flags |= O_WRONLY; if (w) { if (!(r && !a)) { flags |= O_CREAT; mode = S_IREAD | S_IWRITE; } if (!r && !a) flags |= O_TRUNC; } if (a) flags |= O_APPEND; _FD_STRUCT* fds = fds_from_index(STDIN); if (fds == NULL) goto cleanup; if (!_wopen_fds(stdinRedir->filename, flags, mode, fds)) goto cleanup; } } if (stdoutRedir != NULL && stdoutRedir->redirType != RT_NONE) { if (stdoutRedir->redirType == RT_PIPE_UNSPEC) { _FD_STRUCT* fds = fds_from_index(STDOUT); if (fds == NULL) goto cleanup; fds->pipe = createPipe(stdoutRedir->filename, OPEN_EXISTING); if (fds->pipe == NULL) { // failed to open stdout pipe goto cleanup; } fds->pipeChannel = (unsigned char)stdoutRedir->fd2; } else if (stdoutRedir->redirType == RT_HANDLE) { } else if (stdoutRedir->redirType == RT_FILE) { // WCHAR* mode = L"r"; // default to "r" for the cases we don't know how to handle bool r = stdoutRedir->openForRead; bool w = stdoutRedir->openForWrite; bool a = stdoutRedir->append; /* // rwa mode // 010 "w" // 011 "a" // 100 "r" // 110 "r+" // 111 "a+" if (a) { if (r) mode = L"a+"; else mode = L"a"; } else if (r) { if (w) mode = L"r+"; else mode = L"r"; } else if (w) mode = L"w"; FILE* f = _wfopen(stdoutRedir->filename, mode); if (f == NULL) goto cleanup; memcpy(&mystdout, f, sizeof(_FD_STRUCT)); free(f); */ // rwa mode // 010 "w" w, CREATE_ALWAYS O_WRONLY O_CREAT|O_TRUNC // 011 "a" w, OPEN_ALWAYS (APPEND DATA) O_WRONLY O_APPEND O_CREAT // 100 "r" r, OPEN_EXISTING O_RDONLY // 110 "r+" r/w, OPEN_EXISTING O_RDWR // 111 "a+" r/w, OPEN_ALWAYS (APPEND DATA) O_RDWR O_APPEND O_CREAT int flags = 0; int mode = 0; if (r && w) flags |= O_RDWR; else if (r) flags |= O_RDONLY; else if (w) flags |= O_WRONLY; if (w) { if (!(r && !a)) { flags |= O_CREAT; mode = S_IREAD | S_IWRITE; } if (!r && !a) flags |= O_TRUNC; } if (a) flags |= O_APPEND; _FD_STRUCT* fds = fds_from_index(STDOUT); if (fds == NULL) goto cleanup; if (!_wopen_fds(stdoutRedir->filename, flags, mode, fds)) goto cleanup; } } if (stderrRedir != NULL && stderrRedir->redirType != RT_NONE) { if (stderrRedir->redirType == RT_PIPE_UNSPEC) { _FD_STRUCT* fds = fds_from_index(STDERR); if (fds == NULL) goto cleanup; if (stdoutRedir != NULL && stdoutRedir->redirType == RT_PIPE_UNSPEC && wcscmp(stderrRedir->filename, stdoutRedir->filename) == 0) { _FD_STRUCT* fds_stdout = fds_from_index(STDOUT); if (fds_stdout == NULL) goto cleanup; fds->pipe = fds_stdout->pipe; } else { fds->pipe = createPipe(stderrRedir->filename, OPEN_EXISTING); if (fds->pipe == NULL) { // failed to open stderr pipe goto cleanup; } } fds->pipeChannel = (unsigned char)stderrRedir->fd2; } else if (stderrRedir->redirType == RT_HANDLE) { } else if (stderrRedir->redirType == RT_FILE) { // WCHAR* mode = L"r"; // default to "r" for the cases we don't know how to handle bool r = stderrRedir->openForRead; bool w = stderrRedir->openForWrite; bool a = stderrRedir->append; /* // rwa mode // 010 "w" // 011 "a" // 100 "r" // 110 "r+" // 111 "a+" if (a) { if (r) mode = L"a+"; else mode = L"a"; } else if (r) { if (w) mode = L"r+"; else mode = L"r"; } else if (w) mode = L"w"; FILE* f = _wfopen(stderrRedir->filename, mode); if (f == NULL) goto cleanup; memcpy(&mystderr, f, sizeof(_FD_STRUCT)); free(f); */ // rwa mode // 010 "w" w, CREATE_ALWAYS O_WRONLY O_CREAT|O_TRUNC // 011 "a" w, OPEN_ALWAYS (APPEND DATA) O_WRONLY O_APPEND O_CREAT // 100 "r" r, OPEN_EXISTING O_RDONLY // 110 "r+" r/w, OPEN_EXISTING O_RDWR // 111 "a+" r/w, OPEN_ALWAYS (APPEND DATA) O_RDWR O_APPEND O_CREAT int flags = 0; int mode = 0; if (r && w) flags |= O_RDWR; else if (r) flags |= O_RDONLY; else if (w) flags |= O_WRONLY; if (w) { if (!(r && !a)) { flags |= O_CREAT; mode = S_IREAD | S_IWRITE; } if (!r && !a) flags |= O_TRUNC; } if (a) flags |= O_APPEND; _FD_STRUCT* fds = fds_from_index(STDERR); if (fds == NULL) goto cleanup; if (!_wopen_fds(stderrRedir->filename, flags, mode, fds)) goto cleanup; } } } } initialisedStdHandles = true; atexit(shutdownIo); cleanup: if (!initialisedStdHandles) uninitStdHandles(); if (pBuffer != NULL) UnmapViewOfFile(pBuffer); if (hFileMapping != NULL) CloseHandle(hFileMapping); return initialisedStdHandles; }
// Create a socket so we can talk to the player. bool GnashPluginScriptObject::createPipe() { log_debug(__PRETTY_FUNCTION__); #if 0 int p2c_pipe[2]; int c2p_pipe[2]; int p2c_controlpipe[2]; int ret = socketpair(AF_UNIX, SOCK_STREAM, 0, p2c_pipe); if (ret == -1) { gnash::log_error("ERROR: socketpair(p2c) failed: %s", strerror(errno)); return; } _streamfd = p2c_pipe[1]; ret = socketpair(AF_UNIX, SOCK_STREAM, 0, c2p_pipe); if (ret == -1) { gnash::log_error("ERROR: socketpair(c2p) failed: %s", strerror(errno)); return; } ret = socketpair(AF_UNIX, SOCK_STREAM, 0, p2c_controlpipe); if (ret == -1) { gnash::log_error("ERROR: socketpair(control) failed: %s", strerror(errno)); return; } _controlfd = p2c_controlpipe[1]; #endif #if 0 if ((_sockfds[READFD] == 0) && (_sockfds[WRITEFD] == 0)) { int ret = socketpair(AF_UNIX, SOCK_STREAM, 0, _sockfds); if (ret == 0) { // Set up the Glib IO Channel for reading from the plugin // log_debug("Read fd for socketpair is: %d", _sockfds[READFD]); _iochan[READFD] = g_io_channel_unix_new(_sockfds[READFD]); g_io_channel_set_close_on_unref(_iochan[READFD], true); _watchid = g_io_add_watch(_iochan[READFD], (GIOCondition)(G_IO_IN|G_IO_HUP), (GIOFunc)handleInvokeWrapper, this); // Set up the Glib IO Channel for writing to the plugin // log_debug("Write fd for socketpair is: %d", _sockfds[WRITEFD]); _iochan[WRITEFD] = g_io_channel_unix_new(_sockfds[WRITEFD]); g_io_channel_set_close_on_unref(_iochan[WRITEFD], true); return true; } } #endif #if 0 std::stringstream ss; static int count = 0; ss << "/tmp/gnash-" << getpid() << count++; return createPipe(ss.str()); #endif return false; }