Exemplo n.º 1
0
static bool
startup(void *data)
{
    bool finished = true;
    int result = EXIT_FAILURE;

    the_runner = runner_new(args.filename);
    if (!the_runner)
        goto end;

    if (args.check_only) {
        printf("file: '%s' - Syntax OK\n", args.filename);
        result = EXIT_SUCCESS;
        goto end;
    }

    if (runner_run(the_runner) < 0) {
        SOL_ERR("Failed to run");
        goto end;
    }

    finished = false;

end:
    if (finished)
        sol_quit_with_code(result);

    return false;
}
Exemplo n.º 2
0
int
gf_umount_lazy (char *xlname, char *path, int rmdir_flag)
{
        int                   ret               = -1;
        runner_t              runner            = {0,};

        runinit (&runner);
#ifdef GF_LINUX_HOST_OS
        runner_add_args (&runner, _PATH_UMOUNT, "-l", path, NULL);
#else
        if (rmdir_flag)
                runner_add_args (&runner, SBIN_DIR "/umountd",
                                 "-r", path, NULL);
        else
                runner_add_args (&runner, SBIN_DIR "/umountd",
                                 path, NULL);
#endif
        ret = runner_run (&runner);
        if (ret) {
                gf_msg (xlname, GF_LOG_ERROR, errno, LG_MSG_UNMOUNT_FAILED,
                        "Lazy unmount of %s", path);
        }

#ifdef GF_LINUX_HOST_OS
        if (!ret && rmdir_flag) {
                ret = rmdir (path);
                if (ret)
                        gf_msg (xlname, GF_LOG_WARNING, errno,
                                LG_MSG_DIR_OP_FAILED, "rmdir %s", path);
        }
#endif

        return ret;
}
Exemplo n.º 3
0
static bool
startup(void *data)
{
    bool finished = true;
    int result = EXIT_FAILURE;
    struct sol_ptr_vector *memory_maps;

    str_arena = sol_arena_new();
    if (!str_arena) {
        fprintf(stderr, "Cannot create str arena\n");
        goto end;
    }

    if (args.execute_type) {
        the_runner = runner_new_from_type(args.name, args.options);
    } else {
        the_runner = runner_new_from_file(args.name, args.options,
                                          &args.fbp_search_paths);
    }

    if (!the_runner)
        goto end;

    if (args.check_only) {
        printf("'%s' - Syntax OK\n", args.name);
        result = EXIT_SUCCESS;
        goto end;
    }

    if (args.provide_sim_nodes) {
        int err;
        err = runner_attach_simulation(the_runner);
        if (err < 0) {
            fprintf(stderr, "Cannot attach simulation nodes\n");
            goto end;
        }
    }

    if (sol_conffile_resolve_memmap(&memory_maps)) {
        SOL_ERR("Couldn't resolve memory mappings on config file");
        goto end;
    }
    if (memory_maps)
        load_memory_maps(memory_maps);

    if (runner_run(the_runner) < 0) {
        fprintf(stderr, "Failed to run\n");
        goto end;
    }

    finished = false;

end:
    if (finished)
        sol_quit_with_code(result);

    return false;
}
Exemplo n.º 4
0
static int
sc_service_action (struct service_command *sc, char *command)
{
        runner_t      runner = {0,};

        runinit (&runner);
        runner_add_args (&runner, sc->binary, sc->service, command, NULL);
        return runner_run (&runner);
}
Exemplo n.º 5
0
int
runcmd (const char *arg, ...)
{
        runner_t runner;
        va_list argp;

        runinit (&runner);
        /* ISO C requires a named argument before '...' */
        runner_add_arg (&runner, arg);

        va_start (argp, arg);
        runner_va_add_args (&runner, argp);
        va_end (argp);

        return runner_run (&runner);
}
Exemplo n.º 6
0
int
main (int argc, char **argv)
{
        runner_t runner;
        char buf[80];
        char *wdbuf;;
        int ret;
        int fd;
        long pathmax = pathconf ("/", _PC_PATH_MAX);
        struct timeval tv = {0,};
        struct timeval *tvp = NULL;

        wdbuf = malloc (pathmax);
        assert (wdbuf);
        getcwd (wdbuf, pathmax);

        TBANNER ("basic functionality");
        runcmd ("echo", "a", "b", NULL);

        TBANNER ("argv extension");
        runcmd ("echo", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10",
                "11", "12", "13", "14", "15", "16", "17", "18", "19", "20",
                "21", "22", "23", "24", "25", "26", "27", "28", "29", "30",
                "31", "32", "33", "34", "35", "36", "37", "38", "39", "40",
                "41", "42", "43", "44", "45", "46", "47", "48", "49", "50",
                "51", "52", "53", "54", "55", "56", "57", "58", "59", "60",
                "61", "62", "63", "64", "65", "66", "67", "68", "69", "70",
                "71", "72", "73", "74", "75", "76", "77", "78", "79", "80",
                "81", "82", "83", "84", "85", "86", "87", "88", "89", "90",
                "91", "92", "93", "94", "95", "96", "97", "98", "99", "100", NULL);

        TBANNER ("add_args, argprintf, log, and popen-style functionality");
        runinit (&runner);
        runner_add_args (&runner, "echo", "pid:", NULL);
        runner_argprintf (&runner, "%d\n", getpid());
        runner_add_arg (&runner, "wd:");
        runner_add_arg (&runner, wdbuf);
        runner_redir (&runner, 1, RUN_PIPE);
        runner_start (&runner);
        runner_log (&runner, "(x)", LOG_DEBUG, "starting program");
        while (fgets (buf, sizeof(buf), runner_chio (&runner, 1)))
                printf ("got: %s", buf);
        runner_end (&runner);

        TBANNER ("execve error reporting");
        ret = runcmd ("bafflavvitty", NULL);
        printf ("%d %d [%s]\n", ret, errno, strerror (errno));

        TBANNER ("output redirection");
        fd = mkstemp ("/tmp/foof");
        assert (fd != -1);
        runinit (&runner);
        runner_add_args (&runner, "echo", "foo", NULL);
        runner_redir (&runner, 1, fd);
        ret = runner_run (&runner);
        printf ("%d", ret);
        if (ret != 0)
                printf (" %d [%s]", errno, strerror (errno));
        putchar ('\n');

        if (argc > 1) {
                tv.tv_sec = strtoul (argv[1], NULL, 10);
                if (tv.tv_sec > 0)
                        tvp = &tv;
                select (0, 0, 0, 0, tvp);
        }

        return 0;
}
Exemplo n.º 7
0
void runner_change_callback( resolver* RS, const char* key, size_t key_len, const char* val, size_t val_len )
{
	if( g_changeStack >= MAX_CHANGE_STACK )
	{
		fprintf( stderr, "ERROR: exceeded change stack (%d changes)\n", MAX_CHANGE_STACK );
		return;
	}
	g_changeStack++;
#define ISKEY( s ) ( key_len == sizeof(s)-1 && !memcmp( s, key, sizeof(s)-1 ) )
#define PARSEINT() str_to_int( val )
#define PARSEENUM( enumstr ) enumstr_to_int( val, enumstr )
#define NOTNULL() ( val_len && ( val[0] != '0' || val[1] != 0 ) )
	
	X_DBG( printf( "CHANGE \"%.*s\" = \"%.*s\"\n", key_len, key, val_len, val ) );
	
	if( ISKEY( "quit" ) ){ if( NOTNULL() ) win_quit(); }
	else if( ISKEY( "run" ) ){ if( NOTNULL() ) runner_run( val ); }
	else if( ISKEY( "test" ) )
	{
		if( NOTNULL() )
		{
			if( g_inTest )
			{
				fprintf( stderr, "ERROR: 'test' action recursion, cannot start testing in testing progress callback\n" );
				return;
			}
			g_inTest = 1;
			runner_fsproc( 1 );
			g_inTest = 0;
		}
	}
	else if( ISKEY( "window.width" ) ){ g_window_width = PARSEINT(); g_requested_changes |= REQCHG_WINDOWSIZE; }
	else if( ISKEY( "window.height" ) ){ g_window_height = PARSEINT(); g_requested_changes |= REQCHG_WINDOWSIZE; }
	else if( ISKEY( "window.image" ) ){ win_set_background_image( PARSEINT() ); }
	else if( ISKEY( "window.title" ) )
	{
		win_set_title( val );
	}
	else if( key_len && *key == '#' )
	{
		/* CONTROL SETTINGS */
		const char* nkey = NULL;
		int ctlid = str_to_int_ext( key + 1, &nkey );
		if( ctlid < 0 )
		{
			fprintf( stderr, "ERROR: invalid control id=%d\n", ctlid );
			goto end;
		}
		if( ctlid > MAX_CONTROLS )
		{
			fprintf( stderr, "ERROR: exceeded MAX_CONTROLS with id=%d\n", ctlid );
			goto end;
		}
		if( ctlid >= g_numControls )
			win_ctl_resize( ctlid + 1 );
		
		key_len -= nkey - key;
		key = nkey;
		runner_change_ctl_handler( RS, &g_controls[ ctlid ], key, key_len, val, val_len );
		
	}
	else if( key_len >= sizeof("event.control")-1 && !strncmp( key, "event.control", sizeof( "event.control" )-1 ) )
	{
		key += sizeof("event.control")-1;
		key_len -= sizeof("event.control")-1;
		runner_change_ctl_handler( RS, g_event_control, key, key_len, val, val_len );
	}
	
end:
	g_changeStack--;
}