Introduce liftoff_log_errno

Like perror, but uses the liftoff logging infrastructure.
This commit is contained in:
Simon Ser 2019-10-19 13:35:14 +03:00
parent dc9c39ed5c
commit ba80e32054
No known key found for this signature in database
GPG key ID: 0FDE7BE0E88F5E48
5 changed files with 23 additions and 4 deletions

View file

@ -18,6 +18,7 @@ struct liftoff_display *liftoff_display_create(int drm_fd)
display = calloc(1, sizeof(*display));
if (display == NULL) {
liftoff_log_errno(LIFTOFF_ERROR, "calloc");
return NULL;
}
@ -26,18 +27,21 @@ struct liftoff_display *liftoff_display_create(int drm_fd)
display->drm_fd = dup(drm_fd);
if (display->drm_fd < 0) {
liftoff_log_errno(LIFTOFF_ERROR, "dup");
liftoff_display_destroy(display);
return NULL;
}
drm_res = drmModeGetResources(drm_fd);
if (drm_res == NULL) {
liftoff_log_errno(LIFTOFF_ERROR, "drmModeGetResources");
liftoff_display_destroy(display);
return NULL;
}
display->crtcs = malloc(drm_res->count_crtcs * sizeof(uint32_t));
if (display->crtcs == NULL) {
liftoff_log_errno(LIFTOFF_ERROR, "malloc");
drmModeFreeResources(drm_res);
liftoff_display_destroy(display);
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 */
drm_plane_res = drmModeGetPlaneResources(drm_fd);
if (drm_plane_res == NULL) {
liftoff_log_errno(LIFTOFF_ERROR, "drmModeGetPlaneResources");
liftoff_display_destroy(display);
return NULL;
}
@ -100,7 +105,7 @@ static bool plane_set_prop(struct liftoff_plane *plane, drmModeAtomicReq *req,
prop->name, value);
ret = drmModeAtomicAddProperty(req, plane->id, prop->id, value);
if (ret < 0) {
perror("drmModeAtomicAddProperty");
liftoff_log_errno(LIFTOFF_ERROR, "drmModeAtomicAddProperty");
return false;
}
@ -515,7 +520,7 @@ static bool display_test_commit(struct liftoff_display *display,
} else if (-ret == EINVAL || -ret == ERANGE) {
*compatible = false;
} else {
perror("drmModeAtomicCommit");
liftoff_log_errno(LIFTOFF_ERROR, "drmModeAtomicCommit");
*compatible = 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));
result.best = malloc(result.planes_len * sizeof(*result.best));
if (step.alloc == NULL || result.best == NULL) {
perror("malloc");
liftoff_log_errno(LIFTOFF_ERROR, "malloc");
return false;
}

View file

@ -11,5 +11,6 @@
void liftoff_log(enum liftoff_log_importance verbosity,
const char *format, ...) _LIFTOFF_ATTRIB_PRINTF(2, 3);
void liftoff_log_errno(enum liftoff_log_importance verbosity, const char *msg);
#endif

View file

@ -9,6 +9,7 @@ struct liftoff_layer *liftoff_layer_create(struct liftoff_output *output)
layer = calloc(1, sizeof(*layer));
if (layer == NULL) {
liftoff_log_errno(LIFTOFF_ERROR, "calloc");
return NULL;
}
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)
* sizeof(struct liftoff_layer_property));
if (props == NULL) {
perror("realloc");
liftoff_log_errno(LIFTOFF_ERROR, "realloc");
return;
}
layer->props = props;

7
log.c
View file

@ -1,4 +1,6 @@
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include "log.h"
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);
va_end(args);
}
void liftoff_log_errno(enum liftoff_log_importance verbosity, const char *msg)
{
liftoff_log(verbosity, "%s: %s", msg, strerror(errno));
}

View file

@ -43,11 +43,13 @@ struct liftoff_plane *plane_create(struct liftoff_display *display, uint32_t id)
plane = calloc(1, sizeof(*plane));
if (plane == NULL) {
liftoff_log_errno(LIFTOFF_ERROR, "calloc");
return NULL;
}
drm_plane = drmModeGetPlane(display->drm_fd, id);
if (drm_plane == NULL) {
liftoff_log_errno(LIFTOFF_ERROR, "drmModeGetPlane");
return NULL;
}
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_MODE_OBJECT_PLANE);
if (drm_props == NULL) {
liftoff_log_errno(LIFTOFF_ERROR, "drmModeObjectGetProperties");
return NULL;
}
plane->props = calloc(drm_props->count_props,
sizeof(struct liftoff_plane_property));
if (plane->props == NULL) {
liftoff_log_errno(LIFTOFF_ERROR, "calloc");
drmModeFreeObjectProperties(drm_props);
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_props->props[i]);
if (drm_prop == NULL) {
liftoff_log_errno(LIFTOFF_ERROR, "drmModeGetProperty");
drmModeFreeObjectProperties(drm_props);
return NULL;
}