void ShellWorker::perform() { output_.clear(); child_ = vfork(); switch (child_) { case -1: // error perror("vfork"); finish(false); break; case 0: // in child setupChild(); break; default: // in parent setupParent(); break; } }
bool PlayLayer::init() { if(!Layer::init()) { return false; } currentLevel = CCUserDefault::getInstance()->getIntegerForKey("currentLevel"); if(currentLevel == 0) { currentLevel = 1; CCUserDefault::getInstance()->setIntegerForKey("currentLevel", currentLevel); CCUserDefault::getInstance()->flush(); } bestDistance = CCUserDefault::getInstance()->getIntegerForKey("bestDistance"); terrain = NULL; truck = NULL; setupChild(); return true; }
int Process::start(const std::string& exe, const ArgumentList& args, const Environment& env, const std::string& workdir) { #if !defined(NDEBUG) //::fprintf(stderr, "proc[%d] start(exe=%s, args=[...], workdir=%s)\n", getpid(), exe.c_str(), workdir.c_str()); for (int i = 3; i < 32; ++i) if (!(fcntl(i, F_GETFD) & FD_CLOEXEC)) fprintf(stderr, "Process: fd %d still open\n", i); #endif switch (pid_ = vfork()) { case -1: // error fprintf(stderr, "Process: error starting process: %s\n", strerror(errno)); return -1; case 0: // child setupChild(exe, args, env, workdir); break; default: // parent setupParent(); break; } return 0; }
/** * now we will send the file. * * we request an fd. The IOLayer should be closed * then we will setup a pipe for progress communication * then we will dup2 the m_fd in the forked process * to do direct IO from and to the fd */ void FileTransfer::sendFile( const QString& file ) { m_prog =-1; m_fd = layer()->rawIO(); // // m_fd = ::open("/dev/ttyS0", O_RDWR); m_file = file; if ( pipe( m_comm ) < 0 ) m_comm[0] = m_comm[1] = 0; if ( pipe( m_info ) < 0 ) m_info[0] = m_info[1] = 0; m_pid = fork(); switch( m_pid ) { case -1: emit error( StartError, tr("Was not able to fork") ); slotExec(); break; case 0:{ setupChild(); /* exec */ char* verbose = "-vv"; char* binray = "-b"; char* typus; switch(m_type ) { default: case SZ: typus = ""; break; case SX: typus = "-X"; break; case SY: typus = "--ymodem"; break; } /* we should never return from here */ execlp("sz", "sz", verbose, binray, file.latin1(), typus, NULL ); /* communication for error!*/ char resultByte =1; if (m_info[1] ) write(m_info[1], &resultByte, 1 ); _exit( -1 ); break; } default:{ if ( m_info[1] ) close( m_info[1] ); if ( m_info[0] ) for (;;) { char resultByte; int len; len = read(m_info[0], &resultByte, 1 ); /* len == 1 start up failed */ if ( len == 1 ) { emit error( StartError, tr("Could not start") ); return; } if ( len == -1 ) if ( (errno == ECHILD ) || (errno == EINTR ) ) continue; // len == 0 or something like this break; } if ( m_info[0] ) close( m_info[0] ); /* replace by QSocketNotifier!!! */ m_not = new QSocketNotifier(m_comm[0], QSocketNotifier::Read ); connect(m_not, SIGNAL(activated(int) ), this, SLOT(slotRead() ) ); if ( pipe(m_term) < 0 ) m_term[0] = m_term[1] = 0; ProcCtl::self()->add(m_pid, m_term[1] ); m_proc = new QSocketNotifier(m_term[0], QSocketNotifier::Read ); connect(m_proc, SIGNAL(activated(int) ), this, SLOT(slotExec() ) ); } break; } }