Exemple #1
0
kbool_t knh_VirtualMachine_launch(CTX ctx, ksfp_t *sfp)
{
#ifdef K_USING_SIGNAL
#if defined(K_USING_MINGW_)
	knh_setsignal(ctx);
#else
	struct sigaction sa_orig[32];
	knh_bzero(sa_orig, sizeof(struct sigaction) * 32);
	knh_setsignal(ctx, sa_orig, 32);
#endif /* defined(K_USING_MINGW_) */
	kbool_t b = (knh_VirtualMachine_run(ctx, sfp, CODE_LAUNCH) == NULL);
	if(ctx->signal != 0) {
#if defined(K_USING_MINGW_)
		if(ctx->signal == SIGSEGV || ctx->signal == SIGILL) {
#else
		if(ctx->signal == SIGSEGV || ctx->signal == SIGBUS || ctx->signal == SIGILL) {
#endif /* defined(K_USING_MINGW_) */
			_Exit(EX_SOFTWARE);
		}
	}
#if defined(K_USING_MINGW_)
	knh_unsetsignal(ctx);
#else
	knh_unsetsignal(ctx, sa_orig, 32);
#endif /* defined(K_USING_MINGW_) */
	return b;
#else
	kbool_t b = (knh_VirtualMachine_run(ctx, sfp, CODE_LAUNCH) == NULL);
#endif
#if !defined(K_USING_MINGW_)
	if(ctx->signal == SIGKILL) {
		_Exit(EX_SOFTWARE);
	}
#endif /* !defined(K_USING_MINGW_) */
	return b;
}

/* ------------------------------------------------------------------------ */

#define OPT_EMPTY    0
#define OPT_NUMBER   1
#define OPT_STRING   2
#define OPT_(O)      O, (sizeof(O)-1)

typedef struct {
	const char *name;
	size_t len;
	int type;
	void (*setopt)(int, const char *);
} knh_optdata_t ;

static knh_optdata_t optdata[] = {
	{OPT_("-v"), OPT_NUMBER, opt_v},
	{OPT_("-a"), OPT_NUMBER, opt_a},
	{OPT_("-l"), OPT_STRING, opt_l},
	{OPT_("--enforce-security"), OPT_STRING, opt_enforce_security},
	{OPT_("--logcached"), OPT_STRING, opt_logcached},
	{OPT_("--verbose:gc"), OPT_EMPTY, opt_verbose_gc},
	{OPT_("--verbose:lang"), OPT_EMPTY, opt_verbose_lang},
	{OPT_("--verbose:pref"), OPT_EMPTY, opt_verbose_pref},
	{NULL, 0, OPT_EMPTY, NULL}, // END
};

static knh_optdata_t *knh_getoptdata(const char *name)
{
	knh_optdata_t *d = optdata;
	while(d->name != NULL) {
		if(knh_strncmp(d->name, name, d->len) == 0) {
			return d;
		}
		d++;
	}
	return NULL;
}
Exemple #2
0
#define OPT_STRING   2
#define OPT_(O)      O, (sizeof(O)-1)

typedef struct {
	const char *name;
	size_t len;
	int type;
	void (*setopt)(CTX, int, const char *);
} knh_optdata_t ;

static void opt_dummy(CTX ctx, int mode, const char *optstr)
{
}

static knh_optdata_t optdata[] = {
	{OPT_("-a"), OPT_NUMBER, opt_dummy},
	{OPT_("-c"), OPT_EMPTY, opt_c},
	{OPT_("-i"), OPT_EMPTY, opt_i},
	{OPT_("-g"), OPT_NUMBER, opt_g},
	{OPT_("-v"), OPT_NUMBER, opt_dummy},
	{OPT_("-l"), OPT_STRING, opt_dummy},
	{OPT_("-O"), OPT_NUMBER, opt_O},
	{OPT_("-P"), OPT_STRING, knh_setStartUpPackage},
	{OPT_("-p"), OPT_NUMBER, opt_p},
	{OPT_("-W"), OPT_NUMBER, opt_W},
	{OPT_("-h"), OPT_EMPTY, opt_help},
	{OPT_("--verbose:gc"), OPT_EMPTY, opt_dummy},
	{OPT_("--verbose:lang"), OPT_EMPTY, opt_dummy},
	{OPT_("--verbose:pref"), OPT_EMPTY, opt_dummy},
//	{"--utest", OPT_EMPTY, opt_utest},
	{OPT_("--help"), OPT_EMPTY, opt_help},
Exemple #3
0
/*!
 *****************************************************************************
 *
 ****************************************************************************/
int optdb_save(int opt, const char *s)
{
        char *s1 = NULL;
        char *endptr = NULL;

        if (opt < 0 || opt > OPT_KEY_LAST)
                return 1;

        OPT_(opt)->is_set = 1;

        if (OPT_(opt)->read_from_file && s && *s == '/') {
                FILE *fp = fopen(s, "r");
                if (fp) {
                        struct stat st;
                        (void)fstat(fileno(fp), &st);
                        s1 = malloc(st.st_size * 2);
                        if (s1) {
                                char *s2 = s1;
                                NO_UNUSED_RESULT fread(s1, 1, st.st_size, fp);
                                while(*s1) {
                                        if (*s1=='\n') *s1=';';
                                                s1++;
                                }
                                s1 = s2;
                        }
                        fclose(fp);
                }
        } else {
                if (s)
                        s1 = strdup(s);
        }
        if (!s1)
                return 0;

        switch (opt)
        {
        case OPT_KEY_SEEK_LENGTH:
        case OPT_KEY_HIST_SIZE:
        {
                NO_UNUSED_RESULT strtoul(s1, &endptr, 10);
                if (*endptr)
                        return 1;
                CLR_OPT_(opt);
                ADD_OPT_(opt, s1, OPT_INT_);
                break;
        }
        case OPT_KEY_SRC:
        case OPT_KEY_DST:
                CLR_OPT_(opt);
                ADD_OPT_(opt, s1, OPT_STR_);
                break;
        default:
                {
                        /*
                         * One could easily have used strsep() here but I
                         * choose not to:
                         * "This function suffers from the same problems as
                         * strtok(). In particular, it modifies the original
                         * string. Avoid it."
                         */
                        char *s2 = s1;
                        char *s_free = s1;   /* save pointer for free() */
                        if (strlen(s1)) {
                                while ((s2 = strchr(s2, ';'))) {
                                        *s2++ = 0;
                                        if (strlen(s1) > 1)
                                                ADD_OPT_(opt, s1, OPT_STR_);
                                        s1 = s2;
                                }
                                if (*s1)
                                        ADD_OPT_(opt, s1, OPT_STR_);
                        }
                        s1 = s_free;         /* restore pointer */
                }
                break;
        }
        if (s1)
                free(s1);

#ifdef DEBUG_
        {
                int i;
                printd(5, "option %d : ", opt);
                for(i = 0; i < OPT_(opt)->n_elem; i++)
                        if (!OPT_(opt)->type)
                                printd(5, "\"%s\" ", OPT_(opt)->u.v_arr_str[i]);
                        else
                                printd(5, "\"%ld\" ", OPT_(opt)->u.v_arr_int[i]);
                printd(5, "\n");
        }
#endif

        return 0;
}