Changed logging.

This commit is contained in:
Scott Anderson 2017-05-02 13:00:25 +12:00
parent 41a82fd2fc
commit 562d43a5ec
5 changed files with 176 additions and 74 deletions

View file

@ -4,6 +4,7 @@
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <systemd/sd-bus.h>
#include <systemd/sd-login.h>
#include <unistd.h>
@ -13,6 +14,7 @@
#include "backend/drm/backend.h"
#include "backend/drm/session.h"
#include "common/log.h"
int wlr_session_take_device(struct wlr_session *restrict session,
const char *restrict path,
@ -25,7 +27,7 @@ int wlr_session_take_device(struct wlr_session *restrict session,
struct stat st;
if (stat(path, &st) < 0) {
fprintf(stderr, "Failed to stat '%s'\n", path);
wlr_log(L_ERROR, "Failed to stat '%s'", path);
return -1;
}
@ -37,20 +39,26 @@ int wlr_session_take_device(struct wlr_session *restrict session,
&error, &msg,
"uu", major(st.st_rdev), minor(st.st_rdev));
if (ret < 0) {
fprintf(stderr, "%s\n", error.message);
wlr_log(L_ERROR, "Failed to take device '%s': %s", path, error.message);
goto error;
}
int paused = 0;
ret = sd_bus_message_read(msg, "hb", &fd, &paused);
if (ret < 0) {
fprintf(stderr, "%s\n", strerror(-ret));
wlr_log(L_ERROR, "Failed to parse DBus response for '%s': %s",
path, strerror(-ret));
goto error;
}
// The original fd seem to be closed when the message is freed
// so we just clone it.
fd = fcntl(fd, F_DUPFD_CLOEXEC, 0);
if (fd == -1) {
wlr_log(L_ERROR, "Failed to clone file descriptor for '%s': %s",
path, strerror(errno));
goto error;
}
if (paused_out)
*paused_out = paused;
@ -69,7 +77,7 @@ void wlr_session_release_device(struct wlr_session *session, int fd)
struct stat st;
if (fstat(fd, &st) < 0) {
fprintf(stderr, "Could not stat fd %d\n", fd);
wlr_log(L_ERROR, "Failed to stat device '%d'", fd);
return;
}
@ -80,9 +88,8 @@ void wlr_session_release_device(struct wlr_session *session, int fd)
"ReleaseDevice",
&error, &msg,
"uu", major(st.st_rdev), minor(st.st_rdev));
if (ret < 0) {
/* Log something */;
}
if (ret < 0)
wlr_log(L_ERROR, "Failed to release device '%d'", fd);
sd_bus_error_free(&error);
sd_bus_message_unref(msg);
@ -101,9 +108,8 @@ static bool session_activate(struct wlr_session *session)
"Activate",
&error, &msg,
"");
if (ret < 0) {
fprintf(stderr, "%s\n", error.message);
}
if (ret < 0)
wlr_log(L_ERROR, "Failed to activate session");
sd_bus_error_free(&error);
sd_bus_message_unref(msg);
@ -123,9 +129,8 @@ static bool take_control(struct wlr_session *session)
"TakeControl",
&error, &msg,
"b", false);
if (ret < 0) {
/* Log something */;
}
if (ret < 0)
wlr_log(L_ERROR, "Failed to take control of session");
sd_bus_error_free(&error);
sd_bus_message_unref(msg);
@ -145,9 +150,8 @@ static void release_control(struct wlr_session *session)
"ReleaseControl",
&error, &msg,
"");
if (ret < 0) {
/* Log something */;
}
if (ret < 0)
wlr_log(L_ERROR, "Failed to release control of session");
sd_bus_error_free(&error);
sd_bus_message_unref(msg);
@ -169,13 +173,13 @@ bool wlr_session_start(struct wlr_session *session)
ret = sd_pid_get_session(getpid(), &session->id);
if (ret < 0) {
fprintf(stderr, "Could not get session\n");
wlr_log(L_ERROR, "Failed to get session id: %s", strerror(-ret));
goto error;
}
ret = sd_session_get_seat(session->id, &session->seat);
if (ret < 0) {
fprintf(stderr, "Could not get seat\n");
wlr_log(L_ERROR, "Failed to get seat id: %s", strerror(-ret));
goto error;
}
@ -192,19 +196,15 @@ bool wlr_session_start(struct wlr_session *session)
ret = sd_bus_open_system(&session->bus);
if (ret < 0) {
fprintf(stderr, "Could not open bus\n");
wlr_log(L_ERROR, "Failed to open DBus connection: %s", strerror(-ret));
goto error;
}
if (!session_activate(session)) {
fprintf(stderr, "Could not activate session\n");
if (!session_activate(session))
goto error_bus;
}
if (!take_control(session)) {
fprintf(stderr, "Could not take control of session\n");
if (!take_control(session))
goto error_bus;
}
return true;