KoFilter::ConversionStatus ChainLink::invokeFilter(const ChainLink *const parentChainLink) { if (!m_filterEntry) { kError(30500) << "This filter entry is null. Strange stuff going on." << endl; return KoFilter::CreationError; } m_filter = m_filterEntry->createFilter(m_chain); if (!m_filter) { kError(30500) << "Couldn't create the filter." << endl; return KoFilter::CreationError; } if (m_updater) { // if there is an updater, use that for progress reporting m_filter->setUpdater(m_updater); } if (parentChainLink) { setupCommunication(parentChainLink->m_filter); } KoFilter::ConversionStatus status = m_filter->convert(m_from, m_to); delete m_filter; m_filter = 0; return status; }
void setup() { /* set up pins */ pinMode(CALIB_SWITCH, INPUT); pinMode(BOT_SWITCH, INPUT); pinMode(RED_LED, OUTPUT); pinMode(YELLOW_LED, OUTPUT); pinMode(GREEN_LED, OUTPUT); pinMode(BLUE_LED, OUTPUT); Serial.begin(9600); setupPhotosensor(); setupMotorControl(); setupCollision(); setupCommunication(); }
bool K3Process::start(RunMode runmode, Communication comm) { if (runs) { qDebug() << "Attempted to start an already running process" << endl; return false; } uint n = arguments.count(); if (n == 0) { qDebug() << "Attempted to start a process without arguments" << endl; return false; } char **arglist; QByteArray shellCmd; if (d->useShell) { if (d->shell.isEmpty()) { qDebug() << "Invalid shell specified" << endl; return false; } for (uint i = 0; i < n; i++) { shellCmd += arguments[i]; shellCmd += ' '; // CC: to separate the arguments } arglist = static_cast<char **>(malloc( 4 * sizeof(char *))); arglist[0] = d->shell.data(); arglist[1] = (char *) "-c"; arglist[2] = shellCmd.data(); arglist[3] = 0; } else { arglist = static_cast<char **>(malloc( (n + 1) * sizeof(char *))); for (uint i = 0; i < n; i++) arglist[i] = arguments[i].data(); arglist[n] = 0; } run_mode = runmode; if (!setupCommunication(comm)) { qDebug() << "Could not setup Communication!" << endl; free(arglist); return false; } // We do this in the parent because if we do it in the child process // gdb gets confused when the application runs from gdb. #ifdef HAVE_INITGROUPS struct passwd *pw = geteuid() ? 0 : getpwuid(getuid()); #endif int fd[2]; if (pipe(fd)) fd[0] = fd[1] = -1; // Pipe failed.. continue // we don't use vfork() because // - it has unclear semantics and is not standardized // - we do way too much magic in the child pid_ = fork(); if (pid_ == 0) { // The child process close(fd[0]); // Closing of fd[1] indicates that the execvp() succeeded! fcntl(fd[1], F_SETFD, FD_CLOEXEC); if (!commSetupDoneC()) qDebug() << "Could not finish comm setup in child!" << endl; // reset all signal handlers struct sigaction act; sigemptyset(&act.sa_mask); act.sa_handler = SIG_DFL; act.sa_flags = 0; for (int sig = 1; sig < NSIG; sig++) sigaction(sig, &act, 0L); if (d->priority) setpriority(PRIO_PROCESS, 0, d->priority); if (!runPrivileged()) { setgid(getgid()); #ifdef HAVE_INITGROUPS if (pw) initgroups(pw->pw_name, pw->pw_gid); #endif if (geteuid() != getuid()) setuid(getuid()); if (geteuid() != getuid()) _exit(1); } setupEnvironment(); if (runmode == DontCare || runmode == OwnGroup) setsid(); const char *executable = arglist[0]; if (!d->executable.isEmpty()) executable = d->executable.data(); execvp(executable, arglist); char resultByte = 1; write(fd[1], &resultByte, 1); _exit(-1); } else if (pid_ == -1) { // forking failed // commAbort(); pid_ = 0; free(arglist); return false; } // the parent continues here free(arglist); if (!commSetupDoneP()) qDebug() << "Could not finish comm setup in parent!" << endl; // Check whether client could be started. close(fd[1]); for(;;) { char resultByte; int n = ::read(fd[0], &resultByte, 1); if (n == 1) { // exec() failed close(fd[0]); waitpid(pid_, 0, 0); pid_ = 0; commClose(); return false; } if (n == -1) { if (errno == EINTR) continue; // Ignore } break; // success } close(fd[0]); runs = true; switch (runmode) { case Block: for (;;) { commClose(); // drain only, unless obsolete reimplementation if (!runs) { // commClose detected data on the process exit notifification pipe K3ProcessController::instance()->unscheduleCheck(); if (waitpid(pid_, &status, WNOHANG) != 0) // error finishes, too { commClose(); // this time for real (runs is false) K3ProcessController::instance()->rescheduleCheck(); break; } runs = true; // for next commClose() iteration } else { // commClose is an obsolete reimplementation and waited until // all output channels were closed (or it was interrupted). // there is a chance that it never gets here ... waitpid(pid_, &status, 0); runs = false; break; } } // why do we do this? i think this signal should be emitted _only_ // after the process has successfully run _asynchronously_ --ossi emit processExited(this); break; default: // NotifyOnExit & OwnGroup input_data = 0; // Discard any data for stdin that might still be there break; } return true; }