Exemple #1
0
void initialize()
{
	jobList = createList();
	using_history();
	bindKeys();
	initSignals(jumpBack);
}
bool CWizDatabaseManager::open(const QString& strKbGUID)
{
    Q_ASSERT(!m_strUserId.isEmpty());

    CWizDatabase* db = new CWizDatabase();

    bool ret = false;
    if (strKbGUID.isEmpty()) {
        ret = db->openPrivate(m_strUserId, m_strPasswd);
    } else {
        ret = db->openGroup(m_strUserId, strKbGUID);
    }

    if (!ret) {
        delete db;
        return false;
    }

    initSignals(db);

    if (strKbGUID.isEmpty()) {
        m_dbPrivate = db;
    } else {
        m_dbGroups.append(db);
    }

    Q_EMIT databaseOpened(strKbGUID);

    return true;
}
bool CWizDatabaseManager::openWithInfo(const QString& strKbGUID, const WIZDATABASEINFO* pInfo)
{
    Q_ASSERT(!m_strUserId.isEmpty());

    if (isOpened(strKbGUID))
        return true;

    CWizDatabase* db = new CWizDatabase();

    if (!db->Open(m_strUserId, strKbGUID)) {
        delete db;
        return false;
    }
    //
    if (pInfo)
    {
        db->InitDatabaseInfo(*pInfo);
    }

    if (strKbGUID.isEmpty()) {
        m_dbPrivate = db;

        // take ownership immediately
        connect(db, SIGNAL(databaseOpened(CWizDatabase*, const QString&)),
                SLOT(on_groupDatabaseOpened(CWizDatabase*, const QString&)),
                Qt::BlockingQueuedConnection);
    } else {
        m_mapGroups[strKbGUID] = db;
    }

    initSignals(db);

    Q_EMIT databaseOpened(strKbGUID);
    return true;
}
Exemple #4
0
/*
 * Start of the ssl client
 * There is a main thread and a receive thread
 * Main:
 *
 * Recv:
 */
main() {
	int status;
	pthread_t recvThread;
	pthread_t fsmThread;
	sslStruct *sslC;

	// For now this is just a function where we set all variables
	// Ultimately this should be read from a resource file
	initCfg();
	// Connect to Unit under Test (UT)
	initConnectionToServer();
	// Ctrl-Z to give stats
	initSignals();

	status = pthread_create(&recvThread, NULL, &recvFunction, (void*)NULL);
	if (status != 0) {
		perror("Start Thread Error:"); return -1;
	}
	status = pthread_create(&fsmThread, NULL, &fsmFunction, (void*)NULL);
	if (status != 0) {
		perror("Start Thread Error:"); return -1;
	}
	fflush(stdout);

	// For now just create 1 Client to test Server
	sslC = createClient();
	if (sslC == NULL)
		return -1;
	sendHello(sslC);
	while(1);
}
DatagramTransceiver::DatagramTransceiver(boost::asio::io_service &io_service, size_t max_data_length, QObject *parent)
    : QObject(parent),
      m_io_service(io_service),
      m_signals(io_service),
      m_socket(0),
      m_max_data_length(max_data_length)
{
    m_data_received = new char[m_max_data_length];
    initSignals();
}
Exemple #6
0
void tosThread_init()
{
#ifdef rt_LIB_Solaris2_SPARC
    thr_setconcurrency(5);
#endif
#if !defined(rt_LIB_Win32_i386)
    initSignals();
#endif

}
  void beginStimulusProcess() {
    vhdl << "   stimulus_proc: process\n";
    vhdl << "   begin\n";

    initSignals();

    vhdl << "      -- hold reset state for 100 ns.\n";
    vhdl << "      reset <= '1';\n";
    vhdl << "      wait for 100 ns;\n";
    vhdl << "      reset <= '0';\n";
  }
void CWizDatabaseManager::on_groupDatabaseOpened(CWizDatabase* pDb, const QString& strKbGUID)
{
    // check if this group is already opened, to avoid memory leak!
    if (isOpened(strKbGUID)) {
        close(strKbGUID, false);
    }

    m_mapGroups[strKbGUID] = pDb;
    initSignals(pDb);

    Q_EMIT databaseOpened(strKbGUID);
}
Horus::Commons::Network::StreamServer::StreamServer
(
    boost::asio::io_service &io_service,
    const boost::shared_ptr<StreamServerConnectionManager> &manager
) : m_manager(manager),
    m_signals(io_service),
    m_acceptor(io_service),
    m_new_connection(),
    m_address(StreamDefaults::default_address),
    m_port(StreamDefaults::default_port),
    m_running(false)
{
    initSignals();
}
Exemple #10
0
MprCmdService::MprCmdService()
{
    int		i;

#if BLD_FEATURE_MULTITHREAD
    mutex = new MprMutex();
#endif
    timer = 0;
    for (i = 0; i < MPR_CMD_REAP_MAX; i++) {
        children[i].pid = 0;
        children[i].exitStatus = 0;
    }
#if CYGWIN || LINUX || SOLARIS || VXWORKS || MACOSX
    initSignals();
#endif
}
Exemple #11
0
static void init(bool pDaemon, const char *pLogName, const char *pSafeDir)
{
  if (pDaemon) {
    forkChildAndExit();
    becomeSessionLeader();
    initSignals();
    forkChildAndExit(); // guarantee daemon is detached from a terminal permanently
    setFilePermissions();
    closeAllOpenFileDescrtiptors();
  }

  // always do the following
  initLog(pLogName);
  moveToSafeDirectory(pSafeDir);

  if (pDaemon) {
    notice("Started as daemon.");
  }
  else {
    notice("Started as interactive program.");
  }
}
Exemple #12
0
//-----------------------------------------------------------------------------
// 描述: 应用程序初始化 (若初始化失败则抛出异常)
//-----------------------------------------------------------------------------
void IseApplication::initialize()
{
    try
    {
#ifdef ISE_LINUX
        // 在初始化阶段要屏蔽退出信号
        SignalMasker sigMasker(true);
        sigMasker.setSignals(1, SIGTERM);
        sigMasker.block();
#endif

        networkInitialize();
        initExeName();
        iseBusiness_->beforeInit();
        iseBusiness_->initIseOptions(iseOptions_);
        processStandardArgs(true);
        checkMultiInstance();
     //   if (iseOptions_.getIsDaemon()) initDaemon();
        initSignals();
        initNewOperHandler();
        applyIseOptions();
        createMainServer();
        iseBusiness_->initialize();
        mainServer_->initialize();
        iseBusiness_->afterInit();
        if (iseOptions_.getIsDaemon()) closeTerminal();
        initialized_ = true;
    }
    catch (Exception& e)
    {
        openTerminal();
        iseBusiness_->onInitFailed(e);
        doFinalize();
        throw;
    }
}
Exemple #13
0
int main(int argc, char **argv)
{
    int ch;
    int nChildren = 0;
    static char *progname = "**UNSET**";

    /*
     * Parse the command line arguments.
     */
    progname = argv[0];
    for (;;) {
        ch = getopt_long(argc, argv, "c::ghnp", options, NULL);
        if (ch == -1)
            break;

        switch (ch) {

        case 'c':
            if (optarg)
                nChildren = atoi(optarg);
            else
                nChildren = 1;
            break;

        case 'g':
            showPgids = 1;
            break;

        case 'h':
            usage(progname);
            exit(0);

        case 'n':
            synchronize = 0;
            break;

        case 'p':
            showPpids = 1;
            break;

        default:
            printf("?? getopt returned character code 0x%02x ??\n", ch);
            exit(1);
        }
    }

    int count, childPid;
    initSignals();


    if(nChildren==0) {

        writeLog("main is pause()'d for a signal", __func__);
        pause();

    }
    else {
        for(count =0; count < nChildren; count++)
            childPid = fork();
        if(childPid == 0) {
            inChild(count);
        }
        else {
            char* message = malloc(2048);
            snprintf(message, 2048, "parent forked a child. iSibling %d child process %d", count, childPid);
            writeLog(message, __func__);
            free(message);
        }
    }
    inParent();


    exit(EXIT_SUCCESS);
    return 0;
}
Exemple #14
0
int MprTestSession::setupTests(MprTestResult *result, Mpr *mpr, int argc, 
	char *argv[], char *switches)
{
	char			switchBuf[80];
	char			*programName, *argp;
	int				errflg, c, i, l;
#if BLD_FEATURE_LOG
	char			*logSpec;
#endif

	this->mpr = mpr;
	programName = mprGetBaseName(argv[0]);
	errflg = 0;
#if BLD_FEATURE_LOG
	logSpec = "stdout:1";
	logger = new MprLogToFile();
#endif

	switchBuf[0] = '\0';
	mprStrcat(switchBuf, sizeof(switchBuf), 0, "cDeg:i:l:n:msT:t:v?", 
		switches, (void*) 0);
	MprCmdLine	cmdLine(argc, argv, switchBuf);

	while ((c = cmdLine.next(&argp)) != EOF) {
		switch(c) {
		case 'c':
			result->setContinueOnFailures(1);
			break;

		case 'D':
			mprSetDebugMode(1);
			result->setDebugOnFailures(1);
			break;

		case 'e':
			needEventsThread = 1;
			break;

		case 'g':
			testGroups->parse(argp);
			break;

		case 'i':
			iterations = atoi(argp);
			break;

		case 'l':
#if BLD_FEATURE_LOG
			logSpec = argp;
#endif
			break;

		case 'n':
			l = atoi(argp);
			if (l == 0) {
				sessionLevel = MPR_BASIC;
			} else if (l == 1) {
				sessionLevel = MPR_THOROUGH;
			} else {
				sessionLevel = MPR_DEDICATED;
			}
			break;

		case 'm':
			mprRequestMemStats(1);
			break;

		case 's':
			result->setSingleStep(1);
			break;

		case 't':
			i = atoi(argp);
			if (i <= 0 || i > 100) {
				mprFprintf(MPR_STDERR, "%s: Bad number of threads (0-100)\n", 
					programName);
				exit(2);
			
			}
#if BLD_FEATURE_MULTITHREAD
			numThreads = i;
#endif
			break;

		case 'T':
#if BLD_FEATURE_MULTITHREAD
			poolThreads = atoi(argp);
#endif
			break;

		case 'v':
			verbose++;
			break;

		default:
			//
			//	Ignore args we don't understand
			//
			break;

		case '?':
			errflg++;
			break;
		}
	}
	if (errflg) {
		mprFprintf(MPR_STDERR, 
			"usage: %s [-cDemsv] [-g groups] [-i iterations] "
			"[-l logSpec] [-n testLevel] [-T poolThreads] [-t threads]\n", 
			programName);
		exit(2);
	}

#if !BLD_FEATURE_MULTITHREAD
	needEventsThread = 0;
#endif

#if BLD_FEATURE_LOG
	mpr->addListener(logger);
	mpr->setLogSpec(logSpec);
#endif

	initSignals();

	this->argc = argc;
	this->argv = argv;
	this->firstArg = cmdLine.firstArg();

#if BLD_FEATURE_MULTITHREAD
	mpr->setMaxPoolThreads(poolThreads);
#endif
	if (mpr->start(needEventsThread ? MPR_SERVICE_THREAD : 0) < 0) {
		return MPR_ERR_CANT_INITIALIZE;
	}

	result->adjustThreadCount(numThreads);
	result->setVerbosity(verbose);
	if (result->getListenerCount() == 0) {
		result->addListener(new MprTestListener("__default__"));
	}

	if (verbose) {
		mprFprintf(MPR_STDOUT, 
			"Testing: iterations %d, threads %d, pool %d, service thread %d\n", 
			iterations, numThreads, poolThreads, needEventsThread);
	}

	//
	//	Use current session object for the main thread
	//
	sessions = (MprTestSession**) mprMalloc(sizeof(MprTestSession*) * 
		numThreads);
	sessions[0] = this;
	if (sessions[0]->initializeClasses(result) < 0) {
		exit(3);
	}

#if BLD_FEATURE_MULTITHREAD
	//
	//	Now clone this session object for all other threads
	//
	for (i = 1; i < numThreads; i++) {
		char tName[64];
		sessions[i] = this->newSession();
		sessions[i]->setResult(result);
		sessions[i]->cloneSettings(this);
		mprSprintf(tName, sizeof(tName), "test.%d", i);
	}
#endif
	return 0;
}
Exemple #15
0
int
main(int argc, char **argv)
{
    static char fname[] = "res/main";
    int nready;
    int maxfd;
    int i;
    char *sp;
    char *pathname = NULL;
    int didSomething = 0;
    char exbuf;

    time_t thisPeriodic, lastPeriodic = 0, timeDiff;


    fd_set rm, wm, em;

    int sbdPty = FALSE;
    char *sbdClHost = NULL;
    ushort sbdClPort = 0;
    char **sbdArgv = NULL;
    int selectError = 0;


    _i18n_init(I18N_CAT_RES);

    saveDaemonDir_(argv[0]);



    for (i=1; i<argc; i++) {
      if (strcmp(argv[i], "-d") == 0 && argv[i+1] != NULL) {
         pathname = argv[i+1];
         putEnv("LSF_ENVDIR",pathname);
         break;
      }
    }

    if (pathname == NULL) {
	if ((pathname = getenv("LSF_ENVDIR")) == NULL)
	    pathname = LSETCDIR;
    }


    if (argc > 1) {
        if (!strcmp(argv[1],"-V")) {
            fputs(_LS_VERSION_, stderr);
            exit(0);
        }
    }



    if ((ls_readconfenv(resConfParams, NULL) < 0) ||
        (initenv_(resParams, pathname) < 0) ) {
        if ((sp = getenv("LSF_LOGDIR")) != NULL)
            resParams[LSF_LOGDIR].paramValue = sp;
        ls_openlog("res", resParams[LSF_LOGDIR].paramValue, (debug > 1),
                   resParams[LSF_LOG_MASK].paramValue);
        ls_syslog(LOG_ERR, I18N_FUNC_S_FAIL_MM, fname, "initenv_",
            pathname);
        ls_syslog(LOG_ERR, I18N_Exiting);
        exit(-1);
    }



    restart_argc = argc;
    restart_argv = argv;
    for (i=1; i<argc; i++) {
	if (strcmp(argv[i], "-d") == 0 && argv[i+1] != NULL) {
	    pathname = argv[i+1];
	    i++;
	    continue;
	}

	if (strcmp(argv[i], "-1") == 0) {
	    debug = 1;
	    continue;
	}

	if (strcmp(argv[i], "-2") == 0) {
	    debug = 2;
	    continue;
	}


	if (strcmp(argv[i], "-PTY_FIX") == 0) {
	    printf("PTY_FIX");
	    exit(0);
	}


	if ( (strcmp(argv[i], "-j") == 0) && (argv[i+1] != NULL) ) {
	    lsbJobStarter = argv[++i];
	    continue;
	}

	if (strcmp(argv[i], "-P") == 0) {
	    sbdPty = TRUE;
	    continue;
	}

	if (strcmp(argv[i], "-i") == 0) {
	    sbdFlags |= SBD_FLAG_STDIN;
	    continue;
	}

	if (strcmp(argv[i], "-o") == 0) {
	    sbdFlags |= SBD_FLAG_STDOUT;
	    continue;
	}

	if (strcmp(argv[i], "-e") == 0) {
	    sbdFlags |= SBD_FLAG_STDERR;
	    continue;
	}

	if (strcmp(argv[i], "-m") == 0 && argv[i+1] != NULL) {
	    sbdClHost = argv[i+1];
	    i++;
	    sbdMode = TRUE;
	    continue;
	}

	if (strcmp(argv[i], "-p") == 0 && argv[i+1] != NULL) {
	    sbdClPort = atoi(argv[i+1]);
	    i++;
	    sbdMode = TRUE;
	    continue;
	}


	if (argv[i][0] != '-') {
	    sbdMode = TRUE;
	    sbdArgv = argv + i;
	    break;
	}

        usage(argv[0]);
    }

    if (sbdMode) {

	if (sbdClHost == NULL || sbdArgv == NULL) {
	    usage(argv[0]);
	    exit(-1);
	}
	if (sbdClPort) {
	    sbdFlags |= SBD_FLAG_TERM;
	} else {

	    sbdFlags |= SBD_FLAG_STDIN | SBD_FLAG_STDOUT | SBD_FLAG_STDERR;
	}
    } else {


	if (debug < 2)
	    for (i = sysconf(_SC_OPEN_MAX) ; i >= 0 ; i--)
		close(i);
    }


    if (resParams[LSF_SERVERDIR].paramValue == NULL) {
	ls_openlog("res", resParams[LSF_LOGDIR].paramValue, (debug > 1),
				   resParams[LSF_LOG_MASK].paramValue);
	ls_syslog(LOG_ERR, _i18n_msg_get(ls_catd , NL_SETN, 5001,
	    "LSF_SERVERDIR not defined in %s/lsf.conf: %M; res exiting"), /* catgets 5001 */
	    pathname);
	resExit_(-1);
    }


    if (! debug && resParams[LSF_RES_DEBUG].paramValue != NULL) {
	debug = atoi(resParams[LSF_RES_DEBUG].paramValue);
	if (debug <= 0)
	    debug = 1;
    }


    getLogClass_(resParams[LSF_DEBUG_RES].paramValue,
                 resParams[LSF_TIME_RES].paramValue);


    if (getuid() == 0 && debug) {
        if (sbdMode)  {
	   debug = 0;
	} else {
          ls_openlog("res", resParams[LSF_LOGDIR].paramValue, FALSE,
		   resParams[LSF_LOG_MASK].paramValue);
          ls_syslog(LOG_ERR, I18N(5005,"Root cannot run RES in debug mode ... exiting."));/*catgets 5005 */
	   exit(-1);
	}
    }

    if (debug > 1)
	ls_openlog("res", resParams[LSF_LOGDIR].paramValue, TRUE, "LOG_DEBUG");
    else {
 	ls_openlog("res", resParams[LSF_LOGDIR].paramValue, FALSE,
		   resParams[LSF_LOG_MASK].paramValue);
    }
    if (logclass & (LC_TRACE | LC_HANG))
        ls_syslog(LOG_DEBUG, "%s: logclass=%x", fname, logclass);

    ls_syslog(LOG_DEBUG, "%s: LSF_SERVERDIR=%s", fname, resParams[LSF_SERVERDIR].paramValue);



    init_res();
    initSignals();

    periodic(0);



    if (sbdMode) {
	lsbJobStart(sbdArgv, sbdClPort, sbdClHost, sbdPty);
    }

    maxfd = FD_SETSIZE;


    for (;;) {
        struct timeval *timep;
        struct timeval timeout;
loop:
        didSomething = 0;

        for (i = 0; i < child_cnt; i++) {
            if (children[i]->backClnPtr == NULL
                 && !FD_IS_VALID(conn2NIOS.sock.fd)
                 && children[i]->running == 0) {
                delete_child (children[i]);
            }
        }

	if (logclass & LC_TRACE) {
	    ls_syslog(LOG_DEBUG,"\
%s: %s Res child_res=<%d> child_go=<%d> child_cnt=<%d> client_cnt=<%d>",
		      fname, ((child_res) ? "Application" : "Root") ,
		      child_res, child_go, child_cnt, client_cnt);
            if (child_cnt == 1 && children != NULL && children[0] != NULL) {
                dumpChild(children[0], 1, "in main()");
            }
	}

        if (child_res && child_go && child_cnt == 0 && client_cnt == 0)  {


            if (debug > 1)
		printf (" \n Child <%d> Retired! \n", (int)getpid());

	    if (logclass & LC_TRACE) {
		ls_syslog(LOG_DEBUG,"\
%s: Application Res is exiting.....", fname);
	    }


	    millisleep_(5000);


	    if (sbdMode) {

		close(1);
		close(2);
		exit(lastChildExitStatus);
            }
	    resExit_(EXIT_NO_ERROR);
        }
Exemple #16
0
void WebView::setPage(QWebPage *page)
{
    QWebView::setPage(page);
    initSignals();
}
Exemple #17
0
void trikKernel::coreDumping::initCoreDumping()
{
	initSignals();
	setCoreLimits();
}
Exemple #18
0
static int realMain(MprCmdLine *cmdLine)
{
	MaHttp		*http;
	char        portNumBuf[MPR_MAX_IP_PORT];
	char		*argp, *logSpec;
	int			c, errflg, kill, poolThreads, outputVersion;

	mprSetMemHandler(memoryFailure);
	mprCreateMemHeap(0, 16 * 1024, MAXINT);
	program = mprGetBaseName(cmdLine->getArgv()[0]);

	poolThreads = -1;
	kill = errflg = 0;
	logSpec = 0;
	outputVersion = 0;
	autoScan = 1;
	background = 0;

	serverRoot = 0;
	docRoot = "web";

#if !WIN && !WINCE && !VXWORKS
	if (getuid()) {
		ipAddr = mprStrdup("4000");

	} else {
		mprSprintf(portNumBuf, sizeof(portNumBuf), "%d", 
			MA_SERVER_DEFAULT_PORT_NUM);
		ipAddr = mprStrdup(portNumBuf);
	}
#else
	mprSprintf(portNumBuf, sizeof(portNumBuf), "%d", 
		MA_SERVER_DEFAULT_PORT_NUM);
	    
	ipAddr = mprStrdup(portNumBuf);
#endif

	while ((c = cmdLine->next(&argp)) != EOF) {
		switch(c) {
		case 'A':
			autoScan = 0;
			break;

		case 'a':
			mprFree(ipAddr);
			ipAddr = mprStrdup(argp);
			break;
			
		case 'b':
			background++;
			break;

		case 'c':
			/* Ignored */
			break;

		case 'D':
			mprSetDebugMode(1);
			break;

		case 'd':
			docRoot = argp;
			break;

		case 'f':
#if BLD_FEATURE_CONFIG_PARSE
			configFile = argp;
			autoScan = 0;
#else
			errflg++;
#endif
			break;

		case 'k':
			kill++;
			logSpec = 0;
			break;

		case 'l':
			logSpec = (*argp) ? argp : 0;
			break;

		case 'm':
			mprRequestMemStats(1);
			break;

		case 'r':
			serverRoot = argp;
			break;
		
		case 't':
			poolThreads = atoi(argp);
			break;

			//
			//	FUTURE -- just for test. Will be removed
			//
		case 'w':
			writeFile = argp;
			break;

		case 'v':
			outputVersion++;
			break;
		
#if WIN && BLD_FEATURE_RUN_AS_SERVICE
		case 'i':
			serviceOp = MPR_INSTALL_SERVICE;
			if (strcmp(argp, "none") == 0) {
				serviceCmdLine = "";
			} else if (strcmp(argp, "default") == 0) {
				serviceCmdLine = "-b -c -f " BLD_PRODUCT ".conf";
			} else {
				serviceCmdLine = argp;
			}
			break;

		case 'g':
			serviceOp = MPR_GO_SERVICE;
			break;

		case 's':
			serviceOp = MPR_STOP_SERVICE;
			break;

		case 'u':
			serviceOp = MPR_UNINSTALL_SERVICE;
			break;

#endif
		default:
			errflg++;
			break;
		}
	}

	if (errflg) {
		printUsage(program);
		return MPR_ERR_BAD_SYNTAX;
	}	

	mp = new Mpr(program);
	mp->setAppName(BLD_PRODUCT);
	mp->setAppTitle(BLD_NAME);
	mp->setHeadless(isService || background);

#if BLD_HOST_UNIX || VXWORKS
	initSignals();
#endif

	if (kill) {
		mp->killMpr();
		delete mp;
		exit(0);
	}

	if (outputVersion) {
		printVersion();
		delete mp;
		exit(0);
	}

	//
	//	Create the top level HTTP service and default HTTP server
	//
	http = new MaHttp();
	server = new MaServer(http, "default");
	setupFileSystem();
	
	setLogging(logSpec);

	//
	//	Confirm the location of the server root
	//
	if (locateServerRoot(serverRoot) < 0) {
		mprError(MPR_L, MPR_USER, "Can't start server, exiting.");
		exit(2);
	}

	if (securityChecks(cmdLine->getArgv()[0]) < 0) {
		exit(3);
	}

#if WIN
#if BLD_FEATURE_RUN_AS_SERVICE
	if (serviceOp) {
		windowsServiceOps();
		delete mp;
		return 0;
	}
#endif
	if (windowsInit() < 0) {
		delete mp;
		return MPR_ERR_CANT_INITIALIZE;
	}
#endif

	//
	//	Start the MPR. This starts Timer, Socket and Pool services
	//
	if (mp->start(MPR_KILLABLE) < 0) {
		mprError(MPR_L, MPR_USER, "Can't start MPR for %s", mp->getAppTitle());
		delete mp;
		return MPR_ERR_CANT_INITIALIZE;
	}

	//
	//	Load the statically linked modules
	//
	maLoadStaticModules();

	if (setupServer(http, poolThreads) < 0) {
		mprError(MPR_L, MPR_USER, "Can't configure the server, exiting.");
		exit(6);
	}

#if BLD_FEATURE_CONFIG_SAVE
	if (writeFile) {
		server->saveConfig(writeFile);
		mprLog(0, "Configuration saved to %s\nExiting ...\n", writeFile);
		exit(0);
	}
#endif

	if (http->start() < 0) {
		mprError(MPR_L, MPR_USER, "Can't start server, exiting.");
		exit(7); 

	} else {
#if LINUX && BLD_FEATURE_RUN_AS_SERVICE
		if (background && mp->makeDaemon(1) < 0) {
			mprError(MPR_L, MPR_USER, "Could not run in the background");
		} else 
#endif
		{
#if BLD_FEATURE_MULTITHREAD
			mprLog(MPR_CONFIG, 
				"HTTP services are ready with %d pool threads\n",
				http->getLimits()->maxThreads);
#else
			mprLog(MPR_CONFIG, 
				"HTTP services are ready (single-threaded).\n");
#endif
		}
		mp->setHeadless(1);

		eventLoop();

		mprLog(MPR_WARN, "Stopping HTTP services.\n");
		http->stop();
	}

#if WIN
	if (trayIcon > 0) {
		closeTrayIcon();
	}
	if (trayTimer) {
		trayTimer->stop(MPR_TIMEOUT_STOP);
		trayTimer->dispose();
		trayTimer = 0;
	}
#endif

	mprLog(MPR_WARN, "Stopping MPR services.\n");
	mp->stop(0);
	maUnloadStaticModules();
	delete server;
	delete http;
	delete mp;

	mprFree(ipAddr);

#if BLD_FEATURE_ROMFS
	delete romFileSystem;
#endif

#if BLD_FEATURE_LOG
	mprLog(MPR_WARN, "Closing log.\n");
	if (logger) {
		delete logger;
	}
#if WIN
	if (dialog) {
		delete dialog;
	}
#endif
#endif
	return 0;
}
Exemple #19
0
int main(int argc, char **argv) {


    int sfiford;
    int sfifowr;
    int mfiford;
    int mfifowr;
    double x;

    int opID;
    double param;
    int i;
    int iWaitTime = 5;
    int iParams;
    int iLookedUp;
    struct result res;
    FILE *fPids;
    pid_t clientpid;

    initSignals();
    if(argc > 16) {
        fprintf(stderr, "You can enter maximum 16 command-line arguments");
        exit(1);
    }

    if(argc < 6) {
        fprintf(stderr, "You cannot enter less than 6 command-line arguments");
        exit(1);
    }

    fPids = fopen(PIDS, "a");
    fprintf(fPids, "%d\n", getpid());
    fclose(fPids);

    sprintf(sMainFifoName, "%s", &argv[1][1]);
    mkfifo(sMainFifoName, 0666);
    iWaitTime = atoi(&argv[2][1]);
    opID = atoi(&argv[3][1]);
    iLookedUp = 4;

    switch(opID) {
    case 1:
        res.opId = 1;
        break;
    case 2:
        res.opId = 2;
        break;
    case 3:
        res.opId = 3;
        break;
    case 4:
        res.opId = 4;
        break;
    default:
        fprintf(stderr, "Usage: You cannot enter less than 1 and grater that 4 as operation.\n");
        exit(1);
    }
    iParams = getParamNum(opID);
    clientpid = getpid();

    mfifowr = open(sMainFifoName, O_WRONLY);
    if (write(mfifowr, &clientpid, sizeof(clientpid)) < 0 || write(mfifowr, &opID, sizeof(opID)) < 0 || write(mfifowr, &iWaitTime, sizeof(iWaitTime)) < 0) {
        perror("write op");
        quit(EXIT_FAILURE);
    }
    close(mfifowr);

    mfiford = open(sMainFifoName, O_RDONLY);
    if(read(mfiford, &sspid, sizeof(sspid)) < 0 ||read(mfiford, &serverpid, sizeof(serverpid)) < 0 || read(mfiford, sServerFifoName, sizeof(sServerFifoName)) < 0) {
        perror("read client fifo");
        quit(EXIT_FAILURE);
    }
    close(mfiford);

    snprintf(sLogFileName, MAX, LOG_FILE_NAME, (long)serverpid);
    fprintf(stdout, "client got pid and sServerFifoName name from main fifo: %d, %s\n", serverpid, sServerFifoName);

    mkfifo(sServerFifoName, 0666);

    while(iLookedUp + iParams <= argc) {
        sfifowr = open(sServerFifoName, O_WRONLY);
        fprintf(stdout, "Sending parameters to math-server ");
        for(i = 0; i < iParams; ++i) {
            param = (double) atoi(&argv[iLookedUp++][1]);
            if(write(sfifowr, &param, sizeof(param)) < 0) {
                perror("write client fifo");
                quit(EXIT_FAILURE);
            }
            fprintf(stdout, "%f ", param);
        }
        fprintf(stdout, "\n");
        close(sfifowr);

        sfiford = open(sServerFifoName, O_RDONLY);
        if(read(sfiford, &res, sizeof(res)) < 0) {
            perror("read server fifo");
            quit(EXIT_FAILURE);
        }
        close(sfiford);

        if(handlerflag != 1) {
            appendLog(sLogFileName, serverpid, sServerFifoName);
            writeResultsToLog(sLogFileName, &res);
            writeResultsToConsole(&res);
        }
        else
            handlerflag = 0;

    }
    sfifowr = open(sServerFifoName, O_WRONLY);
    x = -9999.0;
    write(sfifowr, &x, sizeof(x));
    close(sfifowr);
    unlink(sServerFifoName);
    return 0;
}
Exemple #20
0
int main(int argc,char *argv[])
{
    struct pgpmainBones *mainbPtr = &_pgp_mainBones;
    struct pgpargsBones *argsbPtr;
    struct pgpfileBones *filebPtr;
    struct pgpenvBones *envbPtr;
    PGPContextRef mainContext;
    int errorLvl = 0, status;
    PGPError err = PGPsdkInit();
    pgpAssertNoErr(err);

    err = PGPsdkNetworkLibInit();
    pgpAssertNoErr(err);

    err = PGPNewContext( kPGPsdkAPIVersion, &mainContext );
    pgpAssertNoErr(err);

    err = pgpInitSDKPrefsDir( mainContext );
    pgpAssertNoErr(err);

    initMainBones( mainbPtr, mainContext );

    signonMsg(mainbPtr);

    /* link the context and initialize what used to be the global
       variables. */
    argsbPtr = mainbPtr->argsbPtr;
    filebPtr = mainbPtr->filebPtr;
    envbPtr = mainbPtr->envbPtr;
    err = pgpParseArgs( mainbPtr, argc, argv, &errorLvl);
    /* parse the arguments */
    if(err != 0)
        goto ex;

    if (argsbPtr->keyFlag && argsbPtr->keyChar == '\0') {
        keyUsage(filebPtr,&errorLvl);
        goto ex;
    }

    if (argsbPtr->groupFlag && argsbPtr->groupChar == '\0') {
        groupUsage(filebPtr,&errorLvl);
        goto ex;
    }

    /*
     * Write to stdout if explicitly asked to, or in filter mode and
     * no explicit file name was given.
     */
    mainbPtr->outputStdout = argsbPtr->outputFileName ?
        strcmp(argsbPtr->outputFileName, "-") == 0 : envbPtr->filterMode;

#if 1
    /* At request of Peter Simons, use stderr always. Sounds reasonable. */
    /* JIS: Put this code back in... removing it broke too many things */
    if (!mainbPtr->outputStdout)
        filebPtr->pgpout = stdout;
#endif

#if defined(PGP_UNIX) || defined(VMS)
    umask(077); /* Make files default to private */
#endif

    initSignals(); /* Catch signals */

    /* get our groups...*/
    err = pgpInitializeWorkingGroupSet( mainbPtr );

    if (argsbPtr->keyFlag) {
        status = doKeyOpt( mainbPtr, argsbPtr->keyChar, &errorLvl );
        if (status < 0) {
            userError(filebPtr,&errorLvl);
            goto ex;
        }
        errorLvl=status;
        goto ex;
    }

    if(argsbPtr->groupFlag) {
        status = doGroupOpt( mainbPtr, argsbPtr->groupChar, &errorLvl );
        if( status < 0 ) {
            userError(filebPtr,&errorLvl);
            goto ex;
        }
        errorLvl=status;
        goto ex;
    }

    err = pgpProcessArgs(mainbPtr, &errorLvl);

ex:
    err = pgpFinalizeWorkingGroupSet( mainbPtr );

    pgpTearDown( mainbPtr, &errorLvl );

    exit(errorLvl);
    /*NOTREACHED*/
    return errorLvl;
}
Exemple #21
0
/**
 * Function: main()
 * Description: main routine of the shell.
 * Synopsis: int main(int argc, char* argv[]) (conforms to ANSI C)
 * Return value:
 *   o An integer, indicating exit status.
 */
int
main(int argc, char* argv[])
{
	char* prompts[] =
	{
		"msh",
		"rshell",
		"rsnoop"
	};

	enum
	{
		P_MSH,
		P_RSHELL,
		P_RSNOOP
	};

	int prompt = P_MSH;

	printf
	(
		"\nWelcome to Microshell Client\nVersion: %s\nType '?' for help.\n",
		MICROSHELL_VERSION
	);

	memset(&status, 0, sizeof(sh_status_t));
	init();

	/* We loop until we get the quit signal */
	while(status.curr_signal != SH_QUIT)
	{
		char        cmdline[CMD_LINE_MAX_CHARS] = {0};
		/*sh_commands cmd_type;*/

		/* Save our state here to restart from here
		 * in case we got interrupted by a SIGALRM
		 */
		if(sigsetjmp(jmpbuf, SIGALRM))
		{
		}

		/* Prompt */
		printf("\n%s> ", prompts[prompt]);

		fgets(cmdline, CMD_LINE_MAX_CHARS, stdin);

		/* A copy of a command line for processing */
		strcpy(status.cmdline, cmdline);

		if(status.curr_signal == SH_REMOTE)
		{
			if(prompt == P_RSHELL)
				rshell(cmdline);
			else
				rsnoop(cmdline);
		}
		else
		{
			/* Parse the command line */
			status.curr_cmd = parseCmd(cmdline);

			prompt = P_MSH;

			/* Dispatch according to the command type */
			switch(status.curr_cmd)
			{
				case QUIT:
					status.curr_signal = SH_QUIT;
					/*disconnect();*/
					break;

				case SRV_RSHELL:
					/*rshell(cmdline);*/
					connectSnoopSrv(cmdline);
					prompt = P_RSHELL;
					break;

				case SRV_RSNOOP:
					/*rsnoop(cmdline);*/
					connectSnoopSrv(cmdline);
					prompt = P_RSNOOP;
					break;

				case REGISTER: /* Send connection request */

					if(status.connected == true)
						fprintf(stderr, "This client already opened a connection to the server!\n");
					else
					{
						connectTimeSrv();
						initSignals();
					}

					break;


				case SRV_VERSION: /* Send version request */

					if(status.connected == false)
						fprintf(stderr, "Server Version Request: Not connected to the server yet.\n");
					else
						srvVersion();

					break;


				case SRV_ELAPSED_TIME: /* Send eslsapsed time request */

					if(status.connected == false)
						fprintf(stderr, "Elapsed Time Request: Not connected to the server yet.\n");
					else
						srvElapsedTime();

					break;


				case SRV_TOD:/* Send time-of-the-day request */
					if(status.connected == false)
						fprintf(stderr, "Time of the Day Request: Not connected to the server yet.\n");
					else
						srvTOD();

					break;


				case PIPELINE:
					execPipeline(status.pipeline_size, -1);
					reset();
					break;


				case HELP:
					showHelp();
					break;


				case BLANK:
				case UNKNOWN: /* UNKNOWN was meant for error checking. Unused. */
					reset();
					break;


				default:
					fprintf(stderr, "msh: Unexpected command type: %d (internal error)\n", status.curr_cmd);
					exit(1);
			} /* switch(status.curr_cmd) */
		} /* !SH_REMOTE */

		/* Make sure we don't have anything in those streams */
		fflush(stdout);
		fflush(stdin);
		fflush(stderr);

	} /*  while(not QUIT) */

	exit(0);

} /* main() */