Replace wlr_log with sway_log

This commit mostly duplicates the wlr_log functions, although
with a sway_* prefix. (This is very similar to PR #2009.)
However, the logging function no longer needs to be replaceable,
so sway_log_init's second argument is used to set the exit
callback for sway_abort.

wlr_log_init is still invoked in sway/main.c

This commit makes it easier to remove the wlroots dependency for
the helper programs swaymsg, swaybg, swaybar, and swaynag.
This commit is contained in:
M Stoeckl 2019-01-20 13:51:12 -05:00 committed by emersion
parent 5c834d36e1
commit 1211a81aad
108 changed files with 613 additions and 504 deletions

View file

@ -19,10 +19,10 @@
#include "util.h"
static void terminate_swaybar(pid_t pid) {
wlr_log(WLR_DEBUG, "Terminating swaybar %d", pid);
sway_log(SWAY_DEBUG, "Terminating swaybar %d", pid);
int ret = kill(-pid, SIGTERM);
if (ret != 0) {
wlr_log_errno(WLR_ERROR, "Unable to terminate swaybar %d", pid);
sway_log_errno(SWAY_ERROR, "Unable to terminate swaybar %d", pid);
} else {
int status;
waitpid(pid, &status, 0);
@ -194,7 +194,7 @@ static void invoke_swaybar(struct bar_config *bar) {
// Pipe to communicate errors
int filedes[2];
if (pipe(filedes) == -1) {
wlr_log(WLR_ERROR, "Pipe setup failed! Cannot fork into bar");
sway_log(SWAY_ERROR, "Pipe setup failed! Cannot fork into bar");
return;
}
@ -227,17 +227,17 @@ static void invoke_swaybar(struct bar_config *bar) {
execvp(cmd[0], cmd);
exit(1);
}
wlr_log(WLR_DEBUG, "Spawned swaybar %d", bar->pid);
sway_log(SWAY_DEBUG, "Spawned swaybar %d", bar->pid);
close(filedes[0]);
size_t len;
if (read(filedes[1], &len, sizeof(size_t)) == sizeof(size_t)) {
char *buf = malloc(len);
if(!buf) {
wlr_log(WLR_ERROR, "Cannot allocate error string");
sway_log(SWAY_ERROR, "Cannot allocate error string");
return;
}
if (read(filedes[1], buf, len)) {
wlr_log(WLR_ERROR, "%s", buf);
sway_log(SWAY_ERROR, "%s", buf);
}
free(buf);
}
@ -248,7 +248,7 @@ void load_swaybar(struct bar_config *bar) {
if (bar->pid != 0) {
terminate_swaybar(bar->pid);
}
wlr_log(WLR_DEBUG, "Invoking swaybar for bar id '%s'", bar->id);
sway_log(SWAY_DEBUG, "Invoking swaybar for bar id '%s'", bar->id);
invoke_swaybar(bar);
}