Failure of config file parsing is a hard failure

compton will now quit if it fails to parse the config file.

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui 2019-02-13 02:04:05 +00:00
parent 7a21cef9a4
commit 60aa36b7af
No known key found for this signature in database
GPG Key ID: 37C999F617EA1A47
4 changed files with 58 additions and 10 deletions

View File

@ -45,6 +45,8 @@
#else
# define attr_warn_unused_result
#endif
// An alias for conveninence
#define must_use attr_warn_unused_result
#if __has_attribute(nonnull)
# define attr_nonnull(...) __attribute__((nonnull(__VA_ARGS__)))

View File

@ -28,6 +28,7 @@
#include <ev.h>
#include "err.h"
#include "kernel.h"
#include "common.h"
#include "compiler.h"
@ -2737,6 +2738,10 @@ session_init(int argc, char **argv, Display *dpy, const char *config_file,
parse_config(&ps->o, config_file, &shadow_enabled,
&fading_enable, &hasneg, winopt_mask);
if (IS_ERR(config_file_to_free)) {
return NULL;
}
// Parse all of the rest command line options
get_cfg(&ps->o, argc, argv, shadow_enabled, fading_enable, hasneg, winopt_mask);

View File

@ -10,6 +10,7 @@
#include <libconfig.h>
#include <basedir_fs.h>
#include "err.h"
#include "common.h"
#include "compiler.h"
#include "config.h"
@ -176,11 +177,11 @@ char *parse_config_libconfig(options_t *opt, const char *config_file, bool *shad
f = open_config_file(config_file, &path);
if (!f) {
free(path);
if (config_file) {
log_fatal("Failed to read configuration file \"%s\".", config_file);
abort();
return ERR_PTR(-1);
}
free(path);
return NULL;
}
@ -202,11 +203,9 @@ char *parse_config_libconfig(options_t *opt, const char *config_file, bool *shad
fclose(f);
f = NULL;
if (read_result == CONFIG_FALSE) {
log_error("Error when reading configuration file \"%s\", line %d: %s",
log_fatal("Error when reading configuration file \"%s\", line %d: %s",
path, config_error_line(&cfg), config_error_text(&cfg));
config_destroy(&cfg);
free(path);
return NULL;
goto err;
}
}
config_set_auto_convert(&cfg, 1);
@ -311,7 +310,7 @@ char *parse_config_libconfig(options_t *opt, const char *config_file, bool *shad
opt->vsync = parse_vsync(sval);
if (opt->vsync >= NUM_VSYNC) {
log_fatal("Cannot parse vsync");
exit(1);
goto err;
}
}
// --backend
@ -319,7 +318,7 @@ char *parse_config_libconfig(options_t *opt, const char *config_file, bool *shad
opt->backend = parse_backend(sval);
if (opt->backend >= NUM_BKEND) {
log_fatal("Cannot parse backend");
exit(1);
goto err;
}
}
// --log-level
@ -382,7 +381,7 @@ char *parse_config_libconfig(options_t *opt, const char *config_file, bool *shad
if (config_lookup_string(&cfg, "blur-kern", &sval) &&
!parse_conv_kern_lst(sval, opt->blur_kerns, MAX_BLUR_PASS, conv_kern_hasneg)) {
log_fatal("Cannot parse \"blur-kern\"");
exit(1);
goto err;
}
// --resize-damage
config_lookup_int(&cfg, "resize-damage", &opt->resize_damage);
@ -395,7 +394,7 @@ char *parse_config_libconfig(options_t *opt, const char *config_file, bool *shad
opt->glx_swap_method = parse_glx_swap_method(sval);
if (opt->glx_swap_method == -2) {
log_fatal("Cannot parse \"glx-swap-method\"");
exit(1);
goto err;
}
}
// --glx-use-gpushader4
@ -468,4 +467,9 @@ char *parse_config_libconfig(options_t *opt, const char *config_file, bool *shad
config_destroy(&cfg);
return path;
err:
config_destroy(&cfg);
free(path);
return ERR_PTR(-1);
}

37
src/err.h Normal file
View File

@ -0,0 +1,37 @@
// SPDX-License-Identifier: MPL-2.0
// Copyright (c) 2019 Yuxuan Shui <yshuiv7@gmail.com>
#pragma once
#include <stdbool.h>
#include <stdint.h>
#include "compiler.h"
// Functions for error reporting, adopted from Linux
// INFO in user space we can probably be more liberal about what pointer we consider
// error. e.g. In x86_64 Linux, all addresses with the highest bit set is invalid in user
// space.
#define MAX_ERRNO 4095
static inline void *must_use ERR_PTR(intptr_t err) {
return (void *)err;
}
static inline intptr_t must_use PTR_ERR(void *ptr) {
return (intptr_t)ptr;
}
static inline bool must_use IS_ERR(void *ptr) {
return unlikely((uintptr_t)ptr > (uintptr_t)-MAX_ERRNO);
}
static inline bool must_use IS_ERR_OR_NULL(void *ptr) {
return unlikely(!ptr) || IS_ERR(ptr);
}
static inline intptr_t must_use PTR_ERR_OR_ZERO(void *ptr) {
if (IS_ERR(ptr)) {
return PTR_ERR(ptr);
}
return 0;
}