Ejemplo n.º 1
0
int main (int argc, char *argv[])
{
    loop = g_main_loop_new (NULL, FALSE);

    if (argc > 1 && g_str_equal(argv[1], "--menu")) {
        menu = spice_ctrl_foreign_menu_new ();
        g_signal_connect (menu, "notify", G_CALLBACK (notified), NULL);
        connect_signals (menu);

        spice_ctrl_foreign_menu_listen (menu, NULL, NULL, NULL);
    } else {
        ctrl = spice_ctrl_controller_new ();
        g_signal_connect (ctrl, "notify", G_CALLBACK (notified), NULL);
        connect_signals (ctrl);

        spice_ctrl_controller_listen (ctrl, NULL, NULL, NULL);
    }

    g_main_loop_run (loop);

    if (ctrl != NULL)
        g_object_unref (ctrl);
    if (menu != NULL)
        g_object_unref (menu);

    return 0;
}
Ejemplo n.º 2
0
/*
 ==================================
 ProfileWindow::ProfileWindow
 ==================================
 */
ProfileWindow::ProfileWindow(Profile *prof, TwoDeeOverview *tdo, Gtk::Window *profilewindow, Gtk::Window *overviewwindow, Gtk::EventBox *eventboxprof,
                             const Glib::RefPtr<Gtk::Builder>& builder, AdvancedOptionsWindow *aow) :
      prof(prof), tdo(tdo), aow(aow), eventboxprof(eventboxprof), profilewindow(profilewindow), overviewwindow(overviewwindow)
{
   profileworker = NULL;
   
   classifyworker = new ClassifyWorker(this->prof);
   classifyworker->sig_done.connect(sigc::mem_fun(*this, &ProfileWindow::points_classified));
   classifyworker->start();
   
   load_xml(builder);
   
   profilewindow->set_title("LAG Profile");
   
   pointwidthselectprof->set_value(2);
   movingaveragerangeselect->set_value(5);
   slantwidthselectprof->set_value(5);
   classificationselect->set_value(7);
   
   connect_signals();
   
   profilewindow->show_all();
   
   set_statusbar_label("");
   
   prof->setshowheightscale(showheightscalecheck->get_active());
   prof->setpointwidth(pointwidthselectprof->get_value());
   prof->setdrawpoints(pointshowtoggle->get_active());
   prof->setdrawmovingaverage(lineshowtoggle->get_active());
   prof->setmavrgrange(movingaveragerangeselect->get_value());
   prof->setslantwidth(slantwidthselectprof->get_value());
   prof->setslantwidth(slantwidthselectprof->get_value());
   prof->setslanted(slantedprof->get_active());
}
Ejemplo n.º 3
0
DocumentView::DocumentView(Window& window, const unicode& filename):
    window_(window) {
    create_buffer();

    build_widgets();
    connect_signals();

    open_file(filename);
}
Ejemplo n.º 4
0
/*  Called by the plugin system when the plugin is loaded.
 *  Registers plugin commands and connects signal handlers.
 */
static gboolean
plugin_load_hook(PurplePlugin *plugin) {
    purple_debug_info(PLUGIN_ID, "AKA Plugin Loaded.\n") ;
    /*  register any custom plugin commands  */
    register_cmds(plugin) ;
    /*  register any signal handlers  */
    connect_signals(plugin) ;
    /*  return TRUE says continue loading the plugin  */
    return TRUE ;
}
Ejemplo n.º 5
0
DocumentView::DocumentView(Window& window):
    window_(window) {

    create_buffer();

    build_widgets();
    connect_signals();

    create_new_file();
}
Ejemplo n.º 6
0
GtkWidget*	get_new_entry(t_entry_arg* args)
{
	GtkWidget*	entry;

	entry = gtk_entry_new();
	connect_signals(entry, args);
	connect_parent(&args->ent_parent, entry);
	if (args->ent_show == TRUE)
		gtk_widget_show(entry);
	return (entry);
}
Ejemplo n.º 7
0
/*
==================================
 FileSaver::FileSaver
==================================
*/
FileSaver::FileSaver(TwoDeeOverview *tdo, Profile *prof, const Glib::RefPtr<Gtk::Builder>& builder)
:
		lidardata	(NULL),
		tdo			(tdo),
		prof		(prof),
		saveworker	(NULL)

{
  load_xml(builder);
  connect_signals();
  utmselect->set_active(true);
}
ChipCapacitiesDialog::ChipCapacitiesDialog( BaseObjectType* cobject,
	const Glib::RefPtr<Gtk::Builder>& builder)
	:
	ScannerTemplateDialog( cobject, builder, "chip-capacities"),
	button_change_capacity_(0),
	capacity_(SCANNER_DEFAULT_CHIP_CAPACITY)
{
	init_ui();

	connect_signals();

	show_all_children();
}
Ejemplo n.º 9
0
/*
 ==================================
 AdvancedOptionsWindow::AdvancedOptionsWindow
 ==================================
 */
AdvancedOptionsWindow::AdvancedOptionsWindow(TwoDeeOverview *tdo, Profile *prof, const Glib::RefPtr<Gtk::Builder>& builder) :
      tdo(tdo), prof(prof)
{
   load_xml(builder);
   connect_signals();
   
   movespeedselect->set_value(10.00);
   maindetailselect->set_value(1.50);
   previewdetailselectprof->set_value(2.0);
   
   tdo->setmaindetail(maindetailselect->get_value());
   prof->setmaindetail(maindetailselectprof->get_value());
   prof->setpreviewdetail(previewdetailselectprof->get_value());
}
Ejemplo n.º 10
0
SliderSpinBox::SliderSpinBox(QWidget * parent, bool vertical) : QWidget(parent){
	mSpinBox = new QSpinBox(this);
	if(vertical) {
		mLayout = new QVBoxLayout(this);
		mSlider = new QSlider(Qt::Vertical, this);
		mLayout->addWidget(mSlider, 1, Qt::AlignHCenter);
	} else {
		mLayout = new QHBoxLayout(this);
		mSlider = new QSlider(Qt::Horizontal, this);
		mLayout->addWidget(mSlider, 1, Qt::AlignVCenter);
	}

	mLayout->addWidget(mSpinBox, 0);
	mLayout->setContentsMargins(1,1,1,1);

	setLayout(mLayout);
	connect_signals();
}
Ejemplo n.º 11
0
int
main (int argc, char **argv)
{
  ol_log_set_level (OL_INFO);
  /* char usage[] = "Usage: ol_player_test <play|pause|info|next|prev|status|capacity>"; */
  gtk_init (&argc, &argv);
  /* if (argc < 2 || argc > 3) */
  /* { */
  /*   fprintf (stderr, "%s\n", usage); */
  /*   return 1; */
  /* } */
  player = ol_player_new ();
  connect_signals ();
  /* if (strcmp (argv[1], "info") == 0) */
  /*   get_music_info (); */
  /* else if (strcmp (argv[1], "play") == 0) */
  /*   play (); */
  /* else if (strcmp (argv[1], "pause") == 0) */
  /*   _pause (); */
  /* else if (strcmp (argv[1], "prev") == 0) */
  /*   prev (); */
  /* else if (strcmp (argv[1], "next") == 0) */
  /*   next (); */
  /* else if (strcmp (argv[1], "stop") == 0) */
  /*   stop (); */
  /* else if (strcmp (argv[1], "status") == 0) */
  /*   status (); */
  /* else if (strcmp (argv[1], "capacity") == 0) */
  /*   capacity (); */
  /* else if (argc == 3 && strcmp (argv[1], "seek") == 0) */
  /* { */
  /*   int pos = 0; */
  /*   sscanf (argv[2], "%d", &pos); */
  /*   seek (pos); */
  /* } */
  /* else */
  /*   fprintf (stderr, "%s\n", usage); */
  gtk_main ();
  g_object_unref (player);
  return 0;
}
Ejemplo n.º 12
0
int main()
{
    int result = 0;

    value = (float)rand();

    signal(SIGINT, ctrlc);

    if (setup_destination()) {
        printf("Error initializing destination.\n");
        result = 1;
        goto done;
    }

    if (setup_source()) {
        printf("Done initializing source.\n");
        result = 1;
        goto done;
    }

    wait_local_devices();

    if (automate)
        connect_signals();

    // start things off
    printf("STARTING TEST...\n");
    times[0] = get_current_time();
    msig_update_instance(sendsig, counter++, &value, 0, MAPPER_TIMETAG_NOW);
    while (!done) {
        mdev_poll(destination, 0);
        mdev_poll(source, 0);
    }
    goto done;

  done:
    cleanup_destination();
    cleanup_source();
    print_results();
    return result;
}
Ejemplo n.º 13
0
static gboolean
run (void)
{
    gboolean success;
    CutTestContext *test_context;
    CutTest *test;

    test = CUT_TEST(test_iterator);
    connect_signals(test);
    test_context = cut_test_context_new(run_context,
                                        NULL, test_case, NULL, NULL);
    cut_test_context_current_push(test_context);
    success = cut_test_runner_run_test_iterator(CUT_TEST_RUNNER(run_context),
                                                test_iterator, test_context);
    cut_test_context_current_pop();
    disconnect_signals(test);

    g_object_unref(test_context);

    return success;
}
Ejemplo n.º 14
0
int initialize_window(Gui *gui){
  //making the window
  gui->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title(GTK_WINDOW(gui->window), "Crayon Physics A++");
  gtk_window_set_default_size(GTK_WINDOW(gui->window), WINDOW_WIDTH, WINDOW_HEIGHT);
  gtk_window_set_position(GTK_WINDOW(gui->window), GTK_WIN_POS_CENTER);
  
  //making the grid to go in the window
  GtkWidget *grid;
  grid = gtk_grid_new();
  gtk_container_add(GTK_CONTAINER(gui->window), grid);
  
  //make the menu
  if (!initialize_menu(grid, gui)){
    return -1;
  }
  
  //initializing the draw area
  gui->draw_area = gtk_drawing_area_new();
  initialize_draw_area(grid, gui->draw_area);
  
  //initialize the text entry box
  gui->entry = gtk_entry_new();
  initialize_text_entry(grid, gui);

  //initialize the text view
  gui->text_view = gtk_text_view_new();
  initialize_text_view(grid, gui);

  //shapes and bodies for testing
  gtk_widget_show_all(gui->window);
  cpShape *ground = cpSpaceAddStaticShape(gui->space, cpSegmentShapeNew(gui->space->staticBody, cpv(0, 1), cpv(10, 1), CRAYON_RADIUS * 2));
  cpShapeSetFriction(ground, 1.0);
  cpSpaceAddStaticShape(gui->space, cpSegmentShapeNew(gui->space->staticBody, cpv(3, -100), cpv(3, 100), CRAYON_RADIUS * 2));
  //add events and connect signals
  gtk_widget_add_events(gui->draw_area, GDK_BUTTON_PRESS_MASK);
  connect_signals(gui);
  
  return 1;
}
LiningAdjustmentDialog::LiningAdjustmentDialog( BaseObjectType* cobject,
	const Glib::RefPtr<Gtk::Builder>& builder)
	:
	ScannerTemplateDialog( cobject, builder, "lining-adjustment"),
	treeview_strip_code_(0),
	spinbutton_strip_(0),
	spinbutton_code_(0),
	spinbutton_broadcast_(0),
	menutoolbutton_write_current_(0),
	menuitem_write_all_(0),
	menutoolbutton_load_from_file_(0),
	menuitem_restore_current_(0),
	menuitem_restore_all_(0)
{
	init_ui();

	connect_signals();

	set_adjustment_sensitive(false);

	show_all_children();
}
Ejemplo n.º 16
0
int main (int argc, char *argv[])
{
	PREFS images;															/* Create preferences object */
	gchar *window_name;												/* String to hold window's name */
	gchar *xmlpath;														/* Path to Glade's XML file */
	gchar *iconpath;													/* Path to MESSyFront's icon */

	gtk_init (&argc, &argv);									/* Initialize GTK */
	glade_init ();														/* Initialize Glade */

	/* Create Glade Interface */
	xmlpath = g_strjoin (DIR_SEP, INSTALL_PREFIX, XML_DIRECTORY, XML_FILENAME, NULL);
	images.xml = glade_xml_new (xmlpath, NULL, NULL);
	if (!images.xml)
	{
		g_warning ("MESSYFRONT: Unable to create interface with libglade!");
		exit (EXIT_FAILURE);
	}

	/* Connect homemade signals */
	connect_signals (&images);

	/* Connect Glade-made signals */
	glade_xml_signal_autoconnect (images.xml);

	/* Set window's name and icon */
	window_name = g_strjoin (" ", MESSY_APP_NAME, MESSY_VERSION, NULL);
	change_window_name (&images, window_name);
	iconpath = g_strjoin (DIR_SEP, INSTALL_PREFIX, ICON_PATH, ICON_NAME, NULL);
	change_window_icon (&images, iconpath);

	get_prefs_from_file (&images);						/* Get user's preferences */
	populate_object_from_fields (&images);		/* Initialize object "images" */

	gtk_main ();															/* Start the main event loop */

	return EXIT_SUCCESS;											/* End of story. */
}
Ejemplo n.º 17
0
/* Main entry point */
int main(int argc, char** argv) {
	GtkWidget *window;
	GtkAccelGroup *group;
	struct eid_vwr_ui_callbacks* cb;
	pthread_t thread;
	GdkPixbuf *logo;
	GError* err = NULL;

	/* The GNU implementation of setlocale() ignores whatever we
	 * specify if the LANGUAGE environment variable has a value, so
	 * ensure that it doesn't
	 */
	putenv("LANGUAGE=");
	bindtextdomain("eid-viewer", DATAROOTDIR "/locale");
	textdomain("eid-viewer");

	eid_vwr_convert_set_lang(langfromenv());

	gtk_init(&argc, &argv);
	builder = gtk_builder_new();
	if(gtk_builder_add_from_string(builder, VIEWER_GLADE_STRING, strlen(VIEWER_GLADE_STRING), &err) == 0) {
		g_critical("Could not parse Glade XML: %s", err->message);
		exit(EXIT_FAILURE);
	}

	window = GTK_WIDGET(gtk_builder_get_object(builder, "mainwin"));
	group = gtk_accel_group_new();
	gtk_window_add_accel_group(GTK_WINDOW(window), group);

	touched_labels = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);

	bindata_init();
	connect_signals(window);
	setup_treeview();

	certs_init();

	cb = eid_vwr_cbstruct();
	cb->newsrc = newsrc;
	cb->newstringdata = newstringdata;
	cb->newbindata = newbindata;
	cb->logv = ui_log_init();
	cb->newstate = newstate;
	cb->pinop_result = pinop_result;
	cb->readers_changed = readers_changed;
	eid_vwr_createcallbacks(cb);

	pthread_create(&thread, NULL, threadmain, NULL);

	G_GNUC_BEGIN_IGNORE_DEPRECATIONS
	logo = gdk_pixbuf_from_pixdata(&logo_128, FALSE, NULL);
	G_GNUC_END_IGNORE_DEPRECATIONS
	gtk_window_set_default_icon(logo);

	gtk_widget_show(window);

	if(argc > 1) {
		eid_vwr_be_deserialize(argv[1]);
	}

	gtk_main();

	return 0;
}
Ejemplo n.º 18
0
static void app_startup_handler(GApplication *app, gpointer data)
{
	gmpv_handle *ctx = data;
	const gchar *vid_area_style = ".gmpv-vid-area{background-color: black}";
	GSettingsBackend *config_backend;
	GtkCssProvider *style_provider;
	gboolean css_loaded;
	gboolean use_opengl;
	gboolean config_migrated;
	gboolean mpvinput_enable;
	gboolean csd_enable;
	gboolean dark_theme_enable;
	gchar *config_file;
	gchar *mpvinput;

	setlocale(LC_NUMERIC, "C");
	g_set_application_name(_("GNOME MPV"));
	gtk_window_set_default_icon_name(ICON_NAME);

	bindtextdomain(GETTEXT_PACKAGE, PACKAGE_LOCALEDIR);
	bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
	textdomain(GETTEXT_PACKAGE);

	config_file = get_config_file_path();

	config_backend = g_keyfile_settings_backend_new
				(	config_file,
					CONFIG_ROOT_PATH,
					CONFIG_ROOT_GROUP );

	use_opengl = get_use_opengl();

	ctx->mpv_ctx = mpv_create();
	ctx->files = NULL;
	ctx->opengl_ctx = NULL;
	ctx->opengl_ready = FALSE;
	ctx->paused = TRUE;
	ctx->loaded = FALSE;
	ctx->new_file = TRUE;
	ctx->sub_visible = TRUE;
	ctx->init_load = TRUE;
	ctx->playlist_move_dest = -1;
	ctx->log_level_list = NULL;
	ctx->keybind_list = NULL;
	ctx->config = g_settings_new_with_backend(APP_ID, config_backend);
	ctx->app = GTK_APPLICATION(app);
	ctx->gui = MAIN_WINDOW(main_window_new(ctx->app, use_opengl));
	ctx->fs_control = NULL;
	ctx->playlist_store = PLAYLIST_WIDGET(ctx->gui->playlist)->list_store;

	config_migrated = migrate_config(ctx);
	style_provider = gtk_css_provider_new();

	css_loaded = gtk_css_provider_load_from_data
			(style_provider, vid_area_style, -1, NULL);

	if(!css_loaded)
	{
		g_warning ("Failed to apply background color css");
	}

	gtk_style_context_add_provider_for_screen
		(	gtk_window_get_screen(GTK_WINDOW(ctx->gui)),
			GTK_STYLE_PROVIDER(style_provider),
			GTK_STYLE_PROVIDER_PRIORITY_APPLICATION );

	g_object_unref(style_provider);

	csd_enable = g_settings_get_boolean
				(ctx->config, "csd-enable");

	dark_theme_enable = g_settings_get_boolean
				(ctx->config, "dark-theme-enable");

	mpvinput_enable = g_settings_get_boolean
				(ctx->config, "mpv-input-config-enable");

	mpvinput = g_settings_get_string
				(ctx->config, "mpv-input-config-file");

	if(csd_enable)
	{
		gtk_application_set_app_menu
			(ctx->app, G_MENU_MODEL(build_app_menu()));

		main_window_enable_csd(ctx->gui);
	}
	else
	{
		gtk_application_set_app_menu
			(ctx->app, NULL);

		gtk_application_set_menubar
			(ctx->app, G_MENU_MODEL(build_full_menu()));
	}

	gtk_widget_show_all(GTK_WIDGET(ctx->gui));

	if(csd_enable)
	{
		control_box_set_fullscreen_btn_visible
			(CONTROL_BOX(ctx->gui->control_box), FALSE);
	}

	control_box_set_chapter_enabled
		(CONTROL_BOX(ctx->gui->control_box), FALSE);

	if(!main_window_get_use_opengl(ctx->gui))
	{
		ctx->vid_area_wid = get_xid(ctx->gui->vid_area);
	}

	g_assert(	main_window_get_use_opengl(ctx->gui) ||
			ctx->vid_area_wid != -1 );

	main_window_load_state(ctx->gui);
	setup_accelerators(ctx);
	setup_dnd_targets(ctx);
	actionctl_map_actions(ctx);
	connect_signals(ctx);
	load_keybind(ctx, mpvinput_enable?mpvinput:NULL, FALSE);
	mpris_init(ctx);
	media_keys_init(ctx);

	g_object_set(	ctx->gui->settings,
			"gtk-application-prefer-dark-theme",
			dark_theme_enable,
			NULL );

	g_timeout_add(	SEEK_BAR_UPDATE_INTERVAL,
			(GSourceFunc)update_seek_bar,
			ctx );

	if(config_migrated)
	{
		GtkWidget *dialog
			= gtk_message_dialog_new
				(	GTK_WINDOW(ctx->gui),
					GTK_DIALOG_DESTROY_WITH_PARENT,
					GTK_MESSAGE_INFO,
					GTK_BUTTONS_OK,
					_("Your configuration file has been "
					"moved to the new location at %s."),
					config_file );

		gtk_dialog_run(GTK_DIALOG(dialog));
		gtk_widget_destroy(dialog);
	}

	g_free(config_file);
	g_free(mpvinput);
}
Ejemplo n.º 19
0
int main(int argc, char *argv[])
{
	int argp = 1;
	uid_t uid = SANDBOX_UID;

	// Check the "net" argument.
	if (argc > argp && strcmp(argv[argp], "net") == 0)
	{
		uid = SANDBOX_NET_UID;
		argp = 2;
	}

	// Print usage.
	if (argc < 6 + argp)
	{
		printf("Runs a command in a sandbox environment.\n");
		printf("Usage: %s [net] time heap files disk dir course_key prg [arguments...]\n", argv[0]);
		printf("    1k for kilobyte, m for mega, g for giga and - for unlimited\n");
		printf("    net          enables network (optional)\n");
		printf("    time         maximum time for process in seconds\n");
		printf("    heap         maximum heap memory size\n");
		printf("    files        maximum number of open file descriptors\n");
		printf("    disk         maximum disk write size\n");
		printf("    dir          a target directory or -\n");
		printf("    course_key   a course key for building PATH\n");
		printf("    prg          a program to envoke\n");
		printf("    arguments    any arguments for program (optional)\n");
		return 0;
	}

	// Create new process group for kill(0).
	if (setpgid(0, 0) != 0) {
		fprintf(stderr, "FAILED: set process group\n");
		return fail("main");
	}

	connect_signals();

	// Look for course specific sandbox.
	char *course = argv[argp + 5];
	char sandbox[strlen(SANDBOX_DIR) + strlen(course) + 2];
	strcpy(sandbox, SANDBOX_DIR);
	strcat(sandbox, "_");
	strcat(sandbox, course);
	DIR* test = opendir(sandbox);
	if (test)
	{
		closedir(test);
	}
	else if (ENOENT == errno)
	{
		sandbox[strlen(SANDBOX_DIR)] = 0;
	}
	else
	{
		fprintf(stderr, "FAILED: looking for course specific sandbox\n");
		return fail("main");
	}

	// Make static dir variable.
	dir = malloc(strlen(argv[argp + 4]) + 1);
	if (dir == NULL)
	{
		fprintf(stderr, "FAILED: malloc directory name\n");
		return fail("main");
	}
	strcpy(dir, argv[argp + 4]);
	if (strcmp(dir, "-") != 0)
	{
		/*if (access(dir, R_OK | W_OK | X_OK) != 0)
		{
			fprintf(stderr, "FAILED: access %s\n", dir);
			return fail("main");
		}*/
		char tmp_path[strlen(sandbox) + strlen(TMP_PATH) + 1];
		strcpy(tmp_path, sandbox);
		strcat(tmp_path, TMP_PATH);
		/*if (access(tmp_path, R_OK | W_OK | X_OK) != 0)
		{
			fprintf(stderr, "FAILED: access %s\n", tmp_path);
			return fail("main");
		}*/

		// Move target dir inside sandbox.
		path = tempnam(tmp_path, NULL);
		if (path == NULL)
		{
			fprintf(stderr, "FAILED: tempnam %s\n", tmp_path);
			return fail("main");
		}
		if (move_directory(dir, path) != 0)
		{
			fprintf(stderr, "FAILED: move %s %s\n", dir, path);
			return 1;
		}

		// Store directory owner.
		struct stat path_stat;
		if (lstat(path, &path_stat) != 0)
		{
			fprintf(stderr, "FAILED: stat %s\n", path);
			return fail("main");
		}
		orig_uid = path_stat.st_uid;
		orig_gid = path_stat.st_gid;

		// Change directory owner.
		if (chown_directory(path, uid, orig_gid) != 0)
		{
			fprintf(stderr, "FAILED: chown %s to %d\n", path, uid);
			return 1;
		}
	}

	// Prepare values before forking.
	char *local_path = TMP_PATH;
	if (path != NULL)
	{
		local_path = path + strlen(sandbox);
	}
	unsigned long int memory = parse_number(argv[argp + 1]);
	unsigned long int files = parse_number(argv[argp + 2]);
	unsigned long int disk = parse_number(argv[argp + 3]);
	char cmd_path[strlen(CMD_PATH) + strlen(argv[argp + 5]) + 1];
	strcpy(cmd_path, CMD_PATH);
	strcat(cmd_path, argv[argp + 5]);

	// Limit maximum run time.
	time_limit = parse_number(argv[argp]);
	if (time_limit > 0 && time_limit < ULONG_MAX) alarm(time_limit);

	// Fork child process.
	pid = fork();
	if (pid == -1)
	{
		fprintf(stderr, "FAILED: fork\n");
		return fail("main");
	}
	if (pid == 0)
	{
		if (chroot(sandbox) != 0)
		{
			fprintf(stderr, "FAILED: chroot %s\n", sandbox);
			return fail("main");
		}
		if (setuid(uid) != 0)
		{
			fprintf(stderr, "FAILED: setuid %d\n", uid);
			return fail("main");
		}
		if (chdir(local_path) != 0)
		{
			fprintf(stderr, "FAILED: chdir %s\n", local_path);
			return fail("main");
		}

		// Create command line array.
		char *cmd = argv[argp + 6];
		int argn = argp + 7;
		char *arg[argc - argn + 2];
		arg[0] = cmd;
		int p = 1;
		while (argn < argc)
		{
			arg[p] = argv[argn];
			p++;
			argn++;
		}
		arg[p] = NULL;

		// Create environment array.
		char *env[5];
		char envpath[6 + strlen(cmd_path)];
		strcpy(envpath, "PATH=");
		strcat(envpath, cmd_path);
		env[0] = envpath;
		struct passwd *pw = getpwuid(uid);
		if (pw == NULL)
		{
			fprintf(stderr, "FAILED: getpwuid %d\n", uid);
			return fail("main");
		}
		char envhome[6 + strlen(pw->pw_dir)];
		strcpy(envhome, "HOME=");
		strcat(envhome, pw->pw_dir);
		env[1] = envhome;
		env[2] = "DISPLAY=:0";
		env[3] = "LANG=en_US.UTF-8";
		env[4] = NULL;

		if (limit_process(memory, files, disk) != 0) return 1;

		// Update path in current env for finding the cmd.
		if (setenv("PATH", cmd_path, 1) != 0)
		{
			fprintf(stderr, "FAILED: setenv PATH=%s\n", cmd_path);
			return fail("main");
		}

		// Replace the process.
		execvpe(cmd, arg, env);
		fprintf(stderr, "FAILED: execvp\n");
		return fail("main");
	}

	// Wait for child process to terminate.
	else
	{
		pid_t w;
		int status;
		do
		{
			w = waitpid(pid, &status, 0);
			if (w == -1)
			{
				fprintf(stderr, "FAILED: waitpid %d\n", pid);
				return fail("main");
			}
		}
		while (!WIFEXITED(status) && !WIFSIGNALED(status));
		cleanup();
		if (WIFEXITED(status))
		{
			return WEXITSTATUS(status);
		}
		fprintf(stderr, "FAILED: Process did not end with exit status.\n");
		return fail("main");
	}
}
Ejemplo n.º 20
0
int
main (int argc, char *argv[])
{
	GtkWidget *dialog = NULL;
#ifdef G_OS_WIN32
	gchar *temp;

	package_prefix =
		g_win32_get_package_installation_directory (NULL, NULL);
	package_datadir = g_strdup_printf ("%s%s", package_prefix, "/share");
#endif

#ifdef ENABLE_NLS
#ifdef G_OS_WIN32
	temp = g_strdup_printf ("%s%s", package_prefix, "/lib/locale");
	bindtextdomain (GETTEXT_PACKAGE, temp);
	g_free (temp);
#else
	bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
#endif
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain (GETTEXT_PACKAGE);
#endif
	
	gtk_set_locale ();
	gtk_init (&argc, &argv);
	
#ifdef G_OS_WIN32
	temp = g_strdup_printf ("%s%s", package_datadir, "/pixmaps");
	//add_pixmap_directory (temp);
	g_free (temp);
#else
	//add_pixmap_directory (PACKAGE_DATA_DIR "/" PACKAGE "/pixmaps");
#endif

	//dialog = create_dialog ();
	xml = glade_xml_new (GLADE_FILE, NULL, NULL);
	if( !xml ) {
	#ifdef G_OS_WIN32
		g_free (package_prefix);
		g_free (package_datadir);
	#endif
		return 1;
	}
	connect_signals ();
	dialog = glade_xml_get_widget (xml, "dialog");
	
	gtk_window_set_title (GTK_WINDOW (dialog), PACKAGE " v" VERSION);

	usb_init ();
	if (usbOpenDevice
		(&handle, USBDEV_SHARED_VENDOR, /*NULL */USBDEV_VENDOR_NAME  ,
		 USBDEV_SHARED_PRODUCT, /*NULL */ USBDEV_NAME ) != 0) {
		psg_message_dialog (GTK_MESSAGE_WARNING,
		//fprintf (stderr,
				 "Could not find USB device \"%s\" with vid=0x%x pid=0x%x\n",
				 USBDEV_NAME, USBDEV_SHARED_VENDOR, USBDEV_SHARED_PRODUCT);
		//exit (1);
	}
// We have searched all devices on all busses for our USB device above. Now
// try to open it and perform the vendor specific control operations for the
// function requested by the user.


	gtk_widget_show (dialog);
	update_toggles (dialog);

	gtk_main ();
	usb_close (handle);
#ifdef G_OS_WIN32
	g_free (package_prefix);
	g_free (package_datadir);
#endif
	return 0;
}
Ejemplo n.º 21
0
int main()
{
    int result = 0;
    int stats[6], i;

    signal(SIGINT, ctrlc);

    if (setup_destination()) {
        printf("Error initializing destination.\n");
        result = 1;
        goto done;
    }

    if (setup_source()) {
        printf("Done initializing source.\n");
        result = 1;
        goto done;
    }

    wait_local_devices();

    if (automate)
        connect_signals();

    printf("\n**********************************************\n");
    printf("************ NO INSTANCE STEALING ************\n");
    loop(100);

    stats[0] = sent;
    stats[1] = received;

    for (i=0; i<10; i++)
        msig_release_instance(sendsig, sendinst[i], MAPPER_TIMETAG_NOW);
    sent = received = 0;

    msig_set_instance_allocation_mode(recvsig, IN_STEAL_OLDEST);
    printf("\n**********************************************\n");
    printf("*************** IN_STEAL_OLDEST **************\n");
    loop(100);

    stats[2] = sent;
    stats[3] = received;

    sent = received = 0;

    msig_set_instance_allocation_mode(recvsig, IN_UNDEFINED);
    msig_set_instance_management_callback(recvsig, overflow_handler);
    printf("\n**********************************************\n");
    printf("*********** CALLBACK > ADD INSTANCE **********\n");
    loop(100);

    stats[4] = sent;
    stats[5] = received;

    printf("NO STEALING: sent %i updates, received %i updates (mismatch is OK).\n", stats[0], stats[1]);
    printf("STEAL OLDEST: sent %i updates, received %i updates (mismatch is OK).\n", stats[2], stats[3]);
    printf("ADD INSTANCE: sent %i updates, received %i updates.\n", stats[4], stats[5]);

    result = (stats[4] != stats[5]);

  done:
    cleanup_destination();
    cleanup_source();
    printf("Test %s.\n", result ? "FAILED" : "PASSED");
    return result;
}