Example #1
0
int generate_static(void)
{
	getenv_default("XYMONLOGSTATUS", "STATIC", NULL);
	return (strcmp(xgetenv("XYMONLOGSTATUS"), "STATIC") == 0);
}
Example #2
0
int env_flags_validate(const ENTRY *item, const char *newval, enum env_op op,
	int flag)
{
	const char *name;
	const char *oldval = NULL;

	if (op != env_op_create)
		oldval = item->data;

	name = item->key;

	/* Default value for NULL to protect string-manipulating functions */
	newval = newval ? : "";

	/* validate the value to match the variable type */
	if (op != env_op_delete) {
		enum env_flags_vartype type = (enum env_flags_vartype)
			(ENV_FLAGS_VARTYPE_BIN_MASK & item->flags);

		if (_env_flags_validate_type(newval, type) < 0) {
			printf("## Error: flags type check failure for "
				"\"%s\" <= \"%s\" (type: %c)\n",
				name, newval, env_flags_vartype_rep[type]);
			return -1;
		}
	}

	/* check for access permission */
	if (flag & H_FORCE)
		return 0;

	switch (op) {
	case env_op_delete:
		if (item->flags & ENV_FLAGS_VARACCESS_PREVENT_DELETE) {
			printf("## Error: Can't delete \"%s\"\n", name);
			return 1;
		}
		break;
	case env_op_overwrite:
		if (item->flags & ENV_FLAGS_VARACCESS_PREVENT_OVERWR) {
			printf("## Error: Can't overwrite \"%s\"\n", name);
			return 1;
		} else if (item->flags &
		    ENV_FLAGS_VARACCESS_PREVENT_NONDEF_OVERWR) {
			const char *defval = getenv_default(name);

			if (defval == NULL)
				defval = "";
			printf("oldval: %s  defval: %s\n", oldval, defval);
			if (strcmp(oldval, defval) != 0) {
				printf("## Error: Can't overwrite \"%s\"\n",
					name);
				return 1;
			}
		}
		break;
	case env_op_create:
		if (item->flags & ENV_FLAGS_VARACCESS_PREVENT_CREATE) {
			printf("## Error: Can't create \"%s\"\n", name);
			return 1;
		}
		break;
	}

	return 0;
}
Example #3
0
File: dll.c Project: icharge/cncnet
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
    if (fdwReason == DLL_PROCESS_ATTACH)
    {
        const char *cfg_p2p;
        const char *cfg_host;
        int s, cfg_port = 9001;

        #ifdef _DEBUG
        freopen("stdout.txt", "w", stdout);
        setvbuf(stdout, NULL, _IONBF, 0); 
        #endif

        printf("CnCNet git~%s\n", CNCNET_REV);

        s = net_init();
        net_opt_reuse();

        if (getenv("CNCNET_HOST"))
        {
            printf("Going into online mode...\n");

            /* allow CnCNet's wolapi.dll to inject itself */
            if (GetFileAttributes("wolapi.dll") != INVALID_FILE_ATTRIBUTES)
            {
                printf("Loading wolapi.dll for WOL mode\n");
                wolapi_dll = LoadLibrary("wolapi.dll");
            }

            cfg_host = getenv_default("CNCNET_HOST", "server.cncnet.org");
            cfg_port = atoi(getenv_default("CNCNET_PORT", "9001"));
            cfg_p2p = getenv_default("CNCNET_P2P", "false");

            if (STR_TRUE(cfg_p2p))
            {
                printf("Peer-to-peer is enabled\n");
                my_p2p = 1;
            }

            if (cfg_port < 1024 || cfg_port > 65534)
            {
                cfg_port = 9001;
            }

            printf("Broadcasting to %s:%d\n", cfg_host, cfg_port);

            dedicated = 1;
            net_address(&server, cfg_host, cfg_port);

            if (my_p2p)
            {
                net_bind("0.0.0.0", 8054);
            }
        }
        else
        {
            printf("CnCNet: Going into LAN mode...\n");
            net_address(&server, "255.255.255.255", 5000);
            net_opt_broadcast(s);
            net_bind("0.0.0.0", 5000);
        }
    }

    if (fdwReason == DLL_PROCESS_DETACH)
    {
        net_free();

        if (wolapi_dll)
            FreeLibrary(wolapi_dll);
    }

    return TRUE;
}
Example #4
0
int get_fqdn(void)
{
	/* Get FQDN setting */
	getenv_default("FQDN", "TRUE", NULL);
	return (strcmp(xgetenv("FQDN"), "TRUE") == 0);
}
Example #5
0
bool
get_package_file(const char *name, char **outname)
{
    *outname = xasprintf("%s/.%s/%s", getenv_default("HOME", ""), PACKAGE, name);
    return true;
}
Example #6
0
Log::GlobalState::GlobalState()
    : log_filename(getenv_default("POMAGMA_LOG_FILE", DEFAULT_LOG_FILE)),
      log_stream(log_filename, std::ios_base::app),
      log_level(getenv_default("POMAGMA_LOG_LEVEL", DEFAULT_LOG_LEVEL)) {
    Log::init();
}
Example #7
0
namespace pomagma
{

//----------------------------------------------------------------------------
// signature

Structure structure;
Signature & signature = structure.signature();
Sampler sampler(signature);

void load_structure (const std::string & filename) { structure.load(filename); }
void dump_structure (const std::string & filename) { structure.dump(filename); }
void load_language (const std::string & filename) { sampler.load(filename); }

void schedule_merge (Ob dep) { schedule(MergeTask(dep)); }
void schedule_exists (Ob ob) { schedule(ExistsTask(ob)); }
void schedule_less (Ob lhs, Ob rhs) { schedule(PositiveOrderTask(lhs, rhs)); }
void schedule_nless (Ob lhs, Ob rhs) { schedule(NegativeOrderTask(lhs, rhs)); }
void schedule_nullary_function (const NullaryFunction * fun)
{
    schedule(NullaryFunctionTask(*fun));
}
void schedule_injective_function (const InjectiveFunction * fun, Ob arg)
{
    schedule(InjectiveFunctionTask(*fun, arg));
}
void schedule_binary_function (const BinaryFunction * fun, Ob lhs, Ob rhs)
{
    schedule(BinaryFunctionTask(*fun, lhs, rhs));
}
void schedule_symmetric_function (const SymmetricFunction * fun, Ob lhs, Ob rhs)
{
    schedule(SymmetricFunctionTask(*fun, lhs, rhs));
}

Carrier carrier(
    getenv_default("POMAGMA_SIZE", DEFAULT_ITEM_DIM),
    schedule_exists,
    schedule_merge);

BinaryRelation LESS(carrier, schedule_less);
BinaryRelation NLESS(carrier, schedule_nless);

//----------------------------------------------------------------------------
// validation

void validate_consistent ()
{
    structure.validate_consistent();
}

void validate_all ()
{
    structure.validate();
    sampler.validate();
}

//----------------------------------------------------------------------------
// logging

void log_stats ()
{
    structure.log_stats();
    sampler.log_stats();
}

//----------------------------------------------------------------------------
// basic ensurers

inline void ensure_equal (Ob lhs, Ob rhs)
{
    carrier.ensure_equal(lhs, rhs);
}

inline void ensure_less (Ob lhs, Ob rhs)
{
    LESS.insert(lhs, rhs);
}

inline void ensure_nless (Ob lhs, Ob rhs)
{
    NLESS.insert(lhs, rhs);
}

//----------------------------------------------------------------------------
// expression parsing

void assume_core_facts (const char * theory_file)
{
    std::ifstream file(theory_file);
    POMAGMA_ASSERT(file, "failed to open " << theory_file);

    std::string expression;
    while (getline(file, expression)) {
        if (not expression.empty() and expression[0] != '#') {
            schedule(AssumeTask(expression));
        }
    }
}

void execute (const AssumeTask & task)
{
    POMAGMA_DEBUG("assume " << task.expression);

    InsertParser parser(signature);
    parser.begin(task.expression);
    std::string type = parser.parse_token();
    Ob lhs = parser.parse_term();
    Ob rhs = parser.parse_term();
    parser.end();

    if (type == "EQUAL") {
        ensure_equal(lhs, rhs);
	} else if (type == "LESS") {
        ensure_less(lhs, rhs);
	} else if (type == "NLESS") {
        ensure_nless(lhs, rhs);
	} else {
        POMAGMA_ERROR("bad relation type: " << type);
	}
}

//----------------------------------------------------------------------------
// sample tasks

void insert_nullary_functions ()
{
    const auto & functions = signature.nullary_functions();
    POMAGMA_INFO("Inserting " << functions.size() << " nullary functions");

    for (auto pair : functions) {
        NullaryFunction * fun = pair.second;
        if (not fun->find()) {
            Ob val = carrier.try_insert();
            POMAGMA_ASSERT(val, "no space to insert nullary functions");
            fun->insert(val);
        }
    }
}

bool sample_tasks_try_pop (SampleTask &)
{
    return carrier.item_count() < carrier.item_dim();
}

void execute (const SampleTask &, rng_t & rng)
{
    Sampler::Policy policy(carrier);
    sampler.try_insert_random(rng, policy);
}

//----------------------------------------------------------------------------
// task profiling

class CleanupProfiler
{
    static std::vector<atomic_default<unsigned long>> s_counts;
    static std::vector<atomic_default<unsigned long>> s_elapsed;

public:

    class Block
    {
        const unsigned long m_type;
        Timer m_timer;
    public:
        Block (unsigned long type) : m_type(type) {}
        ~Block ()
        {
            s_elapsed[m_type].fetch_add(
                m_timer.elapsed_us(),
                std::memory_order_acq_rel);
            s_counts[m_type].fetch_add(1, std::memory_order_acq_rel);
        }
    };

    CleanupProfiler (unsigned long task_count)
    {
        s_counts.resize(task_count);
        s_elapsed.resize(task_count);
    }

    // FIXME HACK this depends on link order, dying if log has been destroyed
    ~CleanupProfiler ()
    {
        unsigned long task_count = s_counts.size();
        POMAGMA_INFO("Task Id\tCount\tElapsed sec");
        for (unsigned long i = 0; i < task_count; ++i) {
            POMAGMA_INFO(
                std::setw(4) << i <<
                std::setw(8) << s_counts[i].load() <<
                std::setw(16) << (s_elapsed[i].load() * 1e-6));
        }
    }
};

std::vector<atomic_default<unsigned long>> CleanupProfiler::s_counts;
std::vector<atomic_default<unsigned long>> CleanupProfiler::s_elapsed;

} // namespace pomagma
Example #8
0
 virtual const char* get_dem_file_name() const
 {
     return getenv_default("FILE_DEM_GAT", "../../PP+BLOC/dati/dem_Gatta.txt");
 }
Example #9
0
 virtual const char* get_dem_file_name() const
 {
     return getenv_default("FILE_DEM_SPC", "../../PP+BLOC/dati/dem_SanPi.txt");
 }