Beispiel #1
0
/* panel_helper_suspend */
static int _panel_helper_suspend(Panel * panel)
{
#ifdef __NetBSD__
	int sleep_state = 3;
#else
	int fd;
	char * suspend[] = { "/usr/bin/sudo", "sudo", "/usr/bin/apm", "-s",
		NULL };
	GError * error = NULL;
#endif

#ifdef __NetBSD__
	if(sysctlbyname("machdep.sleep_state", NULL, NULL, &sleep_state,
				sizeof(sleep_state)) != 0)
		return -panel_error(panel, "sysctl", 1);
#else
	if((fd = open("/sys/power/state", O_WRONLY)) >= 0)
	{
		write(fd, "mem\n", 4);
		close(fd);
		return 0;
	}
	if(g_spawn_async(NULL, suspend, NULL, G_SPAWN_FILE_AND_ARGV_ZERO, NULL,
				NULL, NULL, &error) != TRUE)
	{
		panel_error(panel, error->message, 1);
		g_error_free(error);
		return -1;
	}
#endif
	_panel_helper_lock(panel); /* XXX may already be suspended */
	return 0;
}
Beispiel #2
0
static void _lock_dialog_on_response(GtkWidget * widget, gint response,
		gpointer data)
{
	Panel * panel = data;

	gtk_widget_hide(widget);
	if(response == TRUE)
		_panel_helper_lock(panel);
}
Beispiel #3
0
/* panel_helper_suspend */
static void _panel_helper_suspend(Panel * panel)
{
#ifdef __NetBSD__
	int sleep_state = 3;
#else
	int fd;
	char * suspend[] = { "/usr/bin/sudo", "sudo", "/usr/bin/apm", "-s",
		NULL };
	const unsigned int flags = G_SPAWN_FILE_AND_ARGV_ZERO;
	GError * error = NULL;
#endif

#ifdef __NetBSD__
	if(sysctlbyname("machdep.sleep_state", NULL, NULL, &sleep_state,
				sizeof(sleep_state)) != 0)
	{
		_panel_helper_error(panel, "sysctl", 1);
		return;
	}
#else
	if((fd = open("/sys/power/state", O_WRONLY)) >= 0)
	{
		write(fd, "mem\n", 4);
		close(fd);
	}
	else if(g_spawn_async(NULL, geteuid() == 0 ? &suspend[2] : suspend,
				NULL, geteuid() == 0 ? 0 : flags, NULL, NULL,
				NULL, &error) != TRUE)
	{
		_panel_helper_error(panel, error->message, 1);
		g_error_free(error);
		return;
	}
#endif
	_panel_helper_lock(panel); /* XXX may already be suspended */
}