Ejemplo n.º 1
0
int main(int argc, char * const * argv)
{
    InitModuleObjects();
    try
    {
        KeyPatchParams params;
        getParams(argc, argv, params);
        Owned<IKeyDiffApplicator> applicator;
        if(params.mode == KEYPATCH_explicit)
            applicator.setown(createKeyDiffApplicator(params.patch.str(), params.oldIndex.str(), params.newIndex.str(), params.newTLK.str(), params.overwrite, params.ignoreTLK));
        else
            applicator.setown(createKeyDiffApplicator(params.patch.str(), params.overwrite, params.ignoreTLK));
        if(params.mode == KEYPATCH_info)
            showInfo(params.patch.str(), applicator);
        else
        {
            if(params.xmitTLK)
                applicator->setTransmitTLK(new CNodeSender(params.tlkPort, params.xmitEp));
            else if(params.recvTLK)
                applicator->setReceiveTLK(new CNodeReceiver(params.tlkPort), params.recvNum);
            if(params.progressFrequency)
                applicator->setProgressCallback(new KeyPatchProgressCallback, params.progressFrequency);
            applicator->run();
        }
    }
    catch(IException * e)
    {
        EXCLOG(e);
        e->Release();
        releaseAtoms();
        return 1;
    }
    releaseAtoms();
    return 0;
}
Ejemplo n.º 2
0
int main(int argc, char* argv[])
{
    InitModuleObjects();
    // These are the internal unit tests covered by other modules and libraries
    Array objects;
    objects.append(*(new LoadedObject ("jhtree")));
    objects.append(*(new LoadedObject ("roxiemem")));
    objects.append(*(new LoadedObject ("thorhelper")));

    queryStderrLogMsgHandler()->setMessageFields(MSGFIELD_time);
    CppUnit::TextUi::TestRunner runner;
    if (argc==1)
    {
        CppUnit::TestFactoryRegistry &registry = CppUnit::TestFactoryRegistry::getRegistry();
        runner.addTest( registry.makeTest() );
    }
    else 
    {
        for (int name = 1; name < argc; name++)
        {
            CppUnit::TestFactoryRegistry &registry = CppUnit::TestFactoryRegistry::getRegistry(argv[name]);
            runner.addTest( registry.makeTest() );
        }
    }
    bool wasSucessful = runner.run( "", false );
    ExitModuleObjects();
    releaseAtoms();
    return wasSucessful;
}
Ejemplo n.º 3
0
int main(int argc, char **argv) 
{ 
    InitModuleObjects();

    addAbortHandler(ControlHandler);

    try
    { 
        execSvr.setown(new CEclAgentExecutionServer());
        execSvr->start();
    } 
    catch (...)
    {
        printf("Unexpected error running agentexec server\r\n");
    }
    if (execSvr)
    {
        execSvr->stop();
    }

    releaseAtoms();
    ExitModuleObjects();

    return 0;
} 
Ejemplo n.º 4
0
int main(int argc, char* argv[])
{
    
    enableMemLeakChecking(true);

    InitModuleObjects();
    EnableSEHtoExceptionMapping();

    if (argc<2) {
        usage(argv[0]);
        return -1;
    }
    SocketEndpoint dalieps(argv[1],DALI_SERVER_PORT);       // endpoint of dali server
    Owned<IGroup> group = createIGroup(1,&dalieps); 

    try {
        initClientProcess(group, DCR_Other);            // I will add a DCR_Orbit at some point
        try {
            doStuff();
        }
        catch (IException *e) {
            pexception(argv[0],e);
            e->Release();
        }
        closedownClientProcess();
    }
    catch (IException *e) {
        pexception(argv[0],e);
        e->Release();
    }
    releaseAtoms();
    return 0;
}
Ejemplo n.º 5
0
int main(int argc, char **argv) 
{ 
    InitModuleObjects();

    addAbortHandler(ControlHandler);

    try
    { 
        StringBuffer codeDirectory;
        splitFilename(argv[0], &codeDirectory, &codeDirectory, NULL, NULL);
        if (!codeDirectory.length())
            codeDirectory.append(".");
        
        execSvr.setown(new CEclAgentExecutionServer());
        execSvr->start(codeDirectory);
    } 
    catch (...)
    {
        printf("Unexpected error running agentexec server\r\n");
    }
    if (execSvr)
    {
        execSvr->stop();
    }

    releaseAtoms();
    ExitModuleObjects();

    return 0;
} 
Ejemplo n.º 6
0
void usage(bool isHelp)
{
    printf("usage:\n"
           "  keypatch [options] patch oldindex newindex\n"
           "  keypatch [options] patch\n"
           "options are:\n"
           "   -o --overwrite              overwrite new index file if it exists\n"
           "   -n --nooverwrite            abort if new index file exists (default)\n"
           "   -t --transmit port ip:port  send TLK data to a receiver to be collated\n"
           "                               (sends from given port to given ip:port)\n"
           "   -s --skiptlk                suppresses the warning when patch contains\n"
           "                               TLK header data and -r is not selected\n"
           "   -p --progress freq          log progress reading old index at intervals of freq bytes\n"
           "Using the single argument form of the command, the filenames of the old\n"
           "and new index files are those used to generate the patch.\n"
           "\n"
           "usage:\n"
           "   keypatch [options] [-r | --receive] port num patch oldindex newindex newtlk\n"
           "   keypatch [options] [-r | --receive] port num patch\n"
           "options are:\n"
           "   -o --overwrite              overwrite new index and TLK files if they exist\n"
           "   -n --nooverwrite            abort if new index or TLK files exist (default)\n"
           "These forms of the command listen on the given port to receive and collate TLK\n"
           "data (in addition to applying patch for this part as normal). They will listen\n"
           "for num parts.\n"
           "\n"
           "usage:\n"
           "  keypatch [-v | --version ]\n"
           "  keypatch [-h | -? | --help ]\n"
           "  keypatch [-i| --info] patch\n"
           "The --info option shows the names of the old and new index files\n"
           "and the version of keydiff used to generate the patch, then stops.\n\n");
    releaseAtoms();
    exit(isHelp ? 0 : 2);
}
Ejemplo n.º 7
0
int main(int argc, char* argv[])
{
    InitModuleObjects();
    EnableSEHtoExceptionMapping();

    if (argc<6)
    {
        usage();
        return 0;
    }

    try
    {
        const char *filename = argv[1];
        Owned<IDaliCapabilityCreator> cc = createDaliCapabilityCreator();
        cc->setSystemID(argv[2]);
        cc->setServerPassword(argv[3]);
        for (unsigned i=4;i<argc;i++) {
            const char *cmd = argv[i++];
            if (i==argc)
                break;
            const char *param = argv[i];
            if (stricmp(cmd,"THORWIDTH")==0) {
                cc->setLimit(DCR_ThorSlave,atoi(param));
            }
            else if (stricmp(cmd,"DALINODE")==0) {
                StringBuffer mac;
                if (strchr(param,'.')) { // must be ip
                    IpAddress ip;
                    ip.set(param);
                    if (!getMAC(ip,mac)) {
                        printf("ERROR: could mot get MAC address for %s\n",param);
                        return 1;
                    }
                }
                else
                    mac.append(param);
                cc->addCapability(DCR_DaliServer,mac.str());
            }
            else {
                printf("ERROR: unknown command %s\n",cmd);
                return 1;
            }
        }
        StringBuffer results;
        cc->save(results);
        Owned<IFile> ifile = createIFile(filename);
        Owned<IFileIO> ifileio = ifile->open(IFOcreate);
        ifileio->write(0,results.length(),results.str());
        printf("Dali Capabilities sucessfully exported to %s\n", filename);
    }
    catch (IException *e)
    {
        EXCLOG(e);
        e->Release();
    }

    releaseAtoms();
    return 0;
}
Ejemplo n.º 8
0
int main(int argc, const char *argv[])
{
    InitModuleObjects();
    queryStderrLogMsgHandler()->setMessageFields(0);
    unsigned exitCode = doMain(argc, argv);
    releaseAtoms();
    exit(exitCode);
}
Ejemplo n.º 9
0
int main(int argc, char* argv[])
{
    start_init_main(argc, argv, init_main);
    stopPerformanceMonitor();
    UseSysLogForOperatorMessages(false);
    releaseAtoms();
    return 0;
}
Ejemplo n.º 10
0
int main( int argc, char *argv[] )
{
    int res=0;
    if (argc < 3)
    {
        printf
            ("frunssh <nodelistfile> \"command\" [options] \n"
            "    options: -i:<identity-file> \n"
            "             -u:<user> \n"
            "             -n:<number_of_threads>\n"
            "             -t:<connect-timeout-secs>\n"
            "             -a:<connect-attempts>\n"
            "             -d:<working_directory>\n"
            "             -s                -- strict, must match known_hosts\n"
            "             -b                -- background\n"
            "             -pw:<password>    -- INSECURE: requires pssh (NB identity file preferred)\n"
            "             -pe:<password>    -- INSECURE: as -pw except encrypted password\n"
            "             -pl               -- use plink (on windows)\n"
            "             -v                -- verbose, lists commands run\n"
            "             -d                -- dry run (for testing, enables verbose)\n"
            );
        return 255;
    }


    InitModuleObjects();

#ifndef __64BIT__
    // Restrict stack sizes on 32-bit systems
    Thread::setDefaultStackSize(0x10000);   // NB under windows requires linker setting (/stack:)
#endif

    try  {
        StringBuffer logname;
        splitFilename(argv[0], NULL, NULL, &logname, NULL);

        Owned<IComponentLogFileCreator> lf = createComponentLogFileCreator("frunssh");
        lf->setCreateAliasFile(false);
        lf->setMsgFields(MSGFIELD_prefix);
        lf->beginLogging();

        Owned<IFRunSSH> runssh = createFRunSSH();
        runssh->init(argc,argv);
        runssh->exec();
    }
    catch(IException *e)
    {
        EXCLOG(e,"frunssh");
        e->Release();
        res=255;
    }
    releaseAtoms();
    return res;
}
Ejemplo n.º 11
0
int main( int argc, char *argv[] )
{
    int res=0;
    if (argc < 3)
    {
        printf
            ("frunssh <nodelistfile> \"command\" [options] \n"
            "    options: -i:<identity-file> \n"
            "             -u:<user> \n"
            "             -n:<number_of_threads>\n"
            "             -t:<connect-timeout-secs>\n"
            "             -a:<connect-attempts>\n"
            "             -d:<working_directory>\n"
            "             -s                -- strict, must match known_hosts\n"
            "             -b                -- background\n"
            "             -pw:<password>    -- INSECURE: requires pssh (NB identity file preferred)\n"
            "             -pe:<password>    -- INSECURE: as -pw except encrypted password\n"
            "             -pl               -- use plink (on windows)\n"
            "             -v                -- verbose, lists commands run\n"
            "             -d                -- dry run (for testing, enables verbose)\n"
            );
        return 255;
    }


    InitModuleObjects();
    try  {
        StringBuffer logname;
        splitFilename(argv[0], NULL, NULL, &logname, NULL);
        StringBuffer logdir;
        if (getConfigurationDirectory(NULL,"log","frunssh",logname.str(),logdir)) {
            recursiveCreateDirectory(logdir.str());
            StringBuffer tmp(logname);
            addPathSepChar(logname.clear().append(logdir)).append(tmp);
        }
        addFileTimestamp(logname, true);
        logname.append(".log");
        appendLogFile(logname.str(),0,false);
        queryStderrLogMsgHandler()->setMessageFields(MSGFIELD_prefix);

        Owned<IFRunSSH> runssh = createFRunSSH();
        runssh->init(argc,argv);
        runssh->exec();
    }
    catch(IException *e)
    {
        EXCLOG(e,"frunssh");
        e->Release();
        res=255;
    }
    releaseAtoms();
    return res;
}
Ejemplo n.º 12
0
void fatal(const char *format, ...)
{
    va_list      args;

    va_start(args, format);
    vfprintf(stderr, format, args);
    va_end(args);
    fflush(stderr);
    releaseAtoms();
    ExitModuleObjects();
    _exit(2);
}
Ejemplo n.º 13
0
void version(bool isHelp)
{
    StringBuffer buff("This is keydiff version ");
    getKeyDiffVersion(buff).append(".\nPatches it generates can be applied by keypatch since version ");
    getKeyDiffMinPatchVersionForDiff(buff).append(".\n");
    buff.append("To discover whether patches it generates can be applied by versions\n"
                "of keypatch later than itself, see keypatch -v.\n\n");
    printf("%s", buff.str());
    if(isHelp)
        usage(true);
    releaseAtoms();
    exit(0);
}
Ejemplo n.º 14
0
void version(bool isHelp)
{
    StringBuffer buff("This is keypatch version ");
    getKeyDiffVersion(buff).append(".\nIt can apply patches generated by keydiff since version ");
    getKeyDiffMinDiffVersionForPatch(buff).append(".\n");
    buff.append("To discover whether it can apply patches generated by versions\n"
                "of keydiff later than itself, see keydiff -v.\n\n");
    printf("%s", buff.str());
    if(isHelp)
        usage(true);
    releaseAtoms();
    exit(0);
}
Ejemplo n.º 15
0
int main(int argc, char* argv[])
{
    printf("\n\n");
    test1();
    printf("\n\n");
    test2();    
    printf("\n\n");
    test3();    
    printf("\n\n");
    test4();    

    releaseAtoms();

    return 1;
}
Ejemplo n.º 16
0
void usage()
{
    fprintf(stderr, "Usage: dumpkey dataset [options]\n"
        "Options:\n"
        "  node=[n]            - dump node n (0 = just header)\n"
        "  fpos=[n]            - dump node at offset fpos\n"
        "  recs=[n]            - dump n rows\n"
        "  -H                  - hex display\n"
        "  -R                  - raw output\n"
                    );
    fflush(stderr);
    releaseAtoms();
    ExitModuleObjects();
    _exit(2);
}
Ejemplo n.º 17
0
int main(int argc, char * const * argv)
{
    InitModuleObjects();
    try
    {
        KeyDiffParams params;
        getParams(argc, argv, params);
        Owned<IKeyDiffGenerator> generator(createKeyDiffGenerator(params.oldIndex.str(), params.newIndex.str(), params.patch.str(), (params.tlkInfo ? params.newTLK.str() : 0), params.overwrite, params.compress));
        if(params.progressFrequency)
            generator->setProgressCallback(new KeyDiffProgressCallback, params.progressFrequency);
        generator->run();
        if(params.stats)
            generator->logStats();
    }
    catch(IException * e)
    {
        EXCLOG(e);
        e->Release();
        releaseAtoms();
        return 1;
    }
    releaseAtoms();
    return 0;
}
Ejemplo n.º 18
0
int main(int argc, char* argv[])
{
    if(argc != 2)
    {
        printf("usage: addScopes daliconf.xml\n");
        printf("\n\tCreates all user-specific LDAP private file scopes 'hpccinternal::<user>'\n\tand grants users access to their scope. The configuration file\n\tdaliconf.xml is the dali configuration file, typically\n\tfound in /var/lib/HPCCSystems/mydali\n\n");
        return -1;
    }

    InitModuleObjects();

    try
    {
        Owned<IPropertyTree> cfg = createPTreeFromXMLFile(argv[1]);
        Owned<IPropertyTree> seccfg = cfg->getPropTree(".//ldapSecurity");
        if(seccfg == NULL)
        {
            printf("ldapSecurity not found\n");
            return -1;
        }
#ifdef _NO_LDAP
        printf("System was built with _NO_LDAP\n");
        return -1;
#else
        Owned<ISecManager> secmgr = newLdapSecManager("addScopes", *LINK(seccfg));
        if(secmgr == NULL)
        {
            printf("Security manager can't be created\n");
            return -1;
        }
        bool ok = secmgr->createUserScopes();
        printf(ok ? "User scopes added\n" : "Some scopes not added\n");
#endif
    }
    catch(IException* e)
    {
        StringBuffer errmsg;
        e->errorMessage(errmsg);
        printf("%s\n", errmsg.str());
    }
    catch(...)
    {
        printf("Unknown exception\n");
    }

    releaseAtoms();
    return 0;
}
Ejemplo n.º 19
0
void usage(bool isHelp)
{
    printf("usage:\n"
           "  keydiff [options] oldindex newindex patch\n"
           "options are:\n"
           "   -o --overwrite              overwrite patch file if it exists\n"
           "   -n --nooverwrite            abort if patch file exists (default)\n"
           "   -c --compress               use LZMA block compression\n"
           "   -z                          use LZW block compression (faster/larger)\n"
           "   -s --stats                  log statistics on diff\n"
           "   -t --tlk newtlk             include data on newtlk in header\n"
           "   -p --progress freq          log progress reading old index at intervals of freq bytes\n"
           "\n"
           "usage:\n"
           "  keydiff [-v | --version ]\n"
           "  keydiff [-h | -? | --help ]\n\n");
    releaseAtoms();
    exit(isHelp ? 0 : 2);
}
Ejemplo n.º 20
0
void usage(int exitval = 2)
{
    printf("Usage:\n"
           "scheduleadmin help\n"
           "scheduleadmin <DALI> add <WUID>\n"
           "scheduleadmin <DALI> remove <WUID>\n"
           "scheduleadmin <DALI> removeall\n"
           "scheduleadmin <DALI> servers\n"
           "scheduleadmin <DALI> list <eclserver> (<event name>)\n"
           "scheduleadmin <DALI> monitor <eclserver> (<event name>)\n"
           "scheduleadmin <DALI> cleanup\n"
           "scheduleadmin <DALI> push eventname eventtext (<wuid>)\n"
#if _DEBUG
           "scheduleadmin <DALI> testpull <eclserver queue>\n"
#endif
           );
    releaseAtoms();
    ExitModuleObjects();
    exit(exitval);
}
Ejemplo n.º 21
0
void usage()
{
    printf("USAGE: uttest [options] iprange\n");
    printf("Options are:\n");
    printf("--enableSocketMaxSetting\n"
        "--jumboFrames\n"
        "--udpLocalWriteSocketSize nn\n"
        "--udpRetryBusySenders nn\n"
        "--maxPacketsPerSender nn\n"
        "--udpSnifferEnabled 0|1\n"     
        "--udpTraceCategories nn\n"
        "--udpTraceLevel nn\n"
        "--dontSendToSelf\n"
        "--sendSize nnMB\n"
        "--rawSpeedTest\n"
        "--rawBufferSize nn\n"
        );
    ExitModuleObjects();
    releaseAtoms();
    exit(1);
}
Ejemplo n.º 22
0
int main(int argc, char* argv[])
{
    loadDlls();
    InitModuleObjects();
    queryStderrLogMsgHandler()->setMessageFields(MSGFIELD_time);
    CppUnit::TextUi::TestRunner runner;
    if (argc==1)
    {
        CppUnit::TestFactoryRegistry &registry = CppUnit::TestFactoryRegistry::getRegistry();
        runner.addTest( registry.makeTest() );
    }
    else 
    {
        for (int name = 1; name < argc; name++)
        {
            CppUnit::TestFactoryRegistry &registry = CppUnit::TestFactoryRegistry::getRegistry(argv[name]);
            runner.addTest( registry.makeTest() );
        }
    }
    bool wasSucessful = runner.run( "", false );
    ExitModuleObjects();
    releaseAtoms();
    return wasSucessful;
}
Ejemplo n.º 23
0
int main(int argc, char* argv[])
{
    InitModuleObjects();

    InstanceType itype = IT_UNKNOWN;

    int times = 1;
    int threads = 1;
    StringBuffer in_fname;
    StringBuffer out_fname;
    StringBuffer host;
    int port = 80;
    int localport = 80;
    bool use_ssl = false;
    bool add_soap_headers = false;
    StringBuffer scfname;
    StringBuffer url;

    const char* soapaction = NULL;

    int delay = 0;
    int recvDelay = 0, sendDelay = 0, blockDelay = 0;
    
    int i = 1;
    while(i<argc)
    {
        if (stricmp(argv[i], "-s")==0)
        {
            itype = HTTPSERVER;
            i++;
        }
        else if (stricmp(argv[i], "-c")==0)
        {
            itype = HTTPCLIENT;
            i++;
        }
        else if (stricmp(argv[i], "-x")==0)
        {
            itype = HTTPPROXY;
            i++;
        }
        else if (stricmp(argv[i],"-r")==0)
        {
            i++;
            times = atoi(argv[i++]);
        }
        else if (stricmp(argv[i],"-t")==0)
        {
            i++;
            threads = atoi(argv[i++]);
        }
        else if (stricmp(argv[i], "-h")==0)
        {
            i++;
            host.clear().append(argv[i++]);
        }
        else if (stricmp(argv[i], "-p")==0)
        {
            i++;
            port = atoi(argv[i++]);
        }
        else if (stricmp(argv[i], "-i") == 0)
        {
            i++;
            in_fname.clear().append(argv[i++]);
        }
        else if (stricmp(argv[i], "-o") == 0)
        {
            i++;
            out_fname.clear().append(argv[i++]);
        }
        else if (stricmp(argv[i], "-ssl") == 0)
        {
            use_ssl = true;
            i++;
        }
        else if (stricmp(argv[i], "-sc") == 0)
        {
            i++;
            scfname.clear().append(argv[i++]);
        }
        else if (stricmp(argv[i], "-lp") == 0)
        {
            i++;
            localport = atoi(argv[i++]);
        }
        else if (stricmp(argv[i], "-delay") == 0)
        {
            i++;
            delay = atoi(argv[i++]);
        }
        else if (stricmp(argv[i], "-dr") == 0)
        {
            i++;
            recvDelay = atoi(argv[i++]);
        }
        else if (stricmp(argv[i], "-ds") == 0)
        {
            i++;
            sendDelay = atoi(argv[i++]);
        }
        else if (stricmp(argv[i], "-dc") == 0)
        {
            i++;
            blockDelay = atoi(argv[i++]);
        }
        else if(stricmp(argv[i], "-url") == 0)
        {
            i++;
            url.append(argv[i++]);
        }
        else if (stricmp(argv[i], "-soap")==0)
        {
            add_soap_headers = true;
            i++;
        }
        else if (stricmp(argv[i], "-action")==0)
        {
            i++;
            soapaction = argv[i++];
        }
        else if (stricmp(argv[i], "-d")==0)
        {
            i++;
            httptest_tracelevel = atoi(argv[i++]);;
        }
        else
        {
            printf("Error: command format error\n");
            usage();
        }
    }

    try
    {
        Owned<IPropertyTree> sslconfig;
        if(scfname.length() > 0)
            sslconfig.setown(createPTreeFromXMLFile(scfname.str(), ipt_caseInsensitive));
        FILE* ofile = NULL;
        if(out_fname.length() != 0)
        {
            ofile = fopen(out_fname.str(), "a+");
            if(ofile == NULL)
            {
                printf("can't open file %s\n", out_fname.str());
                exit(-1);
            }
        }
        else
        {
            ofile = stdout;
        }

        if(itype == HTTPSERVER)
        {
            HttpServer server(port, in_fname.str(), ofile, use_ssl, sslconfig.get());
            server.setDelays(recvDelay, sendDelay, blockDelay);
            server.start();
        }
        else if(itype == HTTPPROXY)
        {
            HttpProxy proxy(localport, host.str(), port, ofile, use_ssl, sslconfig.get());
            proxy.start();
        }
        else
        {
            if(add_soap_headers && url.length() == 0)
            {
                printf("Error: when you use -soap option, you must provide the full url\ntype in \"%s -h\" for usage", argv[0]);
                return 0;
            }

            if(host.length() == 0 && url.length() == 0)
            {
                printf("Error: destination host or url required\n");
                usage();
            }


            if(add_soap_headers)
            {
                HttpClient client(threads, times, ofile);
                if(delay > 0)
                    client.setDelay(delay);
                client.sendSoapRequest(url.str(), soapaction, in_fname.str());
            }
            else if(url.length() == 0)
            {
                HttpClient client(threads, times, host.str(), port, ofile, use_ssl, sslconfig.get());
                if(delay > 0)
                    client.setDelay(delay);
                client.sendRequest(in_fname.str());         
            }
            else
            {
                HttpClient client(threads, times, ofile);
                if(delay > 0)
                    client.setDelay(delay);
                client.getUrl(url.str());
            }
        }
        fclose(ofile);
    }
    catch(IException *excpt)
    {
        StringBuffer errMsg;
        DBGLOG("Error - %d:%s", excpt->errorCode(), excpt->errorMessage(errMsg).str());
        return -1;
    }
    catch(...)
    {
        DBGLOG("Unknown exception");
        return -1;
    }

    releaseAtoms();
    return 0;
}
Ejemplo n.º 24
0
int main(int argc, const char *argv[])
{
    InitModuleObjects();
    EnableSEHtoExceptionMapping();

    NoQuickEditSection xxx;

    Owned<IFile> file = createIFile("dfuserver.xml");
    if (file->exists())
        globals.setown(createPTreeFromXMLFile("dfuserver.xml", ipt_caseInsensitive));
    else
        globals.setown(readOldIni());

    for (unsigned i=1;i<(unsigned)argc;i++) {
        const char *arg = argv[i];
        StringBuffer prop("@");
        StringBuffer val;
        while (*arg && *arg != '=')
            prop.append(*arg++);
        if (*arg) {
            arg++;
            while (isspace(*arg))
                arg++;
            val.append(arg);
            prop.clip();
            val.clip();
            if (prop.length()>1)
                globals->setProp(prop.str(), val.str());
        }
    }
    StringBuffer daliServer;
    StringBuffer queue;
    if (!globals->getProp("@DALISERVERS", daliServer)||!globals->getProp("@QUEUE", queue)) {
        usage();
        globals.clear();
        releaseAtoms();
        return 1;
    }
    Owned<IFile> sentinelFile;
    bool stop = globals->getPropInt("@STOP",0)!=0;
    if (!stop) {
        sentinelFile.setown(createSentinelTarget());
        removeSentinelFile(sentinelFile);

        StringBuffer logname;
        StringBuffer logdir;
        if (!getConfigurationDirectory(globals->queryPropTree("Directories"),"log","dfuserver",globals->queryProp("@name"),logdir))
            globals->getProp("@LOG_DIR", logdir);
        if (logdir.length() && recursiveCreateDirectory(logdir.str()))
            logname.append(logdir);
        else
            appendCurrentDirectory(logname, true);

        if (logname.length() && logname.charAt(logname.length()-1) != PATHSEPCHAR)
            logname.append(PATHSEPCHAR);
        logname.append("dfuserver");
        StringBuffer aliasLogName(logname);
        aliasLogName.append(".log");
        fileMsgHandler = getRollingFileLogMsgHandler(logname.str(), ".log", MSGFIELD_STANDARD, false, true, NULL, aliasLogName.str());
        queryLogMsgManager()->addMonitorOwn(fileMsgHandler, getCategoryLogMsgFilter(MSGAUD_all, MSGCLS_all, 1000));
    }
    StringBuffer ftslogdir;
    if (getConfigurationDirectory(globals->queryPropTree("Directories"),"log","ftslave",globals->queryProp("@name"),ftslogdir)) // NB instance deliberately dfuserver's
        setFtSlaveLogDir(ftslogdir.str());
    setRemoteSpawnSSH(
        globals->queryProp("SSH/@SSHidentityfile"),
        globals->queryProp("SSH/@SSHusername"),
        globals->queryProp("SSH/@SSHpassword"),
        globals->getPropInt("SSH/@SSHtimeout",0),
        globals->getPropInt("SSH/@SSHretries",3),
        "run_");
    bool enableSNMP = globals->getPropInt("@enableSNMP")!=0;
    CSDSServerStatus *serverstatus=NULL;
    Owned<IReplicateServer> replserver;
    try {
        Owned<IGroup> serverGroup = createIGroup(daliServer.str(),DALI_SERVER_PORT);
        initClientProcess(serverGroup, DCR_DfuServer, 0, NULL, NULL, stop?(1000*30):MP_WAIT_FOREVER);
        setPasswordsFromSDS();

        if(!stop)
        {
            if (globals->getPropBool("@enableSysLog",true))
                UseSysLogForOperatorMessages();

            serverstatus = new CSDSServerStatus("DFUserver");
            setDaliServixSocketCaching(true); // speeds up lixux operations

            startLogMsgParentReceiver();    // for auditing
            connectLogMsgManagerToDali();

            engine.setown(createDFUengine());
            addAbortHandler(exitDFUserver);
        }
        const char *q = queue.str();
        loop {
            StringBuffer subq;
            const char *comma = strchr(q,',');
            if (comma)
                subq.append(comma-q,q);
            else
                subq.append(q);
            if (stop) {
                stopDFUserver(subq.str());
            }
            else {
                StringBuffer mask;
                mask.appendf("Queue[@name=\"%s\"][1]",subq.str());
                IPropertyTree *t=serverstatus->queryProperties()->queryPropTree(mask.str());
                if (t)
                    t->setPropInt("@num",t->getPropInt("@num",0)+1);
                else {
                    t = createPTree();
                    t->setProp("@name",subq.str());
                    t->setPropInt("@num",1);
                    serverstatus->queryProperties()->addPropTree("Queue",t);
                }
                serverstatus->commitProperties();
                engine->setDefaultTransferBufferSize((size32_t)globals->getPropInt("@transferBufferSize"));
                engine->startListener(subq.str(),serverstatus);
            }
            if (!comma)
                break;
            q = comma+1;
            if (!*q)
                break;
        }
        q = globals->queryProp("@MONITORQUEUE");
        if (q&&*q) {
            if (stop) {
                stopDFUserver(q);
            }
            else {
                IPropertyTree *t=serverstatus->queryProperties()->addPropTree("MonitorQueue",createPTree());
                t->setProp("@name",q);
                engine->startMonitor(q,serverstatus,globals->getPropInt("@MONITORINTERVAL",60)*1000);
            }
        }
        q = globals->queryProp("@REPLICATEQUEUE");
        if (q&&*q) {
            if (stop) {
                // TBD?
            }
            else {
                replserver.setown(createReplicateServer(q));
                replserver->runServer();
            }
        }
        if (!stop) {
            serverstatus->commitProperties();

            writeSentinelFile(sentinelFile);

            engine->joinListeners();
            if (replserver.get())
                replserver->stopServer();
            LOG(MCprogress, unknownJob, "Exiting");
        }

    }
    catch(IException *e){
        EXCLOG(e, "DFU Server Exception: ");
        e->Release();
    }
    catch (const char *s) {
        WARNLOG("DFU: %s",s);
    }

    delete serverstatus;
    if (stop)
        Sleep(2000);    // give time to stop
    engine.clear();
    globals.clear();
    closeEnvironment();
    closedownClientProcess();
    UseSysLogForOperatorMessages(false);
    setDaliServixSocketCaching(false);
    releaseAtoms();
    return 0;
}
Ejemplo n.º 25
0
int main(int argc, char* argv[])
{
    InitModuleObjects();
    int exitCode = 1;
    try
    {
        if (argc<2)
        {
            printf("usage: dalistop <server_ip:port> [/nowait]\n");
            printf("eg:  dalistop .                          -- stop dali server running locally\n");
            printf("     dalistop eq0001016                  -- stop dali server running remotely\n");
        }
        else
        {
            SocketEndpoint ep;
            ep.set(argv[1],DALI_SERVER_PORT);
            bool nowait = false;
            if (argc>=3)
                nowait = stricmp(argv[2],"/nowait")==0;
            printf("Stopping Dali Server on %s\n",argv[1]);
            startMPServer(0);
            Owned<IGroup> group = createIGroup(1,&ep); 
            Owned<ICommunicator> comm = createCommunicator(group);
            CMessageBuffer mb;
            int fn=-1;
            mb.append(fn);
            if (comm->verifyConnection(0,2000))
            {
                comm->send(mb,0,MPTAG_DALI_COVEN_REQUEST,MP_ASYNC_SEND);
                if (nowait)
                {
                    Sleep(1000);
                    exitCode = 0;
                }
                else
                {
                    // verifyConnection() has a min conn timeout of 10s
                    // use recv() instead to check for socket closed ...
                    try
                    {
                        while (!comm->recv(mb,0,MPTAG_DALI_COVEN_REQUEST,nullptr,5000))
                        {
                            printf("Waiting for Dali Server to stop....\n");
                        }
                        exitCode = 0;
                    }
                    catch (IMP_Exception *e)
                    {
                        if (e->errorCode() == MPERR_link_closed)
                            exitCode = 0;
                        e->Release();
                    }
                }
            }
            else
                fprintf(stderr, "Dali not responding\n");
            stopMPServer();
        }
    }
    catch (IException *e)
    {
        pexception("Exception",e);
        stopMPServer();
    }
    releaseAtoms();
    return exitCode;
}
Ejemplo n.º 26
0
int main(int argc, const char* argv[])
{
    InitModuleObjects();

    if ((argc >= 2) && ((stricmp(argv[1], "/version") == 0) || (stricmp(argv[1], "-v") == 0)
        || (stricmp(argv[1], "--version") == 0)))
    {
        printVersion();
        return 0;
    }

    Owned<IFile> inifile = createIFile("dfuplus.ini");
    if(argc < 2 && !(inifile->exists() && inifile->size() > 0))
    {
        handleSyntax();
        return 0;
    }

    if ((argc >= 2) && ((argv[1][0]=='/' || argv[1][0]=='-') && (argv[1][1]=='?' || argv[1][1]=='h'))) 
    {
        handleSyntax();
        return 0;
    }

    //queryLogMsgManager()->changeMonitorFilterOwn(queryStderrLogMsgHandler(), getPassNoneLogMsgFilter());

    Owned<IProperties> globals = createProperties("dfuplus.ini", true);

    if(!build_globals(argc, argv, globals))
    {
        fprintf(stderr, "ERROR: Invalid command syntax.\n");
        releaseAtoms();
        return DFUERR_InvalidCommandSyntax;
    }



    
    const char* action = globals->queryProp("action");
    if(!action || !*action)
    {
        handleSyntax();
        fprintf(stderr, "\nERROR: please specify one action");
        releaseAtoms();
        return DFUERR_TooFewArguments;
    }

    const char* server = globals->queryProp("server");
    if (!server || !*server) {
        if (stricmp(action,"dafilesrv")==0)
            globals->setProp("server","127.0.0.1"); // dummy
        else { 
            fprintf(stderr, "ERROR: Esp server url not specified.\n");
            releaseAtoms();
            return DFUERR_TooFewArguments;
        }
    }

    try
    {
        Owned<CDfuPlusHelper> helper = new CDfuPlusHelper(LINK(globals.get()));
        helper->doit();
    }
    catch(IException* e)
    {
        StringBuffer errmsg;
        e->errorMessage(errmsg);
        fprintf(stderr, "%s\n", errmsg.str());
    }
    
    releaseAtoms();
    return 0;
}
Ejemplo n.º 27
0
int main( int argc, char *argv[]  )
{
#if defined(WIN32) && defined(_DEBUG)
    int tmpFlag = _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG );
    tmpFlag |= _CRTDBG_LEAK_CHECK_DF;
    _CrtSetDbgFlag( tmpFlag );
#endif

    InitModuleObjects();

    addAbortHandler(ControlHandler);
    EnableSEHtoExceptionMapping();

    dummyProc();
#ifndef __64BIT__
    Thread::setDefaultStackSize(0x10000);   // NB under windows requires linker setting (/stack:)
#endif

#ifdef _WIN32
    Owned<CReleaseMutex> globalNamedMutex;
#endif 

    if (globals)
        globals->Release();

    {
        Owned<IFile> iFile = createIFile("thor.xml");
        globals = iFile->exists() ? createPTree(*iFile, ipt_caseInsensitive) : createPTree("Thor", ipt_caseInsensitive);
    }
    unsigned multiThorMemoryThreshold = 0;
    try {
        if (argc==1)
        {
            usage();
            return 1;
        }
        cmdArgs = argv+1;
        mergeCmdParams(globals);
        cmdArgs = argv+1;

        const char *master = globals->queryProp("@MASTER");
        if (!master)
            usage();

        const char *slave = globals->queryProp("@SLAVE");
        if (slave)
        {
            slfEp.set(slave);
            localHostToNIC(slfEp);
        }
        else 
            slfEp.setLocalHost(0);

        if (globals->hasProp("@SLAVENUM"))
            mySlaveNum = atoi(globals->queryProp("@SLAVENUM"));
        else
            mySlaveNum = slfEp.port; // shouldn't happen, provided by script

        setMachinePortBase(slfEp.port);
        slfEp.port = getMachinePortBase();
        startSlaveLog();

        startMPServer(getFixedPort(TPORT_mp));
#ifdef USE_MP_LOG
        startLogMsgParentReceiver();
        LOG(MCdebugProgress, thorJob, "MPServer started on port %d", getFixedPort(TPORT_mp));
#endif

        SocketEndpoint masterEp(master);
        localHostToNIC(masterEp);
        setMasterPortBase(masterEp.port);
        markNodeCentral(masterEp);
        if (RegisterSelf(masterEp))
        {
#define ISDALICLIENT // JCSMORE plugins *can* access dali - though I think we should probably prohibit somehow.
#ifdef ISDALICLIENT
            const char *daliServers = globals->queryProp("@DALISERVERS");
            if (!daliServers)
            {
                LOG(MCerror, thorJob, "No Dali server list specified\n");
                return 1;
            }
            Owned<IGroup> serverGroup = createIGroup(daliServers, DALI_SERVER_PORT);
            unsigned retry = 0;
            loop {
                try {
                    LOG(MCdebugProgress, thorJob, "calling initClientProcess");
                    initClientProcess(serverGroup,DCR_ThorSlave, getFixedPort(TPORT_mp));
                    break;
                }
                catch (IJSOCK_Exception *e) {
                    if ((e->errorCode()!=JSOCKERR_port_in_use))
                        throw;
                    FLLOG(MCexception(e), thorJob, e,"InitClientProcess");
                    if (retry++>10)
                        throw;
                    e->Release();
                    LOG(MCdebugProgress, thorJob, "Retrying");
                    Sleep(retry*2000);
                }
            }
            setPasswordsFromSDS();
#endif
            IDaFileSrvHook *daFileSrvHook = queryDaFileSrvHook();
            if (daFileSrvHook) // probably always installed
                daFileSrvHook->addSubnetFilters(globals->queryPropTree("NAS"), NULL);

            StringBuffer thorPath;
            globals->getProp("@thorPath", thorPath);
            recursiveCreateDirectory(thorPath.str());
            int err = _chdir(thorPath.str());
            if (err)
            {
                IException *e = MakeErrnoException(-1, "Failed to change dir to '%s'",thorPath.str());
                FLLOG(MCexception(e), thorJob, e);
                throw e;
            }

// Initialization from globals
            setIORetryCount(globals->getPropInt("Debug/@ioRetries")); // default == 0 == off

            StringBuffer str;
            if (globals->getProp("@externalProgDir", str.clear()))
                _mkdir(str.str());
            else
                globals->setProp("@externalProgDir", thorPath);

            const char * overrideBaseDirectory = globals->queryProp("@thorDataDirectory");
            const char * overrideReplicateDirectory = globals->queryProp("@thorReplicateDirectory");
            StringBuffer datadir;
            StringBuffer repdir;
            if (getConfigurationDirectory(globals->queryPropTree("Directories"),"data","thor",globals->queryProp("@name"),datadir))
                overrideBaseDirectory = datadir.str();
            if (getConfigurationDirectory(globals->queryPropTree("Directories"),"mirror","thor",globals->queryProp("@name"),repdir))
                overrideReplicateDirectory = repdir.str();
            if (overrideBaseDirectory&&*overrideBaseDirectory)
                setBaseDirectory(overrideBaseDirectory, false);
            if (overrideReplicateDirectory&&*overrideBaseDirectory)
                setBaseDirectory(overrideReplicateDirectory, true);
            StringBuffer tempdirstr;
            const char *tempdir = globals->queryProp("@thorTempDirectory");
            if (getConfigurationDirectory(globals->queryPropTree("Directories"),"temp","thor",globals->queryProp("@name"),tempdirstr))
                tempdir = tempdirstr.str();
            SetTempDir(tempdir,true);

            useMemoryMappedRead(globals->getPropBool("@useMemoryMappedRead"));

            LOG(MCdebugProgress, thorJob, "ThorSlave Version LCR - %d.%d started",THOR_VERSION_MAJOR,THOR_VERSION_MINOR);
            StringBuffer url;
            LOG(MCdebugProgress, thorJob, "Slave %s - temporary dir set to : %s", slfEp.getUrlStr(url).toCharArray(), queryTempDir());
#ifdef _WIN32
            ULARGE_INTEGER userfree;
            ULARGE_INTEGER total;
            ULARGE_INTEGER free;
            if (GetDiskFreeSpaceEx("c:\\",&userfree,&total,&free)&&total.QuadPart) {
                unsigned pc = (unsigned)(free.QuadPart*100/total.QuadPart);
                LOG(MCdebugProgress, thorJob, "Total disk space = %"I64F"d k", total.QuadPart/1000);
                LOG(MCdebugProgress, thorJob, "Free  disk space = %"I64F"d k", free.QuadPart/1000);
                LOG(MCdebugProgress, thorJob, "%d%% disk free\n",pc);
            }
#endif
            if (getConfigurationDirectory(globals->queryPropTree("Directories"),"query","thor",globals->queryProp("@name"),str.clear()))
                globals->setProp("@query_so_dir", str.str());
            else
                globals->getProp("@query_so_dir", str.clear());
            if (str.length())
            {
                if (globals->getPropBool("Debug/@dllsToSlaves", true))
                {
                    StringBuffer uniqSoPath;
                    if (PATHSEPCHAR == str.charAt(str.length()-1))
                        uniqSoPath.append(str.length()-1, str.str());
                    else
                        uniqSoPath.append(str);
                    uniqSoPath.append("_").append(getMachinePortBase());
                    str.swapWith(uniqSoPath);
                    globals->setProp("@query_so_dir", str.str());
                }
                PROGLOG("Using querySo directory: %s", str.str());
                recursiveCreateDirectory(str.str());
            }
     
            multiThorMemoryThreshold = globals->getPropInt("@multiThorMemoryThreshold")*0x100000;
            if (multiThorMemoryThreshold) {
                StringBuffer lgname;
                if (!globals->getProp("@multiThorResourceGroup",lgname))
                    globals->getProp("@nodeGroup",lgname);
                if (lgname.length()) {
                    Owned<ILargeMemLimitNotify> notify = createMultiThorResourceMutex(lgname.str());
                    setMultiThorMemoryNotify(multiThorMemoryThreshold,notify);
                    PROGLOG("Multi-Thor resource limit for %s set to %"I64F"d",lgname.str(),(__int64)multiThorMemoryThreshold);
                }   
                else
                    multiThorMemoryThreshold = 0;
            }
            slaveMain();
        }

        LOG(MCdebugProgress, thorJob, "ThorSlave terminated OK");
    }
    catch (IException *e) 
    {
        FLLOG(MCexception(e), thorJob, e,"ThorSlave");
        e->Release();
    }
    catch (CATCHALL)
    {
        FLLOG(MCerror, thorJob, "ThorSlave exiting because of uncaught exception");
    }
    ClearTempDirs();

    if (multiThorMemoryThreshold)
        setMultiThorMemoryNotify(0,NULL);
    roxiemem::releaseRoxieHeap();

#ifdef ISDALICLIENT
    closeEnvironment();
    closedownClientProcess();   // dali client closedown
#endif

#ifdef USE_MP_LOG
    stopLogMsgReceivers();
#endif
    stopMPServer();
    ::Release(globals);
    releaseAtoms(); // don't know why we can't use a module_exit to destruct these...

    return 0;
}
Ejemplo n.º 28
0
int main( int argc, char *argv[]  )
{
#if defined(WIN32) && defined(_DEBUG)
    int tmpFlag = _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG );
    tmpFlag |= _CRTDBG_LEAK_CHECK_DF;
    _CrtSetDbgFlag( tmpFlag );
#endif

    InitModuleObjects();

    addAbortHandler(ControlHandler);
    EnableSEHtoExceptionMapping();

    dummyProc();
#ifndef __64BIT__
    // Restrict stack sizes on 32-bit systems
    Thread::setDefaultStackSize(0x10000);   // NB under windows requires linker setting (/stack:)
#endif

#ifdef _WIN32
    Owned<CReleaseMutex> globalNamedMutex;
#endif 

    if (globals)
        globals->Release();

    {
        Owned<IFile> iFile = createIFile("thor.xml");
        globals = iFile->exists() ? createPTree(*iFile, ipt_caseInsensitive) : createPTree("Thor", ipt_caseInsensitive);
    }
    unsigned multiThorMemoryThreshold = 0;

    Owned<IException> unregisterException;
    try
    {
        if (argc==1)
        {
            usage();
            return 1;
        }
        cmdArgs = argv+1;
        mergeCmdParams(globals);
        cmdArgs = argv+1;

        const char *master = globals->queryProp("@MASTER");
        if (!master)
            usage();

        const char *slave = globals->queryProp("@SLAVE");
        if (slave)
        {
            slfEp.set(slave);
            localHostToNIC(slfEp);
        }
        else 
            slfEp.setLocalHost(0);

        mySlaveNum = globals->getPropInt("@SLAVENUM");

        setMachinePortBase(slfEp.port);
        slfEp.port = getMachinePortBase();
        startSlaveLog();

        setSlaveAffinity(globals->getPropInt("@SLAVEPROCESSNUM"));

        startMPServer(getFixedPort(TPORT_mp));
#ifdef USE_MP_LOG
        startLogMsgParentReceiver();
        LOG(MCdebugProgress, thorJob, "MPServer started on port %d", getFixedPort(TPORT_mp));
#endif

        SocketEndpoint masterEp(master);
        localHostToNIC(masterEp);
        setMasterPortBase(masterEp.port);
        markNodeCentral(masterEp);
        if (RegisterSelf(masterEp))
        {
            if (globals->getPropBool("Debug/@slaveDaliClient"))
                enableThorSlaveAsDaliClient();

            IDaFileSrvHook *daFileSrvHook = queryDaFileSrvHook();
            if (daFileSrvHook) // probably always installed
                daFileSrvHook->addFilters(globals->queryPropTree("NAS"), &slfEp);

            StringBuffer thorPath;
            globals->getProp("@thorPath", thorPath);
            recursiveCreateDirectory(thorPath.str());
            int err = _chdir(thorPath.str());
            if (err)
            {
                IException *e = makeErrnoExceptionV(-1, "Failed to change dir to '%s'", thorPath.str());
                FLLOG(MCexception(e), thorJob, e);
                throw e;
            }

// Initialization from globals
            setIORetryCount(globals->getPropInt("Debug/@ioRetries")); // default == 0 == off

            StringBuffer str;
            if (globals->getProp("@externalProgDir", str.clear()))
                _mkdir(str.str());
            else
                globals->setProp("@externalProgDir", thorPath);

            const char * overrideBaseDirectory = globals->queryProp("@thorDataDirectory");
            const char * overrideReplicateDirectory = globals->queryProp("@thorReplicateDirectory");
            StringBuffer datadir;
            StringBuffer repdir;
            if (getConfigurationDirectory(globals->queryPropTree("Directories"),"data","thor",globals->queryProp("@name"),datadir))
                overrideBaseDirectory = datadir.str();
            if (getConfigurationDirectory(globals->queryPropTree("Directories"),"mirror","thor",globals->queryProp("@name"),repdir))
                overrideReplicateDirectory = repdir.str();
            if (overrideBaseDirectory&&*overrideBaseDirectory)
                setBaseDirectory(overrideBaseDirectory, false);
            if (overrideReplicateDirectory&&*overrideBaseDirectory)
                setBaseDirectory(overrideReplicateDirectory, true);
            StringBuffer tempDirStr;
            if (getConfigurationDirectory(globals->queryPropTree("Directories"),"temp","thor",globals->queryProp("@name"), tempDirStr))
                globals->setProp("@thorTempDirectory", tempDirStr.str());
            else
                tempDirStr.append(globals->queryProp("@thorTempDirectory"));
            addPathSepChar(tempDirStr).append(getMachinePortBase());

            logDiskSpace(); // Log before temp space is cleared
            SetTempDir(tempDirStr.str(), "thtmp", true);

            useMemoryMappedRead(globals->getPropBool("@useMemoryMappedRead"));

            LOG(MCdebugProgress, thorJob, "ThorSlave Version LCR - %d.%d started",THOR_VERSION_MAJOR,THOR_VERSION_MINOR);
            StringBuffer url;
            LOG(MCdebugProgress, thorJob, "Slave %s - temporary dir set to : %s", slfEp.getUrlStr(url).str(), queryTempDir());
#ifdef _WIN32
            ULARGE_INTEGER userfree;
            ULARGE_INTEGER total;
            ULARGE_INTEGER free;
            if (GetDiskFreeSpaceEx("c:\\",&userfree,&total,&free)&&total.QuadPart) {
                unsigned pc = (unsigned)(free.QuadPart*100/total.QuadPart);
                LOG(MCdebugProgress, thorJob, "Total disk space = %" I64F "d k", total.QuadPart/1000);
                LOG(MCdebugProgress, thorJob, "Free  disk space = %" I64F "d k", free.QuadPart/1000);
                LOG(MCdebugProgress, thorJob, "%d%% disk free\n",pc);
            }
#endif
            if (getConfigurationDirectory(globals->queryPropTree("Directories"),"query","thor",globals->queryProp("@name"),str.clear()))
                globals->setProp("@query_so_dir", str.str());
            else
                globals->getProp("@query_so_dir", str.clear());
            if (str.length())
            {
                if (globals->getPropBool("Debug/@dllsToSlaves", true))
                {
                    StringBuffer uniqSoPath;
                    if (PATHSEPCHAR == str.charAt(str.length()-1))
                        uniqSoPath.append(str.length()-1, str.str());
                    else
                        uniqSoPath.append(str);
                    uniqSoPath.append("_").append(getMachinePortBase());
                    str.swapWith(uniqSoPath);
                    globals->setProp("@query_so_dir", str.str());
                }
                PROGLOG("Using querySo directory: %s", str.str());
                recursiveCreateDirectory(str.str());
            }
     
            multiThorMemoryThreshold = globals->getPropInt("@multiThorMemoryThreshold")*0x100000;
            if (multiThorMemoryThreshold) {
                StringBuffer lgname;
                if (!globals->getProp("@multiThorResourceGroup",lgname))
                    globals->getProp("@nodeGroup",lgname);
                if (lgname.length()) {
                    Owned<ILargeMemLimitNotify> notify = createMultiThorResourceMutex(lgname.str());
                    setMultiThorMemoryNotify(multiThorMemoryThreshold,notify);
                    PROGLOG("Multi-Thor resource limit for %s set to %" I64F "d",lgname.str(),(__int64)multiThorMemoryThreshold);
                }   
                else
                    multiThorMemoryThreshold = 0;
            }
            slaveMain(jobListenerStopped);
        }

        LOG(MCdebugProgress, thorJob, "ThorSlave terminated OK");
    }
    catch (IException *e) 
    {
        if (!jobListenerStopped)
            FLLOG(MCexception(e), thorJob, e,"ThorSlave");
        unregisterException.setown(e);
    }
    ClearTempDirs();

    if (multiThorMemoryThreshold)
        setMultiThorMemoryNotify(0,NULL);
    roxiemem::releaseRoxieHeap();

    if (unregisterException.get())
        UnregisterSelf(unregisterException);

    if (globals->getPropBool("Debug/@slaveDaliClient"))
        disableThorSlaveAsDaliClient();

#ifdef USE_MP_LOG
    stopLogMsgReceivers();
#endif
    stopMPServer();
    ::Release(globals);
    releaseAtoms(); // don't know why we can't use a module_exit to destruct these...

    ExitModuleObjects(); // not necessary, atexit will call, but good for leak checking
    return 0;
}
Ejemplo n.º 29
0
int main(int argc, char** argv)
{
  InitModuleObjects();

  const char* out_envname = NULL;
  const char* in_ipfilename;
  StringBuffer ipAddrs;
  int roxieNodes=0, thorNodes=0, slavesPerNode=1;
  MapStringTo<StringBuffer> dirMap;

  int i = 1;
  bool writeToFiles = false;
  int port = 80;

  while(i<argc)
  {
    if(stricmp(argv[i], "-help") == 0 || stricmp(argv[i], "-?") == 0)
    {
      usage();
      releaseAtoms();
      return 0;
    }
    else if (stricmp(argv[i], "-env") == 0)
    {
      i++;
      out_envname = argv[i++];
    }
    else if (stricmp(argv[i], "-roxienodes") == 0)
    {
      i++;
      roxieNodes = atoi(argv[i++]);
    }
    else if (stricmp(argv[i], "-thornodes") == 0)
    {
      i++;
      thorNodes = atoi(argv[i++]);
    }
    else if (stricmp(argv[i], "-slavespernode") == 0)
    {
      i++;
      slavesPerNode = atoi(argv[i++]);
    }
    else if (stricmp(argv[i], "-ip") == 0)
    {
      i++;
      ipAddrs.append(argv[i++]);
    }
    else if(stricmp(argv[i], "-ipfile") == 0)
    {
      i++;
      in_ipfilename = argv[i++];
      ipAddrs.loadFile(in_ipfilename);
    }
    else if(stricmp(argv[i], "-o") == 0)
    {
      i++;
      StringArray sbarr;
      DelimToStringArray(argv[i++], sbarr, "=");
      if (sbarr.length() != 2)
       continue;

      if (strstr(sbarr.item(1), "[NAME]") && (strstr(sbarr.item(1), "[INST]") || strstr(sbarr.item(1), "[COMPONENT]")))
        dirMap.setValue(sbarr.item(0), sbarr.item(1));
      else
      {
        fprintf(stderr, "Error: Directory Override must contain [NAME] and either [INST] or [COMPONENT]\n");
        releaseAtoms();
        return 1;
      }
    }
    else
    {
      fprintf(stderr, "Error: unknown command line parameter: %s\n", argv[i]);
      usage();
      releaseAtoms();
      return 1;
    }
  }

  if (!out_envname)
  {
    fprintf(stderr, "Error: Output environment xml file is required. Please specify.\n");
    usage();
    releaseAtoms();
    return 1;
  }

  if (ipAddrs.length() == 0)
  {
    fprintf(stderr, "Error: Ip addresses are required. Please specify.\n");
    usage();
    releaseAtoms();
    return 1;
  }

  try
  {
    validateIPS(ipAddrs.str());
    StringBuffer optionsXml, envXml;
    const char* pServiceName = "WsDeploy_wsdeploy_esp";
    Owned<IPropertyTree> pCfg = createPTreeFromXMLFile(ENVGEN_PATH_TO_ESP_CONFIG);

    optionsXml.appendf("<XmlArgs roxieNodes=\"%d\" thorNodes=\"%d\" slavesPerNode=\"%d\" ipList=\"%s\"/>", roxieNodes,
                      thorNodes, slavesPerNode, ipAddrs.str());

    buildEnvFromWizard(optionsXml, pServiceName, pCfg, envXml, &dirMap);
    if(envXml.length())
    {
      StringBuffer env;
      StringBuffer thisip;
      queryHostIP().getIpText(thisip);
      env.appendf("<"XML_HEADER">\n<!-- Generated with envgen on ip %s -->\n", thisip.str());
      env.append(envXml);
      
      Owned<IEnvironmentFactory> factory = getEnvironmentFactory();
      Owned<IConstEnvironment>  constEnv = factory->loadLocalEnvironment(env);
      validateEnv(constEnv);

      Owned<IFile> pFile;
      pFile.setown(createIFile(out_envname));
      
      Owned<IFileIO> pFileIO;
      pFileIO.setown(pFile->open(IFOcreaterw));
      pFileIO->write(0, env.length(), env.str());
    }
  }
  catch(IException *excpt)
  {
    StringBuffer errMsg;
    fprintf(stderr, "Exception: %d:\n%s\n", excpt->errorCode(), excpt->errorMessage(errMsg).str());
    releaseAtoms();
    excpt->Release();
    return 1;
  }
  catch(...)
  {
    fprintf(stderr, "Unknown exception\n");
    releaseAtoms();
    return 1;
  }

  releaseAtoms();

  return 0;
}
Ejemplo n.º 30
0
//-----------------------------------------------------
//
//-----------------------------------------------------
int main(int argc, char* argv[])
{
#ifdef _NO_LDAP
    fprintf(stderr, "System was built with _NO_LDAP\n");
    return -1;
#endif

    for (int x = 1; x < argc; x++)
    {
        if (0==strncmp("-h", argv[x], 2))
        {
            usage();
            exit(0);
        }
        else
        {
            fprintf(stderr, "\nERROR: Unrecognized parameter : '%s', enter 'initldap -h' for help\n", argv[x]);
            exit(1);
        }
    }

    InitModuleObjects();

    //execute configgen to query the LDAP Server configuration(s)
    StringBuffer cmd;
    cmd.appendf("%s%cconfiggen -env %s%c%s -listldapservers", ADMIN_DIR,PATHSEPCHAR,CONFIG_DIR, PATHSEPCHAR, ENV_XML_FILE);

    char * configBuffer = NULL;

    //acquire LDAP configuration by executing configgen and capturing output
    {
        StringBuffer configBuff;
        Owned<IPipeProcess> pipe = createPipeProcess();
        if (pipe->run("configgen", cmd.str(), ".", false, true, true, 0))
        {
            Owned<ISimpleReadStream> pipeReader = pipe->getOutputStream();
            const size32_t chunkSize = 8192;
            for (;;)
            {
                size32_t sizeRead = pipeReader->read(chunkSize, configBuff.reserve(chunkSize));
                if (sizeRead < chunkSize)
                {
                    configBuff.setLength(configBuff.length() - (chunkSize - sizeRead));
                    break;
                }
            }
            pipe->closeOutput();
        }
        int retcode = pipe->wait();
        if (retcode)
        {
            fprintf(stderr, "\nERROR %d: unable to execute %s", retcode, cmd.str());
            exit(1);
        }
        configBuffer = strdup(configBuff.str());
    }

    //Using the LDAP Server parms queried from configgen, build an
    //LDAPSecurity property tree for each LDAP Server and call the LDAP
    //Security Manager to create the needed entries
    Owned<IPropertyTree> ldapProps;
    char *saveptr;
    char * pLine = strtok_r(configBuffer, "\n", &saveptr);
    while (pLine)
    {
        if (pLine && 0==strcmp(pLine, "LDAPServerProcess"))
        {
            if (ldapProps)
                initLDAP(ldapProps);
            ldapProps.clear();
            ldapProps.setown(createPTree("ldapSecurity"));
        }
        else
        {
            char * sep = strchr(pLine, ',');
            if (sep)
            {
                *sep = (char)NULL;
                ldapProps->addProp(pLine, sep+1);
            }
        }
        pLine = strtok_r(NULL, "\n", &saveptr);
    }
    if (ldapProps)
        initLDAP(ldapProps);
    if (configBuffer)
        free(configBuffer);
    ldapProps.clear();

    releaseAtoms();
    return 0;
}