示例#1
0
文件: main.c 项目: sebnow/mush
int main()
{
	char *prompt_argv[2] = {"prompt", "% "};
	cmd_prompt(2, prompt_argv);
	setupSignalHandler();
	run();
	return 0;
}
示例#2
0
文件: main.cpp 项目: pivaldi/TreeFrog
int main(int argc, char *argv[])
{
    TWebApplication webapp(argc, argv);

    // Setup loggers
    tSetupSystemLogger();
    tSetupLoggers();
    qInstallMsgHandler(messageOutput);

#if defined(Q_OS_UNIX)
    webapp.watchUnixSignal(SIGTERM);
    webapp.ignoreUnixSignal(SIGINT);

    // Setup signal handlers for SIGSEGV, SIGILL, SIGFPE, SIGABRT and SIGBUS
    setupFailureWriter(writeFailure);
    setupSignalHandler();
#endif

    // Sets codec
    QTextCodec *codec = QTextCodec::codecForName("UTF-8");  // default value
    QByteArray codecName = webapp.treefrogSettings().value("InternalEncoding").toByteArray().trimmed();
    if (!codecName.isEmpty()) {
        QTextCodec *c = QTextCodec::codecForName(codecName);
        if (c) {
            codec = c;
        } else {
            tWarn("no codec matching the name could be found: %s", codecName.data());
        }
    }
    QTextCodec::setCodecForTr(codec);
    QTextCodec::setCodecForLocale(codec);
    tSystemDebug("setCodecForTr: %s", codec->name().data());

    if (!webapp.webRootExists()) {
        tSystemError("No such directory");
        return 1;
    }
    tSystemDebug("Web Root: %s", qPrintable(webapp.webRootPath()));

    if (!webapp.settingsFileExists()) {
        tSystemError("Settings file not found");
        return 2;
    }
  
    QHash<QString, QString> args = convertArgs(QCoreApplication::arguments());
    TApplicationServer *server = new TApplicationServer(&webapp);
    QString arg = args.value("-s");
    if (!arg.isEmpty()) {
        // Sets a listening socket descriptor
        int sd = arg.toInt();
        if (sd > 0) {
            if (server->setSocketDescriptor(sd)) {
                tSystemDebug("Set socket descriptor: %d", sd);
            } else {
                tSystemError("Failed to set socket descriptor: %d", sd);
                return 3;
            }
        } else {
            tSystemError("Invalid socket descriptor: %d", sd);
            return 4;
        }
    }
    
    server->open();
    return webapp.exec();
}
示例#3
0
文件: util.cpp 项目: haoustc/server1
// Setup signal Term handler
void setupTermHandler(void (*sigtermHandler)(int))
{
    setupSignalHandler(SIGTERM, sigtermHandler);
}
示例#4
0
void TraceThread::run() {
	int status;
	long ret;
	pid_t trace_pid;
	unsigned long event_msg;

	setupSignalHandler();

	// attach to processes
	attach();

	// Check if the observed process is traced
	if (tasks.find(pid) == tasks.end()) {
		trace_mutex.unlock();
		context.report(Error::PROC_TRACE, "observed_process", "Cannot trace the observed_process");
	}

	context.info("Attached to all tasks of process " + QString::number(pid));
	trace_mutex.unlock();

	// start the loop for tracking process events
	while (true) {
		context.debug("Trace Thread is waiting");
		// set alarm
		alarm(3);
		trace_pid = waitpid(-1, &status, __WALL);
		alarm(0);

		if (alarm_occured) {
			context.debug("ALARM!");
			alarm_occured = false;

			if (exreq)
				break;
			else if (trace_pid == -1)
				continue;
		}

		if (trace_pid == -1) {
			context.report(Error::PROC_TRACE, "waitpid", "waitpid failed while tracing the observed process");
			continue;
		}

		context.debug("Got signal from: " + QString::number(trace_pid));

		// check return status of waitpid

		if (WIFEXITED(status) || WIFSIGNALED(status)) {
			tasks.erase(trace_pid);

			emit sig_TaskTerminated(trace_pid);

			if (pid == trace_pid) return;
		} else if (WIFSTOPPED(status)) {

			if (WSTOPSIG(status) == SIGTRAP) {
				ret = ptrace(PTRACE_GETEVENTMSG, trace_pid, nullptr, (void *)&event_msg);

				if (ret != 0)
					context.report(Error::PROC_TRACE, "ptrace_eventmsg", "Could not get ptrace event information");

				switch (status >> 16) {
				case (PTRACE_EVENT_CLONE):

				case (PTRACE_EVENT_FORK):

				case (PTRACE_EVENT_VFORK):
					newTask(event_msg);
					break;

				default:
					context.debug("Received unhandled ptrace event!");
					break;
				}

				ptraceContinue(trace_pid);

			} else if (WSTOPSIG(status) == SIGSTOP) {
				context.debug("Received stop signal!");

				if (tasks.find(trace_pid) != tasks.end()) {
					ptraceContinue(trace_pid);
				} else
					newTask(trace_pid);

			} else {
				context.debug("Received unhandled signal!");
				ptraceContinue(trace_pid, WSTOPSIG(status));
			}

		} else {