Esempio n. 1
0
static int check_image(struct xs_handle *h, struct backend_info *be,
	const char** errmsg)
{
	const char *path;
	int mode;
	blkif_t *blkif = be->blkif;
	blkif_info_t *info = blkif->info;

	path = get_image_path(info->params);

	/* Check if the image exists and access is permitted */
	mode = R_OK;
	if (!be->readonly)
		mode |= W_OK;
	if (access(path, mode)) {
		if (errno == ENOENT)
			*errmsg = "File not found.";
		else
			*errmsg = "Insufficient file permissions.";
		return -1;
	}

	/* Check that the image is not attached to a different VM */
	if (check_sharing(h, be)) {
		*errmsg = "File already in use by other domain";
		return -1;
	}

	return 0;
}
Esempio n. 2
0
static gboolean
load_fish_image (FishApplet *fish)
{
	GdkPixbuf *pixbuf;
	GError    *error = NULL;
	char      *path = NULL;

	if (!fish->image)
		return FALSE;

	path = get_image_path (fish);

	pixbuf = gdk_pixbuf_new_from_file (path, &error);
	if (error) {
		g_warning ("Cannot load '%s': %s", path, error->message);
		g_error_free (error);
		g_free (path);
		return FALSE;
	}

	if (fish->pixbuf)
		g_object_unref (fish->pixbuf);
	fish->pixbuf = pixbuf;

	g_free (path);

	return TRUE;
}
void Lobby::setTheme()
{
  /*
  QString default_path = getBasePath() + "themes/default/";

  QString background_path = (g_theme_path + "lobbybackground.png");
  QString d_background_path = (default_path + "lobbybackground.png");

  */
  //QString refresh_path = get_image_path("refresh.png");
  /*
  QString d_refresh_path = (default_path + "refresh.png");

  QString addtofav_path = (g_theme_path + "addtofav.png");
  QString d_addtofav_path = (default_path + "addtofav.png");

  QString connect_path = (g_theme_path + "connect.png");
  QString publicservers_path = (g_theme_path + "publicservers_selected.png");
  QString favorites_path = (g_theme_path + "favorites.png");

  if (fileExists(background_path))
    ui->background->setPixmap(QPixmap(background_path));

  ui->refresh->setStyleSheet("border-image:url(" + refresh_path );
  if (fileExists(addtofav_path))
    ui->addtofav->setStyleSheet("border-image:url(" + addtofav_path );

  if (fileExists(connect_path))
    ui->connect->setStyleSheet("border-image:url(" + connect_path );

  if (fileExists(publicservers_path))
    ui->publicservers->setStyleSheet("border-image:url(" + publicservers_path );

  if (fileExists(favorites_path))
    ui->favorites->setStyleSheet("border-image:url(" + favorites_path );

  */

  ui->background->setPixmap(get_image_path("lobbybackground.png"));
  ui->refresh->setStyleSheet(get_stylesheet_path("refresh.png"));
  ui->addtofav->setStyleSheet(get_stylesheet_path("addtofav.png"));
  ui->connect->setStyleSheet(get_stylesheet_path("connect.png"));
  ui->publicservers->setStyleSheet(get_stylesheet_path("publicservers_selected.png"));
  ui->favorites->setStyleSheet(get_stylesheet_path("favorites.png"));
  ui->about->setStyleSheet(get_stylesheet_path("about.png"));

  ui->favoritelist->hide();
}
Esempio n. 4
0
static int check_sharing(struct xs_handle *h, struct backend_info *be)
{
	char *dom_uuid;
	char *cur_dom_uuid;
	char *path;
	char *mode;
	char *params;
	char **domains;
	char **devices;
	int i, j;
	unsigned int num_dom, num_dev;
	blkif_info_t *info = be->blkif->info;
	int ret = 0;
	const char *image_path[2];
	int be_domid = get_be_domid(be->backpath);

	image_path[0] = get_image_path(info->params);

	/* If the mode contains '!' or doesn't contain 'w' don't check anything */
	xs_gather(h, be->backpath, "mode", NULL, &mode, NULL);
	if (strchr(mode, '!'))
		goto out;
	if (strchr(mode, 'w') == NULL)
		goto out;

	/* Get the UUID of the domain we want to attach to */
	if (asprintf(&path, "/local/domain/%ld", be->frontend_id) == -1)
		goto fail;
	xs_gather(h, path, "vm", NULL, &dom_uuid, NULL);
	free(path);

	/* Iterate through the devices of all VMs */
	if (asprintf(&path, "/local/domain/%d/backend/tap", be_domid) == -1)
		goto fail;
	domains = xs_directory(h, XBT_NULL, path, &num_dom);
	free(path);
	if (domains == NULL)
		num_dom = 0;

	for (i = 0; !ret && (i < num_dom); i++) {

		/* If it's the same VM, no action needed */
		if (asprintf(&path, "/local/domain/%s", domains[i]) == -1) {
			ret = -1;
			break;
		}
		cur_dom_uuid = NULL;
		xs_gather(h, path, "vm", NULL, &cur_dom_uuid, NULL);
		free(path);
		if (!cur_dom_uuid)
			continue;

		if (!strcmp(cur_dom_uuid, dom_uuid)) {
			free(cur_dom_uuid);
			continue;
		}

		/* Check the devices */
		if (asprintf(&path, "/local/domain/%d/backend/tap/%s", be_domid, domains[i]) == -1) {
			ret = -1;
			free(cur_dom_uuid);
			break;
		}
		devices = xs_directory(h, XBT_NULL, path, &num_dev);
		if (devices == NULL)
			num_dev = 0;
		free(path);

		for (j = 0; !ret && (j < num_dev); j++) {
			if (asprintf(&path, "/local/domain/%d/backend/tap/%s/%s", be_domid, domains[i], devices[j]) == -1) {
				ret = -1;
				break;
			}
			params = NULL;
			xs_gather(h, path, "params", NULL, &params, NULL);
			free(path);
			if (!params)
				continue;

			image_path[1] = get_image_path(params);
			if (!strcmp(image_path[0], image_path[1])) {
				ret = -1;
			}

			free(params);
		}

		free(cur_dom_uuid);
		free(devices);
	}
	free(domains);
	free(dom_uuid);
	goto out;

fail:
	ret = -1;
out:
	free(mode);
	return ret;
}
Esempio n. 5
0
static int check_file(int node_num)
{//check node file, check bus file
	char process_image_dir[PATH_MAX];
	char bus_folder[PATH_MAX];
	char nodes_folder[PATH_MAX];	
	char *process_image_folder = NULL;
	void *res;
	int rval = 0;
	
	res = get_image_path(getpid(), process_image_dir, sizeof(process_image_dir));
	if(res == NULL)
	{
		rval = -1;
	}
	else
	{//get the directory part of image path
		char *point_slush = process_image_dir;
		char *point_file = process_image_dir;
		
		while(point_slush != NULL)
		{
			point_slush = memchr(point_file, '/', strlen(point_file));
			if(point_slush != NULL)
			{
				point_file = point_slush + 1;
			}
		}
		
		memset(point_file, 0, sizeof(process_image_dir) - (point_file - process_image_dir) + 1);
	}
	
	process_image_folder = process_image_dir;
	
	if(rval == 0)
	{//check folder of emulator
		DIR *dir = NULL;
		dir = opendir(process_image_folder);
		if(dir == NULL)
		{
			perror(process_image_folder);
			rval = -1;
		}
		else
		{
			printf("ok for %s\n", process_image_folder);
			closedir(dir);
		}
		
		if(rval == 0)
		{//checknodes folder exist
			DIR *nodes_dir = NULL;
			
			memcpy(nodes_folder, process_image_folder, sizeof(nodes_folder));
			
			strncat(nodes_folder, "nodes/", sizeof(nodes_folder));
			
			nodes_dir = opendir(nodes_folder);
			
			if(nodes_dir == NULL)
			{
				perror("check nodes_dir");
				if(errno == ENOENT)
				{
					rval = mkdir(nodes_folder, 0777);
					if(rval == 0)
					{
						printf("mkdir %s", nodes_folder);
					}
					else
					{
						perror("make nodes folder");
					}
				}
				else
				{
					rval = -1;
				}
			}
			else
			{
				printf("exist %s\n", nodes_folder);
				closedir(nodes_dir);
			}
			
			if(rval == 0)		
			{//check nodes files node_n_r and node_n_w
				//check node file
				int count = 0;
				char nodes_file_read[PATH_MAX];
				char nodes_file_write[PATH_MAX];
				
				for(count = 0; count < node_num; count ++)
				{
					DIR *nodes_dir = NULL;
					memset(nodes_file_read, 0, sizeof(nodes_file));
					memset(nodes_file_write, 0, sizeof(nodes_file));
					snprintf(nodes_file_read, sizeof(nodes_file), "%snode_%d_r", nodes_folder, count);
					snprintf(nodes_file_write, sizeof(nodes_file), "%snode_%d_w", nodes_folder, count);
					
					//try to open node_n_r
					nodes_dir = opendir(nodes_file_read);
					if(nodes_dir == NULL)
					{
						perror("check nodes file");
						if(errno == ENOENT)
						{
							rval = mknod(nodes_file_read, S_IFIFO, 0);
							if(rval == 0)
							{
								printf("make node_%d_r file\n", count);
								chmod(nodes_file_read, 0666);
							}							
							else
							{
								perror("make nodes");
							}
						}
						else
						{
							rval = -1;
						}						
					}
					else
					{
						printf("exist %s\n", nodes_file_read);
						closedir(nodes_dir);
					}
					
					//try to open node_n_w
					nodes_dir = NULL;
					nodes_dir = opendir(nodes_file_write);
					if(nodes_dir == NULL)
					{
						perror("check nodes file");
						if(errno == ENOENT)
						{
							rval = mknod(nodes_file_write, S_IFIFO, 0);
							if(rval == 0)
							{
								printf("make node_%d_w file\n", count);
								chmod(nodes_file_write, 0666);
							}							
							else
							{
								perror("make nodes");
							}
						}
						else
						{
							rval = -1;
						}						
					}
					else
					{
						printf("exist %s\n", nodes_file_write);
						closedir(nodes_dir);
					}					
				}//loop to check nodes file	
			}
		}
	}
	
	if(rval == 0)
	{
//		memset(bus_path, 0, sizeof(bus_path));
		memset(nodes_path, 0, sizeof(nodes_path));
//		snprintf(bus_path, sizeof(bus_path), "%sbus", bus_folder);
		snprintf(nodes_path, sizeof(nodes_path), "%s", nodes_folder);
	}
	
	return rval;
}