Remove info() and die()

This commit is contained in:
Johan Malm 2021-07-22 21:30:17 +01:00
parent 22f5073ebd
commit 20fd8f59a7
11 changed files with 26 additions and 51 deletions

View file

@ -1,19 +1,9 @@
#ifndef __LABWC_LOG_H
#define __LABWC_LOG_H
/**
* info - print info message
*/
void info(const char *msg, ...);
/**
* warn - print warning
*/
void warn(const char *err, ...);
/**
* die - print fatal message and exit()
*/
void die(const char *err, ...);
#endif /* __LABWC_LOG_H */

View file

@ -85,7 +85,7 @@ find_dir(struct ctx *ctx)
/* handle /etc/xdg... */
ctx->build_path_fn(ctx, NULL, d.path);
if (debug) {
info("%s", ctx->buf);
fprintf(stderr, "%s\n", ctx->buf);
}
if (isdir(ctx->buf)) {
return ctx->buf;
@ -100,7 +100,7 @@ find_dir(struct ctx *ctx)
for (gchar **p = prefixes; *p; p++) {
ctx->build_path_fn(ctx, *p, d.path);
if (debug) {
info("%s", ctx->buf);
fprintf(stderr, "%s\n", ctx->buf);
}
if (isdir(ctx->buf)) {
g_strfreev(prefixes);

View file

@ -3,17 +3,6 @@
#include <stdlib.h>
#include <string.h>
void
info(const char *msg, ...)
{
va_list params;
fprintf(stderr, "[labwc] info: ");
va_start(params, msg);
vfprintf(stderr, msg, params);
va_end(params);
fprintf(stderr, "\n");
}
void
warn(const char *err, ...)
{
@ -25,14 +14,3 @@ warn(const char *err, ...)
fprintf(stderr, "\n");
}
void
die(const char *err, ...)
{
va_list params;
fprintf(stderr, "[labwc] fatal: ");
va_start(params, err);
vfprintf(stderr, err, params);
va_end(params);
fprintf(stderr, "\n");
exit(EXIT_FAILURE);
}

View file

@ -10,7 +10,7 @@
#include <strings.h>
#include <unistd.h>
#include <wayland-server-core.h>
#include <wlr/util/log.h>
#include "common/dir.h"
#include "common/log.h"
#include "common/nodename.h"
@ -273,7 +273,7 @@ static void
post_processing(void)
{
if (!wl_list_length(&rc.keybinds)) {
info("load default key bindings");
wlr_log(WLR_INFO, "load default key bindings");
bind("A-Escape", "Exit", NULL);
bind("A-Tab", "NextWindow", NULL);
bind("A-F3", "Execute", "bemenu-run");
@ -323,7 +323,7 @@ rcxml_read(const char *filename)
find_config_file(rcxml, sizeof(rcxml), filename);
}
if (rcxml[0] == '\0') {
info("cannot find rc.xml config file; using defaults");
wlr_log(WLR_INFO, "cannot find rc.xml config file");
goto no_config;
}
@ -333,7 +333,7 @@ rcxml_read(const char *filename)
warn("cannot read (%s)", rcxml);
goto no_config;
}
info("read config file (%s)", rcxml);
wlr_log(WLR_INFO, "read config file %s", rcxml);
buf_init(&b);
while (getline(&line, &len, stream) != -1) {
char *p = strrchr(line, '\n');

View file

@ -5,6 +5,7 @@
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <wlr/util/log.h>
#include "common/dir.h"
#include "common/log.h"
#include "common/spawn.h"
@ -52,7 +53,7 @@ read_environment_file(const char *filename)
if (!stream) {
return;
}
info("read environment file (%s)", filename);
wlr_log(WLR_INFO, "read environment file %s", filename);
while (getline(&line, &len, stream) != -1) {
char *p = strrchr(line, '\n');
if (p) {
@ -101,7 +102,7 @@ session_autostart_init(void)
warn("no autostart file");
goto out;
}
info("run autostart file (%s)", autostart);
wlr_log(WLR_INFO, "run autostart file %s", autostart);
int len = strlen(autostart) + 4;
char *cmd = calloc(len, 1);
strcat(cmd, "sh ");

View file

@ -59,7 +59,8 @@ main(int argc, char *argv[])
rcxml_read(config_file);
if (!getenv("XDG_RUNTIME_DIR")) {
die("XDG_RUNTIME_DIR is unset");
wlr_log(WLR_ERROR, "XDG_RUNTIME_DIR is unset");
exit(EXIT_FAILURE);
}
struct server server = { 0 };

View file

@ -10,6 +10,7 @@
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <wlr/util/log.h>
#include "common/buf.h"
#include "common/dir.h"
#include "common/font.h"
@ -209,7 +210,7 @@ parse_xml(const char *filename, struct menu *menu)
warn("cannot read (%s)", menuxml);
return;
}
info("read menu file (%s)", menuxml);
wlr_log(WLR_INFO, "read menu file %s", menuxml);
buf_init(&b);
while (getline(&line, &len, stream) != -1) {
char *p = strrchr(line, '\n');

View file

@ -834,7 +834,7 @@ new_output_notify(struct wl_listener *listener, void *data)
*/
if (getenv("LABWC_ADAPTIVE_SYNC")) {
info("Set %s adaptive sync to 'true'", wlr_output->name);
wlr_log(WLR_INFO, "enable adaptive sync on %s", wlr_output->name);
wlr_output_enable_adaptive_sync(wlr_output, true);
}
wlr_output_layout_add_auto(server->output_layout, wlr_output);

View file

@ -31,7 +31,7 @@ configure_libinput(struct wlr_input_device *wlr_input_device)
if (libinput_device_config_tap_get_finger_count(libinput_dev) <= 0) {
return;
}
info("tap enabled for libinput device");
wlr_log(WLR_INFO, "tap enabled");
libinput_device_config_tap_set_enabled(libinput_dev,
LIBINPUT_CONFIG_TAP_ENABLED);
}

View file

@ -24,13 +24,14 @@ static struct server *g_server;
static void
reload_config_and_theme(void)
{
damage_all_outputs(g_server);
/* TODO: use rc.config_path */
rcxml_finish();
rcxml_read(NULL);
theme_finish(g_server->theme);
theme_init(g_server->theme, g_server->renderer, rc.theme_name);
menu_reconfigure(g_server, g_server->rootmenu);
damage_all_outputs(g_server);
}
static int
@ -54,14 +55,17 @@ drop_permissions(void)
{
if (getuid() != geteuid() || getgid() != getegid()) {
if (setgid(getgid())) {
die("unable to drop root group");
wlr_log(WLR_ERROR, "unable to drop root group");
exit(EXIT_FAILURE);
}
if (setuid(getuid())) {
die("unable to drop root user");
wlr_log(WLR_ERROR, "unable to drop root user");
exit(EXIT_FAILURE);
}
}
if (setgid(0) != -1 || setuid(0) != -1) {
die("unable to drop root");
wlr_log(WLR_ERROR, "unable to drop root");
exit(EXIT_FAILURE);
}
}

View file

@ -15,6 +15,7 @@
#include <stdlib.h>
#include <string.h>
#include <wlr/util/box.h>
#include <wlr/util/log.h>
#include "common/dir.h"
#include "common/font.h"
@ -191,12 +192,11 @@ theme_read(struct theme *theme, const char *theme_name)
}
if (!stream) {
if (theme_name) {
info("cannot find theme (%s), using built-in",
theme_name);
wlr_log(WLR_INFO, "cannot find theme %s", theme_name);
}
return;
}
info("read themerc (%s)", themerc);
wlr_log(WLR_INFO, "read theme %s", themerc);
while (getline(&line, &len, stream) != -1) {
char *p = strrchr(line, '\n');
if (p) {