wayland: Improve error message handling in cursor buffer code
This commit is contained in:
@ -35,6 +35,7 @@
|
|||||||
#include <gdk-pixbuf/gdk-pixbuf.h>
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
||||||
|
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
#define GDK_TYPE_WAYLAND_CURSOR (_gdk_wayland_cursor_get_type ())
|
#define GDK_TYPE_WAYLAND_CURSOR (_gdk_wayland_cursor_get_type ())
|
||||||
#define GDK_WAYLAND_CURSOR(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GDK_TYPE_WAYLAND_CURSOR, GdkWaylandCursor))
|
#define GDK_WAYLAND_CURSOR(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GDK_TYPE_WAYLAND_CURSOR, GdkWaylandCursor))
|
||||||
@ -193,28 +194,34 @@ create_cursor(GdkWaylandDisplay *display, GdkPixbuf *pixbuf, int x, int y)
|
|||||||
cursor->size = stride * cursor->height;
|
cursor->size = stride * cursor->height;
|
||||||
|
|
||||||
fd = g_file_open_tmp("wayland-shm-XXXXXX", &filename, &error);
|
fd = g_file_open_tmp("wayland-shm-XXXXXX", &filename, &error);
|
||||||
if (fd < 0) {
|
if (fd < 0)
|
||||||
fprintf(stderr, "g_file_open_tmp failed: %s\n", error->message);
|
{
|
||||||
g_error_free (error);
|
g_critical (G_STRLOC ": Error opening temporary file for buffer: %s",
|
||||||
return NULL;
|
error->message);
|
||||||
|
g_error_free (error);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
unlink (filename);
|
unlink (filename);
|
||||||
g_free (filename);
|
g_free (filename);
|
||||||
|
|
||||||
if (ftruncate(fd, cursor->size) < 0) {
|
if (ftruncate(fd, cursor->size) < 0)
|
||||||
fprintf(stderr, "ftruncate failed: %m\n");
|
{
|
||||||
close(fd);
|
g_critical (G_STRLOC ": Error truncating file for buffer: %s",
|
||||||
return NULL;
|
g_strerror (errno));
|
||||||
}
|
close(fd);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
cursor->map = mmap(NULL, cursor->size,
|
cursor->map = mmap(NULL, cursor->size,
|
||||||
PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||||
if (cursor->map == MAP_FAILED) {
|
if (cursor->map == MAP_FAILED)
|
||||||
fprintf(stderr, "mmap failed: %m\n");
|
{
|
||||||
close(fd);
|
g_critical (G_STRLOC ": Error mmap'ing file for buffer: %s",
|
||||||
return NULL;
|
g_strerror (errno));
|
||||||
}
|
close(fd);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (pixbuf)
|
if (pixbuf)
|
||||||
set_pixbuf (cursor, pixbuf);
|
set_pixbuf (cursor, pixbuf);
|
||||||
|
|||||||
Reference in New Issue
Block a user