mirror of
https://gitlab.freedesktop.org/emersion/libliftoff.git
synced 2024-12-26 21:59:18 +01:00
Introduce liftoff_log_errno
Like perror, but uses the liftoff logging infrastructure.
This commit is contained in:
parent
dc9c39ed5c
commit
ba80e32054
5 changed files with 23 additions and 4 deletions
11
display.c
11
display.c
|
@ -18,6 +18,7 @@ struct liftoff_display *liftoff_display_create(int drm_fd)
|
||||||
|
|
||||||
display = calloc(1, sizeof(*display));
|
display = calloc(1, sizeof(*display));
|
||||||
if (display == NULL) {
|
if (display == NULL) {
|
||||||
|
liftoff_log_errno(LIFTOFF_ERROR, "calloc");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,18 +27,21 @@ struct liftoff_display *liftoff_display_create(int drm_fd)
|
||||||
|
|
||||||
display->drm_fd = dup(drm_fd);
|
display->drm_fd = dup(drm_fd);
|
||||||
if (display->drm_fd < 0) {
|
if (display->drm_fd < 0) {
|
||||||
|
liftoff_log_errno(LIFTOFF_ERROR, "dup");
|
||||||
liftoff_display_destroy(display);
|
liftoff_display_destroy(display);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
drm_res = drmModeGetResources(drm_fd);
|
drm_res = drmModeGetResources(drm_fd);
|
||||||
if (drm_res == NULL) {
|
if (drm_res == NULL) {
|
||||||
|
liftoff_log_errno(LIFTOFF_ERROR, "drmModeGetResources");
|
||||||
liftoff_display_destroy(display);
|
liftoff_display_destroy(display);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
display->crtcs = malloc(drm_res->count_crtcs * sizeof(uint32_t));
|
display->crtcs = malloc(drm_res->count_crtcs * sizeof(uint32_t));
|
||||||
if (display->crtcs == NULL) {
|
if (display->crtcs == NULL) {
|
||||||
|
liftoff_log_errno(LIFTOFF_ERROR, "malloc");
|
||||||
drmModeFreeResources(drm_res);
|
drmModeFreeResources(drm_res);
|
||||||
liftoff_display_destroy(display);
|
liftoff_display_destroy(display);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -51,6 +55,7 @@ struct liftoff_display *liftoff_display_create(int drm_fd)
|
||||||
/* TODO: allow users to choose which layers to hand over */
|
/* TODO: allow users to choose which layers to hand over */
|
||||||
drm_plane_res = drmModeGetPlaneResources(drm_fd);
|
drm_plane_res = drmModeGetPlaneResources(drm_fd);
|
||||||
if (drm_plane_res == NULL) {
|
if (drm_plane_res == NULL) {
|
||||||
|
liftoff_log_errno(LIFTOFF_ERROR, "drmModeGetPlaneResources");
|
||||||
liftoff_display_destroy(display);
|
liftoff_display_destroy(display);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -100,7 +105,7 @@ static bool plane_set_prop(struct liftoff_plane *plane, drmModeAtomicReq *req,
|
||||||
prop->name, value);
|
prop->name, value);
|
||||||
ret = drmModeAtomicAddProperty(req, plane->id, prop->id, value);
|
ret = drmModeAtomicAddProperty(req, plane->id, prop->id, value);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
perror("drmModeAtomicAddProperty");
|
liftoff_log_errno(LIFTOFF_ERROR, "drmModeAtomicAddProperty");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -515,7 +520,7 @@ static bool display_test_commit(struct liftoff_display *display,
|
||||||
} else if (-ret == EINVAL || -ret == ERANGE) {
|
} else if (-ret == EINVAL || -ret == ERANGE) {
|
||||||
*compatible = false;
|
*compatible = false;
|
||||||
} else {
|
} else {
|
||||||
perror("drmModeAtomicCommit");
|
liftoff_log_errno(LIFTOFF_ERROR, "drmModeAtomicCommit");
|
||||||
*compatible = false;
|
*compatible = false;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -753,7 +758,7 @@ bool liftoff_display_apply(struct liftoff_display *display, drmModeAtomicReq *re
|
||||||
step.alloc = malloc(result.planes_len * sizeof(*step.alloc));
|
step.alloc = malloc(result.planes_len * sizeof(*step.alloc));
|
||||||
result.best = malloc(result.planes_len * sizeof(*result.best));
|
result.best = malloc(result.planes_len * sizeof(*result.best));
|
||||||
if (step.alloc == NULL || result.best == NULL) {
|
if (step.alloc == NULL || result.best == NULL) {
|
||||||
perror("malloc");
|
liftoff_log_errno(LIFTOFF_ERROR, "malloc");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,5 +11,6 @@
|
||||||
|
|
||||||
void liftoff_log(enum liftoff_log_importance verbosity,
|
void liftoff_log(enum liftoff_log_importance verbosity,
|
||||||
const char *format, ...) _LIFTOFF_ATTRIB_PRINTF(2, 3);
|
const char *format, ...) _LIFTOFF_ATTRIB_PRINTF(2, 3);
|
||||||
|
void liftoff_log_errno(enum liftoff_log_importance verbosity, const char *msg);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
3
layer.c
3
layer.c
|
@ -9,6 +9,7 @@ struct liftoff_layer *liftoff_layer_create(struct liftoff_output *output)
|
||||||
|
|
||||||
layer = calloc(1, sizeof(*layer));
|
layer = calloc(1, sizeof(*layer));
|
||||||
if (layer == NULL) {
|
if (layer == NULL) {
|
||||||
|
liftoff_log_errno(LIFTOFF_ERROR, "calloc");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
layer->output = output;
|
layer->output = output;
|
||||||
|
@ -57,7 +58,7 @@ void liftoff_layer_set_property(struct liftoff_layer *layer, const char *name,
|
||||||
props = realloc(layer->props, (layer->props_len + 1)
|
props = realloc(layer->props, (layer->props_len + 1)
|
||||||
* sizeof(struct liftoff_layer_property));
|
* sizeof(struct liftoff_layer_property));
|
||||||
if (props == NULL) {
|
if (props == NULL) {
|
||||||
perror("realloc");
|
liftoff_log_errno(LIFTOFF_ERROR, "realloc");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
layer->props = props;
|
layer->props = props;
|
||||||
|
|
7
log.c
7
log.c
|
@ -1,4 +1,6 @@
|
||||||
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
static enum liftoff_log_importance log_importance = LIFTOFF_ERROR;
|
static enum liftoff_log_importance log_importance = LIFTOFF_ERROR;
|
||||||
|
@ -31,3 +33,8 @@ void liftoff_log(enum liftoff_log_importance verbosity, const char *fmt, ...)
|
||||||
log_callback(verbosity, fmt, args);
|
log_callback(verbosity, fmt, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void liftoff_log_errno(enum liftoff_log_importance verbosity, const char *msg)
|
||||||
|
{
|
||||||
|
liftoff_log(verbosity, "%s: %s", msg, strerror(errno));
|
||||||
|
}
|
||||||
|
|
5
plane.c
5
plane.c
|
@ -43,11 +43,13 @@ struct liftoff_plane *plane_create(struct liftoff_display *display, uint32_t id)
|
||||||
|
|
||||||
plane = calloc(1, sizeof(*plane));
|
plane = calloc(1, sizeof(*plane));
|
||||||
if (plane == NULL) {
|
if (plane == NULL) {
|
||||||
|
liftoff_log_errno(LIFTOFF_ERROR, "calloc");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
drm_plane = drmModeGetPlane(display->drm_fd, id);
|
drm_plane = drmModeGetPlane(display->drm_fd, id);
|
||||||
if (drm_plane == NULL) {
|
if (drm_plane == NULL) {
|
||||||
|
liftoff_log_errno(LIFTOFF_ERROR, "drmModeGetPlane");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
plane->id = drm_plane->plane_id;
|
plane->id = drm_plane->plane_id;
|
||||||
|
@ -57,11 +59,13 @@ struct liftoff_plane *plane_create(struct liftoff_display *display, uint32_t id)
|
||||||
drm_props = drmModeObjectGetProperties(display->drm_fd, id,
|
drm_props = drmModeObjectGetProperties(display->drm_fd, id,
|
||||||
DRM_MODE_OBJECT_PLANE);
|
DRM_MODE_OBJECT_PLANE);
|
||||||
if (drm_props == NULL) {
|
if (drm_props == NULL) {
|
||||||
|
liftoff_log_errno(LIFTOFF_ERROR, "drmModeObjectGetProperties");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
plane->props = calloc(drm_props->count_props,
|
plane->props = calloc(drm_props->count_props,
|
||||||
sizeof(struct liftoff_plane_property));
|
sizeof(struct liftoff_plane_property));
|
||||||
if (plane->props == NULL) {
|
if (plane->props == NULL) {
|
||||||
|
liftoff_log_errno(LIFTOFF_ERROR, "calloc");
|
||||||
drmModeFreeObjectProperties(drm_props);
|
drmModeFreeObjectProperties(drm_props);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -69,6 +73,7 @@ struct liftoff_plane *plane_create(struct liftoff_display *display, uint32_t id)
|
||||||
drm_prop = drmModeGetProperty(display->drm_fd,
|
drm_prop = drmModeGetProperty(display->drm_fd,
|
||||||
drm_props->props[i]);
|
drm_props->props[i]);
|
||||||
if (drm_prop == NULL) {
|
if (drm_prop == NULL) {
|
||||||
|
liftoff_log_errno(LIFTOFF_ERROR, "drmModeGetProperty");
|
||||||
drmModeFreeObjectProperties(drm_props);
|
drmModeFreeObjectProperties(drm_props);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue